X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FNewTransactionModel.java;h=7fd177683f461db1be543200007585a74dec4efb;hb=356b7a4d11096b57996b0aaca854a8ef63d77670;hp=ed283b211685798f80ea5c64851f4730094ee759;hpb=8115d48e4d3287aea81473ed124d04f8903da1d4;p=mobile-ledger-staging.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 ed283b21..7fd17768 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 @@ -37,6 +37,7 @@ import java.util.Collections; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; +import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -56,6 +57,15 @@ public class NewTransactionModel extends ViewModel { 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); + void observeShowComments(LifecycleOwner owner, Observer observer) { + showComments.observe(owner, observer); + } + void observeBusyFlag(@NonNull LifecycleOwner owner, Observer observer) { + busyFlag.observe(owner, observer); + } void observeDataProfile(LifecycleOwner activity) { if (!observingDataProfile) Data.profile.observe(activity, profileObserver); @@ -83,12 +93,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(""))); @@ -171,10 +185,6 @@ public class NewTransactionModel extends ViewModel { void swapItems(int one, int two) { Collections.swap(items, one - 1, two - 1); } - void toggleComment(int position) { - final MutableLiveData commentVisible = getItem(position).commentVisible; - commentVisible.postValue(!commentVisible.getValue()); - } void moveItemLast(int index) { /* 0 1 <-- index @@ -191,9 +201,26 @@ public class NewTransactionModel extends ViewModel { void toggleCurrencyVisible() { showCurrency.setValue(!showCurrency.getValue()); } + void stopObservingBusyFlag(Observer observer) { + busyFlag.removeObserver(observer); + } + void incrementBusyCounter() { + int newValue = busyCounter.incrementAndGet(); + if (newValue == 1) busyFlag.postValue(true); + } + void decrementBusyCounter() { + int newValue = busyCounter.decrementAndGet(); + if (newValue == 0) busyFlag.postValue(false); + } + public boolean getBusyFlag() { + return busyFlag.getValue(); + } + public void toggleShowComments() { + showComments.setValue(!showComments.getValue()); + } enum ItemType {generalData, transactionRow, bottomFiller} - enum FocusedElement {Account, Comment, Amount} + enum FocusedElement {Account, Comment, Amount, Description, TransactionComment} //========================================================================================== @@ -209,7 +236,6 @@ public class NewTransactionModel extends ViewModel { private MutableLiveData editable = new MutableLiveData<>(true); private FocusedElement focusedElement = FocusedElement.Account; private MutableLiveData comment = new MutableLiveData<>(null); - private MutableLiveData commentVisible = new MutableLiveData<>(false); private MutableLiveData currency = new MutableLiveData<>(null); private boolean amountHintIsSet = false; Item(NewTransactionModel model) { @@ -364,6 +390,23 @@ 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) { + ensureType(ItemType.generalData); + this.comment.removeObserver(observer); + } public LedgerTransactionAccount getAccount() { ensureType(ItemType.transactionRow); return account; @@ -407,12 +450,6 @@ public class NewTransactionModel extends ViewModel { void stopObservingEditableFlag(Observer observer) { editable.removeObserver(observer); } - void observeCommentVisible(NewTransactionActivity activity, Observer observer) { - commentVisible.observe(activity, observer); - } - void stopObservingCommentVisible(Observer observer) { - commentVisible.removeObserver(observer); - } void observeComment(NewTransactionActivity activity, Observer observer) { comment.observe(activity, observer); }