X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FNewTransactionModel.java;h=b647eb85e2ab48c60f4735a268a51db20006ed6e;hp=535b8614530b8ed722f8f800508edec8b2792a90;hb=7ba876d1237f7ceb636035e0d6753195922c8b39;hpb=0ce370cea3c5c980b6eeb14acf965188ae951f51 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..b647eb85 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 @@ -1,5 +1,5 @@ /* - * Copyright © 2020 Damyan Ivanov. + * Copyright © 2021 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -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); } @@ -88,6 +88,9 @@ public class NewTransactionModel extends ViewModel { public SimpleDate getDate() { return header.date.getValue(); } + public void setDate(SimpleDate date) { + header.date.setValue(date); + } public String getDescription() { return header.description.getValue(); } @@ -227,27 +230,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 +274,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 +448,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;