Use steps for keyboard height and offset

This commit is contained in:
Aleksandras Kostarevas 2024-05-08 13:10:55 -05:00
parent 49cbcabf5e
commit 21d55993f0
3 changed files with 25 additions and 11 deletions

View File

@ -392,7 +392,7 @@ fun<T: Number> SettingSlider(
) { ) {
SettingSliderForDataStoreItem( SettingSliderForDataStoreItem(
title = title, title = title,
item = useDataStore(setting), item = useDataStore(setting, blocking = true),
default = setting.default, default = setting.default,
range = range, range = range,
transform = transform, transform = transform,

View File

@ -51,17 +51,27 @@ fun <T> useDataStoreValueBlocking(v: SettingsKey<T>): T {
} }
@Composable @Composable
fun <T> useDataStore(key: Preferences.Key<T>, default: T): DataStoreItem<T> { fun <T> useDataStore(key: Preferences.Key<T>, default: T, blocking: Boolean = false): DataStoreItem<T> {
val context = LocalContext.current val context = LocalContext.current
val coroutineScope = rememberCoroutineScope() val coroutineScope = rememberCoroutineScope()
val enableSoundFlow: Flow<T> = remember { val initialValue = remember {
context.dataStore.data.map { if(blocking) {
preferences -> preferences[key] ?: default runBlocking {
context.getSetting(key, default)
}
} else {
default
} }
} }
val value = enableSoundFlow.collectAsState(initial = default).value!! val valueFlow: Flow<T> = remember {
context.dataStore.data.map { preferences ->
preferences[key] ?: default
}
}
val value = valueFlow.collectAsState(initial = initialValue).value!!
val setValue = { newValue: T -> val setValue = { newValue: T ->
coroutineScope.launch { coroutineScope.launch {
@ -76,8 +86,8 @@ fun <T> useDataStore(key: Preferences.Key<T>, default: T): DataStoreItem<T> {
@Composable @Composable
fun <T> useDataStore(key: SettingsKey<T>): DataStoreItem<T> { fun <T> useDataStore(key: SettingsKey<T>, blocking: Boolean = false): DataStoreItem<T> {
return useDataStore(key.key, key.default) return useDataStore(key.key, key.default, blocking)
} }
@Composable @Composable

View File

@ -227,15 +227,19 @@ fun ThemePicker(onSelected: (ThemeOption) -> Unit) {
title = "Keyboard Height", title = "Keyboard Height",
setting = KeyboardHeightMultiplierSetting, setting = KeyboardHeightMultiplierSetting,
range = 0.33f .. 1.75f, transform = { it }, range = 0.33f .. 1.75f, transform = { it },
indicator = { "${(it * 100.0f).roundToInt()}%" } indicator = { "${(it * 100.0f).roundToInt()}%" },
steps = 16
) )
} }
item(span = { GridItemSpan(maxCurrentLineSpan) }) { item(span = { GridItemSpan(maxCurrentLineSpan) }) {
SettingSlider( SettingSlider(
title = "Keyboard Offset", title = "Keyboard Offset",
setting = KeyboardBottomOffsetSetting, setting = KeyboardBottomOffsetSetting,
range = 0.0f .. 128.0f, transform = { it }, range = 0.0f .. 50.0f,
indicator = { "${String.format("%.1f", it)} dp" } hardRange = 0.0f .. 250.0f,
transform = { it },
indicator = { "${String.format("%.1f", it)} dp" },
steps = 9
) )
} }
} }