summaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net/taler
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2023-09-14 13:44:47 -0600
committerTorsten Grote <t@grobox.de>2023-09-26 18:30:52 +0200
commit138ea1388d4da7b6ca50a16e369d8e45a670089f (patch)
tree83ad895f7dcaa82bc2f04fc429043e40378dabfb /wallet/src/main/java/net/taler
parented7f77234259113007af8cabeed32a560ccd4f32 (diff)
downloadtaler-android-138ea1388d4da7b6ca50a16e369d8e45a670089f.tar.gz
taler-android-138ea1388d4da7b6ca50a16e369d8e45a670089f.tar.bz2
taler-android-138ea1388d4da7b6ca50a16e369d8e45a670089f.zip
[wallet] Support 0.x fractions in AmountInputField
Diffstat (limited to 'wallet/src/main/java/net/taler')
-rw-r--r--wallet/src/main/java/net/taler/wallet/compose/AmountInputField.kt27
1 files changed, 17 insertions, 10 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/compose/AmountInputField.kt b/wallet/src/main/java/net/taler/wallet/compose/AmountInputField.kt
index 79a01c8..df82546 100644
--- a/wallet/src/main/java/net/taler/wallet/compose/AmountInputField.kt
+++ b/wallet/src/main/java/net/taler/wallet/compose/AmountInputField.kt
@@ -30,6 +30,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.text.TextStyle
+import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.VisualTransformation
import net.taler.common.Amount
@@ -56,21 +57,27 @@ fun AmountInputField(
colors: TextFieldColors = TextFieldDefaults.outlinedTextFieldColors()
) {
OutlinedTextField(
- value = if (value == "0" || value.endsWith(".0")) value.trimEnd('0') else value,
+ value = when {
+ value == "0" -> ""
+ value.startsWith("0.") -> value.trimStart('0')
+ value.endsWith(".0") -> value.trimEnd('0')
+ else -> value
+ },
onValueChange = { input ->
- if (input.isNotBlank()) {
- val filtered = input.filter { it.isDigit() || it == '.' }.let {
- if (it == "" || it.endsWith(".")) "${it}0" else it
- }
- if (Amount.isValidAmountStr(filtered)) {
- onValueChange(filtered)
- }
- } else onValueChange("0")
+ val filtered = when {
+ input.isEmpty() -> "0"
+ input.startsWith(".") -> "0${input}"
+ input.endsWith(".") -> "${input}0"
+ else -> input
+ }
+ if (Amount.isValidAmountStr(filtered)) {
+ onValueChange(filtered)
+ }
},
modifier = modifier,
enabled = enabled,
readOnly = readOnly,
- textStyle = textStyle,
+ textStyle = textStyle.copy(fontFamily = FontFamily.Monospace),
label = label,
placeholder = { Text("0") },
leadingIcon = leadingIcon,