Preserve widgets from Loop 1.7.11 and lower versions

pull/538/head
Alinson S. Xavier 6 years ago
parent 38d5b2bf16
commit e3f6353062

@ -38,7 +38,17 @@ public class WidgetPreferences {
} }
public long[] getHabitIdsFromWidgetId(int widgetId) { public long[] getHabitIdsFromWidgetId(int widgetId) {
long habitIds[] = storage.getLongArray(getHabitIdKey(widgetId)); long habitIds[];
String habitIdKey = getHabitIdKey(widgetId);
try {
habitIds = storage.getLongArray(habitIdKey);
} catch (ClassCastException e) {
// Up to Loop 1.7.11, this preference was not an array, but a single
// long. Trying to read the old preference causes a cast exception.
habitIds = new long[1];
habitIds[0] = storage.getLong(habitIdKey, -1);
storage.putLongArray(habitIdKey, habitIds);
}
if (habitIds.length == 0) throw new HabitNotFoundException(); if (habitIds.length == 0) throw new HabitNotFoundException();
return habitIds; return habitIds;
} }

Loading…
Cancel
Save