]> git.ktnx.net Git - mobile-ledger.git/commitdiff
when comparing account rows, ignore amount hints if amount is present
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 28 Feb 2021 21:27:53 +0000 (23:27 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 1 Mar 2021 06:00:42 +0000 (06:00 +0000)
avoids unnecessary view holder update, possibly messing with the amount
being entered

app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java

index a4fe14d2a0c65216e6fec6033bf58e73c0800327..da09fd89a3818dcb9835bf3f96643b792d891d98 100644 (file)
@@ -612,7 +612,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;
@@ -1155,14 +1159,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));