reverting preference set changes
This commit is contained in:
parent
34aa7f9502
commit
20e4470511
|
@ -19,24 +19,12 @@ internal class SharedPreferencesDelegate(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun store(key: String, value: Set<String>) {
|
|
||||||
coroutineDispatchers.withIoContext {
|
|
||||||
preferences.edit().putStringSet(key, value).apply()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun readString(key: String): String? {
|
override suspend fun readString(key: String): String? {
|
||||||
return coroutineDispatchers.withIoContext {
|
return coroutineDispatchers.withIoContext {
|
||||||
preferences.getString(key, null)
|
preferences.getString(key, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun readStrings(key: String): Set<String>? {
|
|
||||||
return coroutineDispatchers.withIoContext {
|
|
||||||
preferences.getStringSet(key, null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun remove(key: String) {
|
override suspend fun remove(key: String) {
|
||||||
coroutineDispatchers.withIoContext {
|
coroutineDispatchers.withIoContext {
|
||||||
preferences.edit().remove(key).apply()
|
preferences.edit().remove(key).apply()
|
||||||
|
|
|
@ -3,9 +3,7 @@ package app.dapk.st.core
|
||||||
interface Preferences {
|
interface Preferences {
|
||||||
|
|
||||||
suspend fun store(key: String, value: String)
|
suspend fun store(key: String, value: String)
|
||||||
suspend fun store(key: String, value: Set<String>)
|
|
||||||
suspend fun readString(key: String): String?
|
suspend fun readString(key: String): String?
|
||||||
suspend fun readStrings(key: String): Set<String>?
|
|
||||||
suspend fun clear()
|
suspend fun clear()
|
||||||
suspend fun remove(key: String)
|
suspend fun remove(key: String)
|
||||||
}
|
}
|
||||||
|
@ -20,13 +18,4 @@ suspend fun CachedPreferences.readBoolean(key: String, defaultValue: Boolean) =
|
||||||
|
|
||||||
suspend fun Preferences.readBoolean(key: String) = this.readString(key)?.toBooleanStrict()
|
suspend fun Preferences.readBoolean(key: String) = this.readString(key)?.toBooleanStrict()
|
||||||
suspend fun Preferences.store(key: String, value: Boolean) = this.store(key, value.toString())
|
suspend fun Preferences.store(key: String, value: Boolean) = this.store(key, value.toString())
|
||||||
suspend fun Preferences.append(key: String, value: String): Set<String> {
|
|
||||||
val current = this.readStrings(key) ?: emptySet()
|
|
||||||
return (current + value).also { this.store(key, it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun Preferences.removeFromSet(key: String, value: String): Set<String> {
|
|
||||||
val current = this.readStrings(key) ?: emptySet()
|
|
||||||
return (current - value).also { this.store(key, it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -10,17 +10,6 @@ class CachingPreferences(private val cache: PropertyCache, private val preferenc
|
||||||
preferences.store(key, value)
|
preferences.store(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun store(key: String, value: Set<String>) {
|
|
||||||
cache.setValue(key, value)
|
|
||||||
preferences.store(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun readStrings(key: String): Set<String>? {
|
|
||||||
return cache.getValue(key) ?: preferences.readStrings(key)?.also {
|
|
||||||
cache.setValue(key, it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun readString(key: String): String? {
|
override suspend fun readString(key: String): String? {
|
||||||
return cache.getValue(key) ?: preferences.readString(key)?.also {
|
return cache.getValue(key) ?: preferences.readString(key)?.also {
|
||||||
cache.setValue(key, it)
|
cache.setValue(key, it)
|
||||||
|
|
|
@ -5,27 +5,19 @@ import app.dapk.st.core.Preferences
|
||||||
class InMemoryPreferences : Preferences {
|
class InMemoryPreferences : Preferences {
|
||||||
|
|
||||||
private val prefs = mutableMapOf<String, String>()
|
private val prefs = mutableMapOf<String, String>()
|
||||||
private val setPrefs = mutableMapOf<String, Set<String>>()
|
|
||||||
|
|
||||||
override suspend fun store(key: String, value: String) {
|
override suspend fun store(key: String, value: String) {
|
||||||
prefs[key] = value
|
prefs[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun store(key: String, value: Set<String>) {
|
|
||||||
setPrefs[key] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun readString(key: String): String? = prefs[key]
|
override suspend fun readString(key: String): String? = prefs[key]
|
||||||
override suspend fun readStrings(key: String): Set<String>? = setPrefs[key]
|
|
||||||
|
|
||||||
override suspend fun remove(key: String) {
|
override suspend fun remove(key: String) {
|
||||||
prefs.remove(key)
|
prefs.remove(key)
|
||||||
setPrefs.remove(key)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun clear() {
|
override suspend fun clear() {
|
||||||
prefs.clear()
|
prefs.clear()
|
||||||
setPrefs.clear()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue