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;
private boolean observingDataProfile;
private Observer<MobileLedgerProfile> profileObserver =
profile -> showCurrency.postValue(profile.getShowCommodityByDefault());
+ private final AtomicInteger busyCounter = new AtomicInteger(0);
+ private final MutableLiveData<Boolean> busyFlag = new MutableLiveData<>(false);
+ void observeBusyFlag(LifecycleOwner owner, Observer<? super Boolean> observer) {
+ busyFlag.observe(owner, observer);
+ }
void observeDataProfile(LifecycleOwner activity) {
if (!observingDataProfile)
Data.profile.observe(activity, profileObserver);
void swapItems(int one, int two) {
Collections.swap(items, one - 1, two - 1);
}
- void toggleComment(int position) {
- final MutableLiveData<Boolean> commentVisible = getItem(position).commentVisible;
- commentVisible.postValue(!commentVisible.getValue());
- }
void moveItemLast(int index) {
/* 0
1 <-- index
void toggleCurrencyVisible() {
showCurrency.setValue(!showCurrency.getValue());
}
+ void stopObservingBusyFlag(Observer<Boolean> 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);
+ }
enum ItemType {generalData, transactionRow, bottomFiller}
enum FocusedElement {Account, Comment, Amount}
private MutableLiveData<Boolean> editable = new MutableLiveData<>(true);
private FocusedElement focusedElement = FocusedElement.Account;
private MutableLiveData<String> comment = new MutableLiveData<>(null);
- private MutableLiveData<Boolean> commentVisible = new MutableLiveData<>(false);
private MutableLiveData<Currency> currency = new MutableLiveData<>(null);
private boolean amountHintIsSet = false;
Item(NewTransactionModel model) {
void stopObservingEditableFlag(Observer<Boolean> observer) {
editable.removeObserver(observer);
}
- void observeCommentVisible(NewTransactionActivity activity, Observer<Boolean> observer) {
- commentVisible.observe(activity, observer);
- }
- void stopObservingCommentVisible(Observer<Boolean> observer) {
- commentVisible.removeObserver(observer);
- }
void observeComment(NewTransactionActivity activity, Observer<String> observer) {
comment.observe(activity, observer);
}