X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fnew_transaction%2FNewTransactionModel.java;h=d0b99f3d558c4106238b5747dd1e94fecc826995;hb=92846565ae94144ea1423be61c37e5a7b1a920fa;hp=a4fe14d2a0c65216e6fec6033bf58e73c0800327;hpb=ef5d367b0e34de0bf65409b3b44d686a19d50cec;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java index a4fe14d2..d0b99f3d 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionModel.java @@ -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));