gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-android] 09/14: [wallet] Support 0.x fractions in AmountInp


From: gnunet
Subject: [taler-taler-android] 09/14: [wallet] Support 0.x fractions in AmountInputField
Date: Tue, 26 Sep 2023 18:31:29 +0200

This is an automated email from the git hooks/post-receive script.

torsten-grote pushed a commit to branch master
in repository taler-android.

commit 138ea1388d4da7b6ca50a16e369d8e45a670089f
Author: Iván Ávalos <avalos@disroot.org>
AuthorDate: Thu Sep 14 13:44:47 2023 -0600

    [wallet] Support 0.x fractions in AmountInputField
---
 .../net/taler/wallet/compose/AmountInputField.kt   | 27 ++++++++++++++--------
 1 file 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,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]