From: Damyan Ivanov Date: Sun, 3 May 2020 08:12:09 +0000 (+0300) Subject: add progress while retrieving previous transaction X-Git-Tag: v0.12.0~30 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=cc37874c011bd23ec4fd34c4423a89ceea2d6509;p=mobile-ledger.git add progress while retrieving previous transaction the search for the right transaction may take some time --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java index ab2f4032..b63ce8e9 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java @@ -30,7 +30,7 @@ import android.view.inputmethod.EditorInfo; import android.widget.AutoCompleteTextView; import android.widget.EditText; import android.widget.FrameLayout; -import android.widget.LinearLayout; +import android.widget.ProgressBar; import android.widget.TextView; import androidx.annotation.NonNull; @@ -75,7 +75,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder private AutoCompleteTextView tvAccount; private TextView tvComment; private EditText tvAmount; - private LinearLayout lHead; + private ViewGroup lHead; private ViewGroup lAccount; private FrameLayout lPadding; private MobileLedgerProfile mProfile; @@ -92,6 +92,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder private Observer currencyObserver; private Observer showCurrencyObserver; private Observer commentObserver; + private Observer busyFlagObserver; private boolean inUpdate = false; private boolean syncingData = false; private View commentButton; @@ -110,6 +111,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder lAccount = itemView.findViewById(R.id.ntr_account); lPadding = itemView.findViewById(R.id.ntr_padding); View commentLayout = itemView.findViewById(R.id.comment_layout); + ProgressBar p = itemView.findViewById(R.id.progressBar); tvDescription.setNextFocusForwardId(View.NO_ID); tvAccount.setNextFocusForwardId(View.NO_ID); @@ -387,6 +389,8 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder ((focusedView != tvComment) && Misc.isEmptyOrNull(comment)) ? View.INVISIBLE : View.VISIBLE); }; + + busyFlagObserver = isBusy -> {p.setVisibility(isBusy ? View.VISIBLE : View.INVISIBLE);}; } private void updateCurrencyPositionAndPadding(Currency.Position position, boolean hasGap) { ConstraintLayout.LayoutParams amountLP = @@ -583,6 +587,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder this.item.stopObservingCurrency(currencyObserver); this.item.getModel().showCurrency.removeObserver(showCurrencyObserver); this.item.stopObservingComment(commentObserver); + this.item.getModel().stopObservingBusyFlag(busyFlagObserver); this.item = null; } @@ -635,6 +640,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder case generalData: item.observeDate(activity, dateObserver); item.observeDescription(activity, descriptionObserver); + item.getModel().observeBusyFlag(activity, busyFlagObserver); break; case transactionRow: item.observeAmountHint(activity, hintObserver); 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..00e44508 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(LifecycleOwner owner, Observer observer) { + busyFlag.observe(owner, observer); + } void observeDataProfile(LifecycleOwner activity) { if (!observingDataProfile) Data.profile.observe(activity, profileObserver); @@ -187,6 +193,17 @@ 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); + } enum ItemType {generalData, transactionRow, bottomFiller} enum FocusedElement {Account, Comment, Amount} diff --git a/app/src/main/res/layout/fragment_new_transaction.xml b/app/src/main/res/layout/fragment_new_transaction.xml index a2bdb7eb..5981f8e7 100644 --- a/app/src/main/res/layout/fragment_new_transaction.xml +++ b/app/src/main/res/layout/fragment_new_transaction.xml @@ -16,10 +16,11 @@ --> - diff --git a/app/src/main/res/layout/new_transaction_row.xml b/app/src/main/res/layout/new_transaction_row.xml index c4097088..782955db 100644 --- a/app/src/main/res/layout/new_transaction_row.xml +++ b/app/src/main/res/layout/new_transaction_row.xml @@ -23,10 +23,11 @@ android:animateLayoutChanges="false" android:orientation="vertical"> - + android:layout_height="wrap_content" + android:orientation="horizontal"> - + + +