mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-09 16:17:44 +00:00
improve behvavior of slider preference
using onConfirm instead of always onValueChange (which is called when sliding, but we're mostly interested in changed settings)
This commit is contained in:
parent
1d441a8ca6
commit
b5dece2ff4
2 changed files with 10 additions and 4 deletions
|
@ -27,6 +27,7 @@ fun <T: Number> SliderPreference(
|
|||
range: ClosedFloatingPointRange<Float>,
|
||||
stepSize: Int? = null,
|
||||
onValueChanged: (Float?) -> Unit = { },
|
||||
onConfirmed: (T) -> Unit = { },
|
||||
) {
|
||||
val ctx = LocalContext.current
|
||||
val prefs = ctx.prefs()
|
||||
|
@ -48,8 +49,13 @@ fun <T: Number> SliderPreference(
|
|||
SliderDialog(
|
||||
onDismissRequest = { showDialog = false },
|
||||
onDone = {
|
||||
if (default is Int) prefs.edit().putInt(key, it.toInt()).apply()
|
||||
else prefs.edit().putFloat(key, it).apply()
|
||||
if (default is Int) {
|
||||
prefs.edit().putInt(key, it.toInt()).apply()
|
||||
onConfirmed(it.toInt() as T)
|
||||
} else {
|
||||
prefs.edit().putFloat(key, it).apply()
|
||||
onConfirmed(it as T)
|
||||
}
|
||||
},
|
||||
initialValue = initialValue.toFloat(),
|
||||
range = range,
|
||||
|
@ -59,7 +65,7 @@ fun <T: Number> SliderPreference(
|
|||
},
|
||||
onValueChanged = onValueChanged,
|
||||
showDefault = true,
|
||||
onDefault = { prefs.edit().remove(key).apply(); onValueChanged(null) },
|
||||
onDefault = { prefs.edit().remove(key).apply(); onConfirmed(default) },
|
||||
intermediateSteps = stepSize?.let {
|
||||
// this is not nice, but slider wants it like this...
|
||||
((range.endInclusive - range.start) / it - 1).toInt()
|
||||
|
|
|
@ -233,7 +233,7 @@ fun createAdvancedSettings(context: Context) = listOf(
|
|||
else -> "version unknown"
|
||||
}
|
||||
},
|
||||
onValueChanged = { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
|
||||
onConfirmed = { KeyboardSwitcher.getInstance().setThemeNeedsReload() }
|
||||
)
|
||||
},
|
||||
Setting(context, Settings.PREF_URL_DETECTION, R.string.url_detection_title, R.string.url_detection_summary) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue