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

Commit 53d76860 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

Fix bug #15161058 Stability: ISE in Settings:Fragment...

Fix bug #15161058 Stability: ISE in Settings:Fragment DashboardSummary{588de71} not attached to Activity

- prevent rebuilding the UI until the fragment got attached

Change-Id: I6d5fcbce2581f3fc9900f1ca4fc8178ee959061e
parent b644f293
Loading
Loading
Loading
Loading
+12 −7
Original line number Original line Diff line number Diff line
@@ -49,12 +49,12 @@ public class DashboardSummary extends Fragment implements OnAccountsUpdateListen
    private AuthenticatorHelper mAuthHelper;
    private AuthenticatorHelper mAuthHelper;
    private boolean mAccountListenerAdded;
    private boolean mAccountListenerAdded;


    private static final int MSG_BUILD_CATEGORIES = 1;
    private static final int MSG_REBUILD_UI = 1;
    private Handler mHandler = new Handler() {
    private Handler mHandler = new Handler() {
        @Override
        @Override
        public void handleMessage(Message msg) {
        public void handleMessage(Message msg) {
            switch (msg.what) {
            switch (msg.what) {
                case MSG_BUILD_CATEGORIES: {
                case MSG_REBUILD_UI: {
                    final Context context = getActivity();
                    final Context context = getActivity();
                    rebuildUI(context);
                    rebuildUI(context);
                } break;
                } break;
@@ -80,6 +80,11 @@ public class DashboardSummary extends Fragment implements OnAccountsUpdateListen
    }
    }


    private void rebuildUI(Context context) {
    private void rebuildUI(Context context) {
        if (!isAdded()) {
            Log.w(LOG_TAG, "Cannot build the DashboardSummary UI yet as the Fragment is not added");
            return;
        }

        long start = System.currentTimeMillis();
        long start = System.currentTimeMillis();
        final Resources res = getResources();
        final Resources res = getResources();


@@ -131,7 +136,7 @@ public class DashboardSummary extends Fragment implements OnAccountsUpdateListen
            mAccountListenerAdded = true;
            mAccountListenerAdded = true;
        }
        }


        rebuildCategories();
        sendRebuildUI();
    }
    }


    @Override
    @Override
@@ -176,9 +181,9 @@ public class DashboardSummary extends Fragment implements OnAccountsUpdateListen
        }
        }
    }
    }


    private void rebuildCategories() {
    private void sendRebuildUI() {
        if (!mHandler.hasMessages(MSG_BUILD_CATEGORIES)) {
        if (!mHandler.hasMessages(MSG_REBUILD_UI)) {
            mHandler.sendEmptyMessage(MSG_BUILD_CATEGORIES);
            mHandler.sendEmptyMessage(MSG_REBUILD_UI);
        }
        }
    }
    }


@@ -186,6 +191,6 @@ public class DashboardSummary extends Fragment implements OnAccountsUpdateListen
    public void onAccountsUpdated(Account[] accounts) {
    public void onAccountsUpdated(Account[] accounts) {
        final SettingsActivity sa = (SettingsActivity) getActivity();
        final SettingsActivity sa = (SettingsActivity) getActivity();
        sa.setNeedToRebuildCategories(true);
        sa.setNeedToRebuildCategories(true);
        rebuildCategories();
        sendRebuildUI();
    }
    }
}
}