]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionAccountRowItemHolder.java
fix a weird bug when an invalid amount is entered
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / new_transaction / NewTransactionAccountRowItemHolder.java
index 7039f53a9b2ea479835c729b6ceb18678d506d44..0725f92c4beb2add32966c198228ab204f767c6f 100644 (file)
@@ -35,7 +35,7 @@ import androidx.recyclerview.widget.RecyclerView;
 
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.databinding.NewTransactionAccountRowBinding;
-import net.ktnx.mobileledger.db.AccountAutocompleteAdapter;
+import net.ktnx.mobileledger.db.AccountWithAmountsAutocompleteAdapter;
 import net.ktnx.mobileledger.model.Currency;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.ui.CurrencySelectorFragment;
@@ -125,8 +125,9 @@ class NewTransactionAccountRowItemHolder extends NewTransactionItemViewHolder {
         NewTransactionActivity activity = (NewTransactionActivity) b.getRoot()
                                                                     .getContext();
 
-        b.accountRowAccName.setAdapter(new AccountAutocompleteAdapter(b.getRoot()
-                                                                       .getContext(), mProfile));
+        b.accountRowAccName.setAdapter(new AccountWithAmountsAutocompleteAdapter(b.getRoot()
+                                                                                  .getContext(),
+                mProfile));
 
         decimalSeparator = "";
         Data.locale.observe(activity, locale -> decimalSeparator = String.valueOf(
@@ -403,7 +404,7 @@ class NewTransactionAccountRowItemHolder extends NewTransactionItemViewHolder {
 
         if (getBindingAdapterPosition() == RecyclerView.NO_POSITION) {
             // probably the row was swiped out
-            Logger.debug("new-trans", "Ignoring request to suncData(): adapter position negative");
+            Logger.debug("new-trans", "Ignoring request to syncData(): adapter position negative");
             return false;
         }
 
@@ -454,6 +455,7 @@ class NewTransactionAccountRowItemHolder extends NewTransactionItemViewHolder {
                             "input was '%s'", amount));
                     if (acc.isAmountValid())
                         significantChange = true;
+                    acc.resetAmount();
                     acc.setAmountValid(false);
                 }
                 final String curr = String.valueOf(b.currency.getText());
@@ -497,8 +499,8 @@ class NewTransactionAccountRowItemHolder extends NewTransactionItemViewHolder {
                                     presentAccountName, incomingAccountName,
                                     acc.getAccountNameCursorPosition()));
                     // avoid triggering completion pop-up
-                    AccountAutocompleteAdapter a =
-                            (AccountAutocompleteAdapter) b.accountRowAccName.getAdapter();
+                    AccountWithAmountsAutocompleteAdapter a =
+                            (AccountWithAmountsAutocompleteAdapter) b.accountRowAccName.getAdapter();
                     try {
                         b.accountRowAccName.setAdapter(null);
                         b.accountRowAccName.setText(incomingAccountName);