From c821eb368150484246f04c6be83c0c27abc65ced Mon Sep 17 00:00:00 2001 From: andrekir Date: Wed, 26 Apr 2023 18:21:27 -0300 Subject: [PATCH] fix #625: handle Samsung Keyboard dot-minus key in TextField validation Samsung Keyboard numerical keypad features a combined '.-' key that outputs a dot (.) on first press and replaces it with a minus (-) on second press. there is no option to output each symbol separately (short or long press, etc). updated validation logic to handle dot symbol at the start of the input string. --- .../com/geeksville/mesh/ui/components/EditTextPreference.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/components/EditTextPreference.kt b/app/src/main/java/com/geeksville/mesh/ui/components/EditTextPreference.kt index dce220df9..413470fdc 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/components/EditTextPreference.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/components/EditTextPreference.kt @@ -101,6 +101,7 @@ fun EditTextPreference( modifier: Modifier = Modifier, ) { var valueState by remember(value) { mutableStateOf(value.toString()) } + val decimalSeparators = setOf('.', ',', '٫', '、', '·') // set of possible decimal separators EditTextPreference( title = title, @@ -112,7 +113,7 @@ fun EditTextPreference( ), keyboardActions = keyboardActions, onValueChanged = { - if (it.isEmpty()) valueState = it + if (it.length <= 1 || it.first() in decimalSeparators) valueState = it else it.toDoubleOrNull()?.let { double -> valueState = it onValueChanged(double)