Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5bede992 authored by hoffc's avatar hoffc
Browse files

DeskClock: Fix Force close caused by IllegalStateException error.

The content of the mCityAdapter has changed but ListView did not receive
a notification, which results in app force close.

So here to make sure mCityAdapter calls NotifyDataSetChanged when its
content changes.

Change-Id: I7594d0e18eaeedf1c569f65b49aef961ca359e3e
CRs-Fixed: 1062713
parent 3d114b3f
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ public final class ClockFragment extends DeskClockFragment {
    private ListView mCityList;
    private String mDateFormat;
    private String mDateFormatForAccessibility;
    private BroadcastReceiver mCitesChangedReceiver;

    /** The public no-arg constructor required by all fragments. */
    public ClockFragment() {}
@@ -119,6 +120,18 @@ public final class ClockFragment extends DeskClockFragment {

        mDigitalClock = (TextClock) mClockFrame.findViewById(R.id.digital_clock);
        mAnalogClock = mClockFrame.findViewById(R.id.analog_clock);

        final IntentFilter filter = new IntentFilter();
        filter.addAction(DataModel.ACTION_DIGITAL_WIDGET_CHANGED);
        getActivity().registerReceiver(mCitesChangedReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (mCityAdapter != null) {
                    mCityAdapter.notifyDataSetChanged();
                }
            }
        }, filter);

        return fragmentView;
    }

@@ -180,6 +193,17 @@ public final class ClockFragment extends DeskClockFragment {
        }
    }

    @Override
    public void onDestroyView() {

        if (mCitesChangedReceiver != null) {
            getActivity().unregisterReceiver(mCitesChangedReceiver);
            mCitesChangedReceiver = null;
        }

        super.onDestroyView();
    }

    @Override
    public void onFabClick(View view) {
        startActivity(new Intent(getActivity(), CitySelectionActivity.class));
@@ -227,6 +251,11 @@ public final class ClockFragment extends DeskClockFragment {
     */
    private void refreshAlarm() {
        Utils.refreshAlarm(getActivity(), mClockFrame);

        // Refresh the next alarm in header view
        if (mCityAdapter != null) {
            mCityAdapter.notifyDataSetChanged();
        }
    }

    /**