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

Commit e4d0ed50 authored by Jason Monk's avatar Jason Monk
Browse files

Fix crash from battery saver switch

Turns out most things expect the conditions to be loaded immediately
so if the dashboard hasn't been hit, they crash.  Instead load
immediately for everything but the dashboard.

Change-Id: Iaa1114c88b3766e2ac513acb417ef2a55a0f4e7f
Fixes: 28952354
parent eb02435c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ public class DashboardSummary extends InstrumentedFragment
        mSummaryLoader = new SummaryLoader(getActivity(), categories);
        setHasOptionsMenu(true);
        Context context = getContext();
        mConditionManager = ConditionManager.get(context);
        mConditionManager = ConditionManager.get(context, false);
        mSuggestionParser = new SuggestionParser(context,
                context.getSharedPreferences(SUGGESTIONS, 0), R.xml.suggestion_ordering);
        mSuggestionsChecks = new SuggestionsChecks(getContext());
+12 −3
Original line number Diff line number Diff line
@@ -54,11 +54,16 @@ public class ConditionManager {

    private final ArrayList<ConditionListener> mListeners = new ArrayList<>();

    private ConditionManager(Context context) {
    private ConditionManager(Context context, boolean loadConditionsNow) {
        mContext = context;
        mConditions = new ArrayList<>();
        if (loadConditionsNow) {
            ConditionLoader loader = new ConditionLoader();
            loader.onPostExecute(loader.doInBackground());
        } else {
            new ConditionLoader().execute();
        }
    }

    public void refreshAll() {
        final int N = mConditions.size();
@@ -241,8 +246,12 @@ public class ConditionManager {
    }

    public static ConditionManager get(Context context) {
        return get(context, true);
    }

    public static ConditionManager get(Context context, boolean loadConditionsNow) {
        if (sInstance == null) {
            sInstance = new ConditionManager(context.getApplicationContext());
            sInstance = new ConditionManager(context.getApplicationContext(), loadConditionsNow);
        }
        return sInstance;
    }