fix: PreferenceFlowWrapper
This commit is contained in:
parent
0bd64a0ab6
commit
36afc1df71
1 changed files with 3 additions and 6 deletions
|
@ -63,11 +63,8 @@ class PreferenceFlowWrapper<T> private constructor(
|
|||
inner: Flow<T>,
|
||||
private val setter: suspend (T) -> T = { it }
|
||||
) : Flow<T> by inner {
|
||||
internal constructor(context: Context, key: Preferences.Key<T>, defaultValue: T) : this(
|
||||
context,
|
||||
key,
|
||||
context.dataStore.data.map { it[key] ?: defaultValue }
|
||||
)
|
||||
internal constructor(context: Context, key: Preferences.Key<T>, defaultValue: T) :
|
||||
this(context, key, context.dataStore.data.map { it[key] ?: defaultValue })
|
||||
|
||||
suspend fun updatePreference(value: T) {
|
||||
context.dataStore.edit { it[key] = setter(value) }
|
||||
|
@ -77,4 +74,4 @@ class PreferenceFlowWrapper<T> private constructor(
|
|||
PreferenceFlowWrapper(context, key, flow, setter)
|
||||
}
|
||||
|
||||
fun PreferenceFlowWrapper<Boolean>.negative() = with(map { !it }, { !it })
|
||||
fun PreferenceFlowWrapper<Boolean>.negative() = with(map { !it }) { !it }
|
||||
|
|
Loading…
Add table
Reference in a new issue