]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionItemHolder.java
avoid dataSync when updating entered amount format on losing focus
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / new_transaction / NewTransactionItemHolder.java
index 01c3bfdf7d07667025666542ba746a17cc5afa5f..6df1b5406cac95c88d9f25565f4374b4764cf2b6 100644 (file)
@@ -125,8 +125,16 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
                         String input = String.valueOf(b.accountRowAccAmounts.getText());
                         input = input.replace(decimalSeparator, decimalDot);
                         final String newText = String.format("%4.2f", Float.parseFloat(input));
-                        if (!newText.equals(input))
-                            b.accountRowAccAmounts.setText(newText);
+                        if (!newText.equals(input)) {
+                            boolean wasSyncingData = syncingData;
+                            syncingData = true;
+                            try {
+                                b.accountRowAccAmounts.setText(newText);
+                            }
+                            finally {
+                                syncingData = wasSyncingData;
+                            }
+                        }
                     }
                     catch (NumberFormatException ex) {
                         // ignored
@@ -207,8 +215,8 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
         b.currencyButton.setOnClickListener(v -> {
             CurrencySelectorFragment cpf = new CurrencySelectorFragment();
             cpf.showPositionAndPadding();
-            cpf.setOnCurrencySelectedListener(
-                    c -> adapter.setItemCurrency(getAdapterPosition(), c.getName()));
+            cpf.setOnCurrencySelectedListener(c -> adapter.setItemCurrency(getAdapterPosition(),
+                    (c == null) ? null : c.getName()));
             cpf.show(activity.getSupportFragmentManager(), "currency-selector");
         });
 
@@ -480,6 +488,12 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
             return false;
         }
 
+        if (getAdapterPosition() < 0) {
+            // probably the row was swiped out
+            Logger.debug("new-trans", "Ignoring request to suncData(): adapter position negative");
+            return false;
+        }
+
         NewTransactionModel.Item item = getItem();
 
         syncingData = true;