[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.
- [taler-taler-android] branch master updated (d7196a0 -> e7e2763), gnunet, 2023/09/26
- [taler-taler-android] 03/14: [wallet] first cleanup of payment template work, gnunet, 2023/09/26
- [taler-taler-android] 01/14: [wallet] Initial version of template support, gnunet, 2023/09/26
- [taler-taler-android] 10/14: [wallet] Improved AmountInputField with a VisualTransformation, gnunet, 2023/09/26
- [taler-taler-android] 11/14: [wallet] fix: AmountInputField reacts to external changes, gnunet, 2023/09/26
- [taler-taler-android] 05/14: [wallet] add some potential TODOs for pay templates, gnunet, 2023/09/26
- [taler-taler-android] 09/14: [wallet] Support 0.x fractions in AmountInputField,
gnunet <=
- [taler-taler-android] 04/14: [wallet] Improve internal logic of templates, gnunet, 2023/09/26
- [taler-taler-android] 08/14: [wallet] Refactor amount input into single composable, gnunet, 2023/09/26
- [taler-taler-android] 02/14: [wallet] Improved templates UX and PoS confirmation codes, gnunet, 2023/09/26
- [taler-taler-android] 14/14: [wallet] Fix back navigation after template prompt., gnunet, 2023/09/26
- [taler-taler-android] 13/14: [wallet] simplify pay templates, gnunet, 2023/09/26
- [taler-taler-android] 12/14: [wallet] simplify AmountInputField, gnunet, 2023/09/26
- [taler-taler-android] 06/14: [wallet] Additional refactoring of pay templates, gnunet, 2023/09/26
- [taler-taler-android] 07/14: [wallet] fixes for templates parsing and UI, gnunet, 2023/09/26