X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FNewTransactionModel.java;h=062495c1537a0a169fe7febc7015a44292b6529b;hb=f2f0413c454a2fd63decc60fcbc0f8ac80f6159f;hp=41f2af4034bd4caaed178fff69a8516821dea654;hpb=69f3ecfe46fa70a3c2c7cfa2295dd5c8d5ffbc06;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 41f2af40..062495c1 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,11 @@ 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); + void observeBusyFlag(@NonNull LifecycleOwner owner, Observer observer) { + busyFlag.observe(owner, observer); + } void observeDataProfile(LifecycleOwner activity) { if (!observingDataProfile) Data.profile.observe(activity, profileObserver); @@ -187,6 +193,20 @@ 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(); + } enum ItemType {generalData, transactionRow, bottomFiller} enum FocusedElement {Account, Comment, Amount}