]> git.ktnx.net Git - mobile-ledger.git/commitdiff
new transaction: locale-aware number formatting (broken in RecyclerView migration)
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 13 Nov 2019 21:36:52 +0000 (23:36 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 13 Nov 2019 21:37:03 +0000 (23:37 +0200)
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java
app/src/main/res/layout/new_transaction_row.xml
app/src/main/res/values-bg/strings.xml
app/src/main/res/values/strings.xml

index a5a4541fd3579635fe102e53dc55f1a14f327ad7..123b91e93ae534e24103b2a3e3a572f729006812 100644 (file)
@@ -17,6 +17,7 @@
 
 package net.ktnx.mobileledger.ui.activity;
 
+import android.annotation.SuppressLint;
 import android.text.Editable;
 import android.text.TextWatcher;
 import android.view.View;
@@ -149,6 +150,9 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
                 return;
             syncingData = true;
             try {
+                if (hint == null)
+                    hint = tvAmount.getResources()
+                                   .getString(R.string.zero_amount);
                 tvAmount.setHint(hint);
             }
             finally {
@@ -289,6 +293,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
      *
      * @param item updates the UI elements with the data from the model item
      */
+    @SuppressLint("DefaultLocale")
     public void setData(NewTransactionModel.Item item) {
         beginUpdates();
         try {
@@ -318,8 +323,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
                     LedgerTransactionAccount acc = item.getAccount();
                     tvAccount.setText(acc.getAccountName());
                     tvAmount.setText(
-                            acc.isAmountSet() ? String.format(Locale.US, "%1.2f", acc.getAmount())
-                                              : "");
+                            acc.isAmountSet() ? String.format("%1.2f", acc.getAmount()) : "");
                     lHead.setVisibility(View.GONE);
                     lAccount.setVisibility(View.VISIBLE);
                     lPadding.setVisibility(View.GONE);
index bbfedcbc1aae2a870a10934f91023d67bd7c60ec..914a478b14945bce6c6f49f5ce7e8c930d8f9172 100644 (file)
@@ -17,6 +17,8 @@
 
 package net.ktnx.mobileledger.ui.activity;
 
+import android.annotation.SuppressLint;
+
 import androidx.annotation.NonNull;
 import androidx.lifecycle.LiveData;
 import androidx.lifecycle.MutableLiveData;
@@ -43,7 +45,6 @@ public class NewTransactionModel extends ViewModel {
     static final Pattern reYMD = Pattern.compile("^\\s*(\\d+)\\d*/\\s*(\\d+)\\s*/\\s*(\\d+)\\s*$");
     static final Pattern reMD = Pattern.compile("^\\s*(\\d+)\\s*/\\s*(\\d+)\\s*$");
     static final Pattern reD = Pattern.compile("\\s*(\\d+)\\s*$");
-    private static final String ZERO_AMOUNT_HINT = "0.00";
     private final Item header = new Item(this, null, "");
     private final Item trailer = new Item(this);
     private final ArrayList<Item> items = new ArrayList<>();
@@ -129,6 +130,7 @@ public class NewTransactionModel extends ViewModel {
     // 3a) there must be exactly one empty amount
     // 4) empty accounts with empty amounts are ignored
     // 5) a row with an empty account name or empty amount is guaranteed to exist
+    @SuppressLint("DefaultLocale")
     public void checkTransactionSubmittable(NewTransactionItemsAdapter adapter) {
         int accounts = 0;
         int accounts_with_values = 0;
@@ -191,18 +193,17 @@ public class NewTransactionModel extends ViewModel {
 
                 if (single_empty_amount) {
                     if (item.equals(empty_amount)) {
-                        empty_amount.setAmountHint(String.format(Locale.US, "%1.2f",
-                                Misc.isZero(running_total) ? 0f : -running_total));
+                        empty_amount.setAmountHint(Misc.isZero(running_total) ? null
+                                                                              : String.format(
+                                                                                      "%1.2f",
+                                                                                      -running_total));
                         continue;
                     }
                 }
                 else {
                     // no single empty account and this account's amount is not set
                     // => hint should be '0.00'
-                    String hint = item.getAmountHint();
-                    if ((hint == null) || !hint.equals(ZERO_AMOUNT_HINT)) {
-                        item.setAmountHint(ZERO_AMOUNT_HINT);
-                    }
+                    item.setAmountHint(null);
                 }
 
             }
index da1514208045e39ac5f96ad23c769a4ee9618aa3..707c7b0d25a0f54ecd02a58ffab5f46b71c6edcb 100644 (file)
             android:width="0dp"
             android:foregroundGravity="bottom"
             android:gravity="bottom|end"
-            android:hint="0.00"
-            android:inputType="numberSigned|numberDecimal"
+            android:hint="@string/zero_amount"
+            android:inputType="numberSigned|numberDecimal|number"
             android:minWidth="70sp"
             android:textAlignment="viewEnd"
             android:selectAllOnFocus="true"
-            tools:ignore="HardcodedText"
             android:imeOptions="actionNext"/>
 
     </LinearLayout>
index f73bd94d27493b6315bda0da47835a16b95fc72d..be9004e3c7cc9d546b09ba58786ab83a8a8f690d 100644 (file)
     <string name="err_invalid_url">Грешен или непълен адрес</string>
     <string name="btn_color_picker_button">Бутон за избор на цвят</string>
     <string name="insecure_scheme_with_auth">ВНИМАНИЕ: Използване на удостоверяване с несигурна схема на достъп</string>
+    <string name="zero_amount">0,00</string>
 
 </resources>
index bdfbf3e73d9de5312e2bec3e6a3b152d449c9579..837daf773ed03d3b230ae900ec21b25bd9639473 100644 (file)
     <string name="err_invalid_url">Invalid URL</string>
     <string name="btn_color_picker_button">Color picker button</string>
     <string name="insecure_scheme_with_auth">WARNING: Insecure http used with authentication</string>
+    <string name="zero_amount">0.00</string>
 </resources>