Skip to content

Commit b7e67f6

Browse files
Fixing default values
1 parent 2d3361d commit b7e67f6

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

library/src/enabled/java/com/gmerinojimenez/tweak/domain/TweaksBusinessLogic.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ class TweaksBusinessLogic @Inject constructor(
4242
}
4343

4444
@Suppress("UNCHECKED_CAST")
45-
fun <T> getValue(key: String): Flow<T?> = tweaksDataStore.data
46-
.map { preferences -> preferences[buildKey(keyToEntryValueMap[key] as TweakEntry<T>)] }
45+
fun <T> getValue(key: String): Flow<T?> {
46+
val tweakEntry = keyToEntryValueMap[key] as TweakEntry<T>
47+
return getValue(tweakEntry)
48+
}
4749

4850
fun <T> getValue(entry: TweakEntry<T>): Flow<T?> = when (entry as Modifiable) {
4951
is ReadOnly<*> -> (entry as ReadOnly<T>).value
@@ -54,13 +56,10 @@ class TweaksBusinessLogic @Inject constructor(
5456
private fun <T> getEditableValue(entry: TweakEntry<T>): Flow<T?> {
5557
val editableCasted = entry as Editable<T>
5658
val defaultValue = editableCasted.defaultValue
57-
return if (defaultValue != null) {
58-
defaultValue.combine(getFromStorage(entry)) { default, storage ->
59-
storage ?: default
60-
}
61-
} else {
62-
getFromStorage(entry)
59+
return defaultValue?.combine(getFromStorage(entry)) { default, storage ->
60+
storage ?: default
6361
}
62+
?: getFromStorage(entry)
6463
}
6564

6665
private fun <T> getFromStorage(entry: TweakEntry<T>) =

0 commit comments

Comments
 (0)