reverting preference set changes

This commit is contained in:
Adam Brown 2022-11-02 14:33:27 +00:00
parent 34aa7f9502
commit 20e4470511
4 changed files with 1 additions and 43 deletions

View File

@ -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? {
return coroutineDispatchers.withIoContext {
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) {
coroutineDispatchers.withIoContext {
preferences.edit().remove(key).apply()

View File

@ -3,9 +3,7 @@ package app.dapk.st.core
interface Preferences {
suspend fun store(key: String, value: String)
suspend fun store(key: String, value: Set<String>)
suspend fun readString(key: String): String?
suspend fun readStrings(key: String): Set<String>?
suspend fun clear()
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.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) }
}

View File

@ -10,17 +10,6 @@ class CachingPreferences(private val cache: PropertyCache, private val preferenc
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? {
return cache.getValue(key) ?: preferences.readString(key)?.also {
cache.setValue(key, it)

View File

@ -5,27 +5,19 @@ import app.dapk.st.core.Preferences
class InMemoryPreferences : Preferences {
private val prefs = mutableMapOf<String, String>()
private val setPrefs = mutableMapOf<String, Set<String>>()
override suspend fun store(key: String, value: String) {
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 readStrings(key: String): Set<String>? = setPrefs[key]
override suspend fun remove(key: String) {
prefs.remove(key)
setPrefs.remove(key)
}
override suspend fun clear() {
prefs.clear()
setPrefs.clear()
}
}