X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FNewTransactionModel.java;h=54867e4da3321cb490fa6f8a2b334649a4066d2e;hb=caee580f62402d32eb743eb2897cde923f8c72e7;hp=914a478b14945bce6c6f49f5ce7e8c930d8f9172;hpb=593d0307aeb6e151c4f693697d7746a3f4c929e8;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java index 914a478b..54867e4d 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java @@ -252,7 +252,7 @@ public class NewTransactionModel extends ViewModel { private MutableLiveData date = new MutableLiveData<>(); private MutableLiveData description = new MutableLiveData<>(); private LedgerTransactionAccount account; - private MutableLiveData amountHint = new MutableLiveData<>(); + private MutableLiveData amountHint = new MutableLiveData<>(null); private NewTransactionModel model; private MutableLiveData editable = new MutableLiveData<>(true); public Item(NewTransactionModel model) { @@ -276,20 +276,34 @@ public class NewTransactionModel extends ViewModel { public NewTransactionModel getModel() { return model; } - public boolean isEditable() { - ensureType(ItemType.transactionRow); - return this.editable.getValue(); - } public void setEditable(boolean editable) { ensureType(ItemType.transactionRow); this.editable.setValue(editable); } + private void ensureType(ItemType type1, ItemType type2) { + if ((type != type1) && (type != type2)) { + throw new RuntimeException( + String.format("Actual type (%s) differs from wanted (%s or %s)", type, + type1, type2)); + } + } public String getAmountHint() { ensureType(ItemType.transactionRow); return amountHint.getValue(); } public void setAmountHint(String amountHint) { ensureType(ItemType.transactionRow); + + // avoid unnecessary triggers + if (amountHint == null) { + if (this.amountHint.getValue() == null) + return; + } + else { + if (amountHint.equals(this.amountHint.getValue())) + return; + } + this.amountHint.setValue(amountHint); } public void observeAmountHint(@NonNull @NotNull androidx.lifecycle.LifecycleOwner owner,