mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 09:38:52 -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) {
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user