Skip to content

Commit

Permalink
Allow setters (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmerinojimenez authored Apr 13, 2023
1 parent 93a0f37 commit ecb577d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions library/src/enabled/java/com/telefonica/tweaks/Tweaks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ open class Tweaks {

open fun <T> getTweakValue(key: String): Flow<T?> = tweaksBusinessLogic.getValue(key)

open suspend fun <T> setTweakValue(key: String, value: T) {
tweaksBusinessLogic.setValue(key, value)
}

open suspend fun clearValue(key: String) {
tweaksBusinessLogic.clearValue(key)
}

private fun initializeGraph(tweaksGraph: TweaksGraph) {
tweaksBusinessLogic.initialize(tweaksGraph)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ class TweaksBusinessLogic @Inject constructor(
setValue(tweakEntry, value)
}

suspend fun <T> clearValue(key: String) {
val tweakEntry = keyToEntryValueMap[key] as Editable<T>
suspend fun clearValue(key: String) {
val tweakEntry = keyToEntryValueMap[key] as Editable<*>
clearValue(tweakEntry)
}

Expand Down
4 changes: 4 additions & 0 deletions library/src/noop/java/com/telefonica/tweaks/Tweaks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ open class Tweaks {
else -> flowOf()
}

open suspend fun <T> setTweakValue(key: String, value: T) {}

open suspend fun clearValue(key: String) {}

private fun initialize(tweaksGraph: TweaksGraph) {
val allEntries: List<Editable<*>> = tweaksGraph.categories
.flatMap { category ->
Expand Down

0 comments on commit ecb577d

Please sign in to comment.