mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-22 11:08:54 +02:00
Add app settings to backups
This should be compatible with Aniyomi's implementation. Related to #1857 Co-authored-by: jmir1 <jmir1@users.noreply.github.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import tachiyomi.core.util.system.logcat
|
||||
|
||||
sealed class AndroidPreference<T>(
|
||||
private val preferences: SharedPreferences,
|
||||
@@ -29,7 +30,13 @@ sealed class AndroidPreference<T>(
|
||||
}
|
||||
|
||||
override fun get(): T {
|
||||
return read(preferences, key, defaultValue)
|
||||
return try {
|
||||
read(preferences, key, defaultValue)
|
||||
} catch (e: ClassCastException) {
|
||||
logcat { "Invalid value for $key; deleting" }
|
||||
delete()
|
||||
defaultValue
|
||||
}
|
||||
}
|
||||
|
||||
override fun set(value: T) {
|
||||
|
@@ -60,6 +60,10 @@ class AndroidPreferenceStore(
|
||||
deserializer = deserializer,
|
||||
)
|
||||
}
|
||||
|
||||
override fun getAll(): Map<String, *> {
|
||||
return sharedPreferences.all ?: emptyMap<String, Any>()
|
||||
}
|
||||
}
|
||||
|
||||
private val SharedPreferences.keyFlow
|
||||
|
@@ -20,6 +20,8 @@ interface PreferenceStore {
|
||||
serializer: (T) -> String,
|
||||
deserializer: (String) -> T,
|
||||
): Preference<T>
|
||||
|
||||
fun getAll(): Map<String, *>
|
||||
}
|
||||
|
||||
inline fun <reified T : Enum<T>> PreferenceStore.getEnum(
|
||||
|
Reference in New Issue
Block a user