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
This commit is contained in:
Jason Monk
2016-05-26 11:07:53 -04:00
parent eb02435cbf
commit e4d0ed502d
2 changed files with 13 additions and 4 deletions

View File

@@ -54,10 +54,15 @@ 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<>();
new ConditionLoader().execute();
if (loadConditionsNow) {
ConditionLoader loader = new ConditionLoader();
loader.onPostExecute(loader.doInBackground());
} else {
new ConditionLoader().execute();
}
}
public void refreshAll() {
@@ -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;
}