]> git.ktnx.net Git - mobile-ledger.git/commitdiff
move previous transaction lookup progress bar to the fragment
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 10 May 2020 12:31:19 +0000 (15:31 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 14 May 2020 17:39:53 +0000 (17:39 +0000)
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionModel.java
app/src/main/res/layout/fragment_new_transaction.xml
app/src/main/res/layout/new_transaction_row.xml

index f97cdfc6011a7b50a92d4dd68f34d8a82caa0be1..1074bcb98f6b30a660f13a3c309eaf4e8e182bb2 100644 (file)
@@ -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) {
index 221e60f873a9e0cc901eb1e5d2996d9e55ad8a4d..63de53709c8e11471e4bcf0ddaa33e4d61b32ea3 100644 (file)
@@ -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<Currency> currencyObserver;
     private Observer<Boolean> showCurrencyObserver;
     private Observer<String> commentObserver;
-    private Observer<Boolean> 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);
index 00e44508a33d4ac0856aa39b3c2485c8dbcaf252..062495c1537a0a169fe7febc7015a44292b6529b 100644 (file)
@@ -59,7 +59,7 @@ public class NewTransactionModel extends ViewModel {
             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) {
+    void observeBusyFlag(@NonNull LifecycleOwner owner, Observer<? super Boolean> 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}
index 5981f8e7fec85a895a0e45093364913a320204a7..f35df638e8575175a4bc35d57ecf55aa2d2653fa 100644 (file)
     <androidx.constraintlayout.widget.ConstraintLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
+        android:animateLayoutChanges="true"
         tools:context="net.ktnx.mobileledger.ui.activity.NewTransactionActivity">
 
+        <ProgressBar
+            android:id="@+id/progressBar"
+            style="@style/Widget.AppCompat.ProgressBar"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="8dp"
+            android:layout_marginEnd="8dp"
+            android:indeterminate="true"
+            android:indeterminateBehavior="cycle"
+            android:visibility="invisible"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent" />
+
         <androidx.recyclerview.widget.RecyclerView
             android:orientation="vertical"
             android:id="@+id/new_transaction_accounts"
index 782955db4da91397706691963b5337f497667cd0..5a057934ffb300e47c98ff1fcb354a2429073a88 100644 (file)
             app:layout_constraintStart_toEndOf="@id/new_transaction_date"
             app:layout_constraintTop_toTopOf="parent" />
 
-        <ProgressBar
-            android:id="@+id/progressBar"
-            style="@style/Widget.AppCompat.ProgressBar.Horizontal"
-            android:layout_width="0dp"
-            android:layout_height="wrap_content"
-            android:indeterminate="true"
-            android:indeterminateBehavior="cycle"
-            android:orientation="horizontal"
-            android:visibility="invisible"
-            app:layout_constraintTop_toBottomOf="@id/new_transaction_date"
-            app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintEnd_toEndOf="parent
-"/>
     </androidx.constraintlayout.widget.ConstraintLayout>
 
     <androidx.constraintlayout.widget.ConstraintLayout