From: Damyan Ivanov Date: Sun, 10 May 2020 12:31:19 +0000 (+0300) Subject: move previous transaction lookup progress bar to the fragment X-Git-Tag: v0.13.0~19 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=f2f0413c454a2fd63decc60fcbc0f8ac80f6159f;p=mobile-ledger.git move previous transaction lookup progress bar to the fragment --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java index f97cdfc6..1074bcb9 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java @@ -26,6 +26,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.ProgressBar; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -159,6 +160,21 @@ public class NewTransactionFragment extends Fragment { else { viewModel.setFocusedItem(focused); } + + ProgressBar p = activity.findViewById(R.id.progressBar); + viewModel.observeBusyFlag(getViewLifecycleOwner(), isBusy -> { + if (isBusy) { +// Handler h = new Handler(); +// h.postDelayed(() -> { +// if (viewModel.getBusyFlag()) +// p.setVisibility(View.VISIBLE); +// +// }, 10); + p.setVisibility(View.VISIBLE); + } + else + p.setVisibility(View.INVISIBLE); + }); } @Override public void onSaveInstanceState(@NonNull Bundle outState) { 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 221e60f8..63de5370 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,6 @@ import android.view.inputmethod.EditorInfo; import android.widget.AutoCompleteTextView; import android.widget.EditText; import android.widget.FrameLayout; -import android.widget.ProgressBar; import android.widget.TextView; import androidx.annotation.NonNull; @@ -92,7 +91,6 @@ 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; @@ -111,7 +109,6 @@ 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); @@ -390,8 +387,6 @@ 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 = @@ -588,7 +583,6 @@ 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; } @@ -641,7 +635,6 @@ 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 00e44508..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 @@ -59,7 +59,7 @@ public class NewTransactionModel extends ViewModel { 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) { + void observeBusyFlag(@NonNull LifecycleOwner owner, Observer observer) { busyFlag.observe(owner, observer); } void observeDataProfile(LifecycleOwner activity) { @@ -204,6 +204,9 @@ public class NewTransactionModel extends ViewModel { 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} diff --git a/app/src/main/res/layout/fragment_new_transaction.xml b/app/src/main/res/layout/fragment_new_transaction.xml index 5981f8e7..f35df638 100644 --- a/app/src/main/res/layout/fragment_new_transaction.xml +++ b/app/src/main/res/layout/fragment_new_transaction.xml @@ -23,8 +23,24 @@ + + -