mirror of
https://github.com/bbara04/Purefin.git
synced 2026-07-23 19:26:50 +00:00
feat: enhance settings screen with dropdown and void setting options for improved user experience
This commit is contained in:
@@ -2,7 +2,8 @@ package hu.bbara.purefin.data.settings
|
||||
|
||||
import androidx.datastore.core.DataStore
|
||||
import hu.bbara.purefin.core.settings.BooleanSetting
|
||||
import hu.bbara.purefin.core.settings.NumberSetting
|
||||
import hu.bbara.purefin.core.settings.DropdownSetting
|
||||
import hu.bbara.purefin.core.settings.RangeSetting
|
||||
import hu.bbara.purefin.core.settings.SettingsRepository
|
||||
import hu.bbara.purefin.core.settings.StringSetting
|
||||
import hu.bbara.purefin.model.Settings
|
||||
@@ -17,7 +18,7 @@ class SettingsRepositoryImpl @Inject constructor(
|
||||
|
||||
override val settings: Flow<Settings> = settingsDataStore.data
|
||||
|
||||
override fun value(option: NumberSetting): Flow<Double> {
|
||||
override fun value(option: RangeSetting): Flow<Double> {
|
||||
return settings
|
||||
.map { it.numberSettings[option.key] ?: option.defaultValue }
|
||||
.distinctUntilChanged()
|
||||
@@ -35,7 +36,16 @@ class SettingsRepositoryImpl @Inject constructor(
|
||||
.distinctUntilChanged()
|
||||
}
|
||||
|
||||
override suspend fun set(option: NumberSetting, value: Double) {
|
||||
override fun <T> value(option: DropdownSetting<T>): Flow<T> {
|
||||
return settings
|
||||
.map { settings ->
|
||||
val storedValue = settings.stringSettings[option.key]
|
||||
option.options.firstOrNull { it.toString() == storedValue } ?: option.defaultValue
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
}
|
||||
|
||||
override suspend fun set(option: RangeSetting, value: Double) {
|
||||
settingsDataStore.updateData { current ->
|
||||
current.copy(
|
||||
numberSettings = current.numberSettings + (option.key to value)
|
||||
@@ -58,4 +68,12 @@ class SettingsRepositoryImpl @Inject constructor(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun <T> set(option: DropdownSetting<T>, value: T) {
|
||||
settingsDataStore.updateData { current ->
|
||||
current.copy(
|
||||
stringSettings = current.stringSettings + (option.key to value.toString())
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user