|
|
@ -27,19 +27,18 @@ class WidgetPreferences @Inject constructor(private val storage: Preferences.Sto
|
|
|
|
storage.putLongArray(getHabitIdKey(widgetId), habitIds)
|
|
|
|
storage.putLongArray(getHabitIdKey(widgetId), habitIds)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun getHabitIdsFromWidgetId(widgetId: Int): LongArray? {
|
|
|
|
fun getHabitIdsFromWidgetId(widgetId: Int): LongArray {
|
|
|
|
var habitIds: LongArray?
|
|
|
|
|
|
|
|
val habitIdKey = getHabitIdKey(widgetId)
|
|
|
|
val habitIdKey = getHabitIdKey(widgetId)
|
|
|
|
try {
|
|
|
|
return try {
|
|
|
|
habitIds = storage.getLongArray(habitIdKey, longArrayOf(-1))
|
|
|
|
storage.getLongArray(habitIdKey, longArrayOf())
|
|
|
|
} catch (e: ClassCastException) {
|
|
|
|
} catch (e: ClassCastException) {
|
|
|
|
// Up to Loop 1.7.11, this preference was not an array, but a single
|
|
|
|
// 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.
|
|
|
|
// long. Trying to read the old preference causes a cast exception.
|
|
|
|
habitIds = LongArray(1)
|
|
|
|
when (val habitId = storage.getLong(habitIdKey, -1)) {
|
|
|
|
habitIds[0] = storage.getLong(habitIdKey, -1)
|
|
|
|
-1L -> longArrayOf()
|
|
|
|
storage.putLongArray(habitIdKey, habitIds)
|
|
|
|
else -> longArrayOf(habitId)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return habitIds
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun removeWidget(id: Int) {
|
|
|
|
fun removeWidget(id: Int) {
|
|
|
|