From: Damyan Ivanov Date: Thu, 23 Jan 2020 19:04:17 +0000 (+0200) Subject: slight improvement in allowing "-" only at the eginning of the amount X-Git-Tag: v0.12.0~98 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=795afbd36113a53f1846a69abb260fa46b3ffc64;p=mobile-ledger.git slight improvement in allowing "-" only at the eginning of the amount --- 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);