]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java
check if transaction is submittable after applying a template
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / new_transaction / NewTransactionModel.java
index a4fe14d2a0c65216e6fec6033bf58e73c0800327..d0b99f3d558c4106238b5747dd1e94fecc826995 100644 (file)
@@ -18,6 +18,8 @@
 package net.ktnx.mobileledger.ui.new_transaction;
 
 import android.annotation.SuppressLint;
+import android.os.Handler;
+import android.os.Looper;
 import android.text.TextUtils;
 
 import androidx.annotation.NonNull;
@@ -276,7 +278,7 @@ public class NewTransactionModel extends ViewModel {
                   newItems.add(accRow);
               }
 
-              items.postValue(newItems);
+              new Handler(Looper.getMainLooper()).post(() -> setItems(newItems));
           });
     }
     private int extractIntFromMatches(MatchResult m, Integer group, Integer literal) {
@@ -612,7 +614,11 @@ public class NewTransactionModel extends ViewModel {
                                         String.format("Resetting hint of '%s' [%s]",
                                                 Misc.nullIsEmpty(acc.getAccountName()),
                                                 balCurrency));
-                            if (acc.amountHintIsSet && !TextUtils.isEmpty(acc.getAmountHint())) {
+                            // skip if the amount is set, in which case the hint is not
+                            // important/visible
+                            if (!acc.isAmountSet() && acc.amountHintIsSet &&
+                                !TextUtils.isEmpty(acc.getAmountHint()))
+                            {
                                 if (workingWithLiveList && !liveListCopied) {
                                     list = copyList(list);
                                     liveListCopied = true;
@@ -1031,7 +1037,7 @@ public class NewTransactionModel extends ViewModel {
         private boolean amountSet;
         private boolean amountValid = true;
         private FocusedElement focusedElement = FocusedElement.Account;
-        private boolean amountHintIsSet = false;
+        private boolean amountHintIsSet = true;
         private boolean isLast = false;
         public TransactionAccount(TransactionAccount origin) {
             id = origin.id;
@@ -1155,14 +1161,17 @@ public class NewTransactionModel extends ViewModel {
             if (other == null)
                 return false;
 
-            boolean equal = TextUtils.equals(accountName, other.accountName) &&
-                            TextUtils.equals(comment, other.comment) &&
-                            (amountSet ? other.amountSet && amount == other.amount
-                                       : !other.amountSet) &&
-                            (amountHintIsSet ? other.amountHintIsSet &&
-                                               TextUtils.equals(amountHint, other.amountHint)
-                                             : !other.amountHintIsSet) &&
-                            TextUtils.equals(currency, other.currency) && isLast == other.isLast;
+            boolean equal = TextUtils.equals(accountName, other.accountName);
+            equal = equal && TextUtils.equals(comment, other.comment) &&
+                    (amountSet ? other.amountSet && amount == other.amount : !other.amountSet);
+
+            // compare amount hint only if there is no amount
+            if (!amountSet)
+                equal = equal && (amountHintIsSet ? other.amountHintIsSet &&
+                                                    TextUtils.equals(amountHint, other.amountHint)
+                                                  : !other.amountHintIsSet);
+            equal = equal && TextUtils.equals(currency, other.currency) && isLast == other.isLast;
+
             Logger.debug("new-trans",
                     String.format("Comparing {%s} and {%s}: %s", this.toString(), other.toString(),
                             equal));