X-Git-Url: https://git.ktnx.net/?p=mobile-ledger-staging.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FNewTransactionModel.java;h=8660c2159f0b5ba93ee7c55db49329f11efc8b09;hp=535b8614530b8ed722f8f800508edec8b2792a90;hb=20c03b7a5eb152d42fbbe9ecbaae27530563b398;hpb=600d64f8daa770afc8f1a809e541573bf317033f 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 535b8614..8660c215 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 @@ -46,18 +46,18 @@ public class NewTransactionModel extends ViewModel { final ArrayList items = new ArrayList<>(); final MutableLiveData isSubmittable = new MutableLiveData<>(false); final MutableLiveData showComments = new MutableLiveData<>(true); - private final Item header = new Item(this, null, ""); + private final Item header = new Item(this, ""); private final Item trailer = new Item(this); private final MutableLiveData focusedItem = new MutableLiveData<>(0); private final MutableLiveData accountCount = new MutableLiveData<>(0); private final MutableLiveData simulateSave = new MutableLiveData<>(false); private final AtomicInteger busyCounter = new AtomicInteger(0); private final MutableLiveData busyFlag = new MutableLiveData<>(false); - private boolean observingDataProfile; - private Observer profileObserver = profile -> { + private final Observer profileObserver = profile -> { showCurrency.postValue(profile.getShowCommodityByDefault()); showComments.postValue(profile.getShowCommentsByDefault()); }; + private boolean observingDataProfile; void observeShowComments(LifecycleOwner owner, Observer observer) { showComments.observe(owner, observer); } @@ -227,27 +227,26 @@ public class NewTransactionModel extends ViewModel { static class Item { - private ItemType type; - private MutableLiveData date = new MutableLiveData<>(); - private MutableLiveData description = new MutableLiveData<>(); + private final ItemType type; + private final MutableLiveData date = new MutableLiveData<>(); + private final MutableLiveData description = new MutableLiveData<>(); + private final MutableLiveData amountHint = new MutableLiveData<>(null); + private final NewTransactionModel model; + private final MutableLiveData editable = new MutableLiveData<>(true); + private final MutableLiveData comment = new MutableLiveData<>(null); + private final MutableLiveData currency = new MutableLiveData<>(null); + private final MutableLiveData amountValid = new MutableLiveData<>(true); private LedgerTransactionAccount account; - private MutableLiveData amountHint = new MutableLiveData<>(null); - private NewTransactionModel model; - private MutableLiveData editable = new MutableLiveData<>(true); private FocusedElement focusedElement = FocusedElement.Account; - private MutableLiveData comment = new MutableLiveData<>(null); - private MutableLiveData currency = new MutableLiveData<>(null); - private MutableLiveData amountValid = new MutableLiveData<>(true); private boolean amountHintIsSet = false; Item(NewTransactionModel model) { this.model = model; type = ItemType.bottomFiller; editable.setValue(false); } - Item(NewTransactionModel model, SimpleDate date, String description) { + Item(NewTransactionModel model, String description) { this.model = model; this.type = ItemType.generalData; - this.date.setValue(date); this.description.setValue(description); this.editable.setValue(true); } @@ -272,14 +271,14 @@ public class NewTransactionModel extends ViewModel { return model; } void setEditable(boolean editable) { - ensureType(ItemType.generalData, ItemType.transactionRow); + ensureTypeIsGeneralDataOrTransactionRow(); this.editable.setValue(editable); } - private void ensureType(ItemType type1, ItemType type2) { - if ((type != type1) && (type != type2)) { + private void ensureTypeIsGeneralDataOrTransactionRow() { + if ((type != ItemType.generalData) && (type != ItemType.transactionRow)) { throw new RuntimeException( String.format("Actual type (%s) differs from wanted (%s or %s)", type, - type1, type2)); + ItemType.generalData, ItemType.transactionRow)); } } String getAmountHint() { @@ -446,8 +445,8 @@ public class NewTransactionModel extends ViewModel { void stopObservingCurrency(Observer observer) { currency.removeObserver(observer); } - boolean isOfType(ItemType type) { - return this.type == type; + boolean isBottomFiller() { + return this.type == ItemType.bottomFiller; } boolean isAmountHintSet() { return amountHintIsSet;