mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Preserve widgets from Loop 1.7.11 and lower versions
This commit is contained in:
@@ -38,7 +38,17 @@ public class WidgetPreferences {
|
||||
}
|
||||
|
||||
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();
|
||||
return habitIds;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user