From 795afbd36113a53f1846a69abb260fa46b3ffc64 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Thu, 23 Jan 2020 21:04:17 +0200 Subject: [PATCH] slight improvement in allowing "-" only at the eginning of the amount --- .../ui/activity/NewTransactionItemHolder.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java index 504ec0ad..45a57e54 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java @@ -67,7 +67,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder private AutoCompleteTextView tvDescription; private AutoCompleteTextView tvAccount; private TextView tvComment; - private TextView tvAmount; + private EditText tvAmount; private LinearLayout lHead; private ViewGroup lAccount; private FrameLayout lPadding; @@ -187,15 +187,14 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { // only one decimal separator is allowed // plus and minus are allowed only at the beginning + String allowed = "0123456789"; String val = s.toString(); - if (val.isEmpty()) - tvAmount.setKeyListener(DigitsKeyListener.getInstance( - "0123456789+-" + decimalSeparator + decimalDot)); - else if (val.contains(decimalSeparator) || val.contains(decimalDot)) - tvAmount.setKeyListener(DigitsKeyListener.getInstance("0123456789")); - else - tvAmount.setKeyListener(DigitsKeyListener.getInstance( - "0123456789" + decimalSeparator + decimalDot)); + if (val.isEmpty() || (tvAmount.getSelectionStart() == 0)) + allowed += "-"; + if (!val.contains(decimalSeparator) && !val.contains(decimalDot)) + allowed += decimalSeparator + decimalDot; + + tvAmount.setKeyListener(DigitsKeyListener.getInstance(allowed)); syncData(); adapter.model.checkTransactionSubmittable(adapter); -- 2.39.5