X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FNewTransactionModel.java;h=83ffbb8f7bed90cdf747e60cc0daf6ef3d61e182;hb=a1f5cf187a6bc2731aa1ed057d3d11fccc5de2c4;hp=d7663bcd7ff272f13b9a070ec20136c63478a0f1;hpb=7b3937e47b0b270651ad3083e467bfaaf62e9dc8;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 d7663bcd..83ffbb8f 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 @@ -49,17 +49,19 @@ public class NewTransactionModel extends ViewModel { final MutableLiveData showCurrency = new MutableLiveData<>(false); 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 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 boolean observingDataProfile; - private Observer profileObserver = - profile -> showCurrency.postValue(profile.getShowCommodityByDefault()); private final AtomicInteger busyCounter = new AtomicInteger(0); private final MutableLiveData busyFlag = new MutableLiveData<>(false); - final MutableLiveData showComments = new MutableLiveData<>(false); + private boolean observingDataProfile; + private Observer profileObserver = profile -> { + showCurrency.postValue(profile.getShowCommodityByDefault()); + showComments.postValue(profile.getShowCommentsByDefault()); + }; void observeShowComments(LifecycleOwner owner, Observer observer) { showComments.observe(owner, observer); } @@ -93,12 +95,16 @@ public class NewTransactionModel extends ViewModel { public String getDescription() { return header.description.getValue(); } + public String getComment() { + return header.comment.getValue(); + } LiveData isSubmittable() { return this.isSubmittable; } void reset() { header.date.setValue(null); header.description.setValue(null); + header.comment.setValue(null); items.clear(); items.add(new Item(this, new LedgerTransactionAccount(""))); items.add(new Item(this, new LedgerTransactionAccount(""))); @@ -202,11 +208,13 @@ public class NewTransactionModel extends ViewModel { } void incrementBusyCounter() { int newValue = busyCounter.incrementAndGet(); - if (newValue == 1) busyFlag.postValue(true); + if (newValue == 1) + busyFlag.postValue(true); } void decrementBusyCounter() { int newValue = busyCounter.decrementAndGet(); - if (newValue == 0) busyFlag.postValue(false); + if (newValue == 0) + busyFlag.postValue(false); } public boolean getBusyFlag() { return busyFlag.getValue(); @@ -216,7 +224,7 @@ public class NewTransactionModel extends ViewModel { } enum ItemType {generalData, transactionRow, bottomFiller} - enum FocusedElement {Account, Comment, Amount} + enum FocusedElement {Account, Comment, Amount, Description, TransactionComment} //========================================================================================== @@ -233,6 +241,7 @@ public class NewTransactionModel extends ViewModel { 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; @@ -386,6 +395,22 @@ public class NewTransactionModel extends ViewModel { @NonNull androidx.lifecycle.Observer observer) { this.description.removeObserver(observer); } + public String getTransactionComment() { + ensureType(ItemType.generalData); + return comment.getValue(); + } + public void setTransactionComment(String transactionComment) { + ensureType(ItemType.generalData); + this.comment.setValue(transactionComment); + } + void observeTransactionComment(@NonNull @NotNull LifecycleOwner owner, + @NonNull Observer observer) { + ensureType(ItemType.generalData); + this.comment.observe(owner, observer); + } + void stopObservingTransactionComment(@NonNull Observer observer) { + this.comment.removeObserver(observer); + } public LedgerTransactionAccount getAccount() { ensureType(ItemType.transactionRow); return account; @@ -465,5 +490,17 @@ public class NewTransactionModel extends ViewModel { boolean isAmountHintSet() { return amountHintIsSet; } + void validateAmount() { + amountValid.setValue(true); + } + void invalidateAmount() { + amountValid.setValue(false); + } + void observeAmountValidity(NewTransactionActivity activity, Observer observer) { + amountValid.observe(activity, observer); + } + void stopObservingAmountValidity(Observer observer) { + amountValid.removeObserver(observer); + } } }