]> git.ktnx.net Git - mobile-ledger.git/commitdiff
switch new transaction UI to FabManager
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 3 Mar 2021 13:30:29 +0000 (15:30 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 3 Mar 2021 13:30:29 +0000 (15:30 +0200)
app/src/main/java/net/ktnx/mobileledger/ui/FabManager.java
app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionActivity.java
app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java
app/src/main/res/layout/activity_new_transaction.xml

index a693a25a1f18befad94acd84c6adf0a26b8b4406..249c5d844352945a02d40396ed47486f5a97f59d 100644 (file)
@@ -75,7 +75,8 @@ public class FabManager {
                             break;
 
                         final float absoluteY = e.getRawY();
-//                        Logger.debug("touch", String.format(Locale.US, "Move to %4.2f", absoluteY));
+//                        Logger.debug("touch", String.format(Locale.US, "Move to %4.2f",
+//                        absoluteY));
 
                         if (absoluteY > absoluteAnchor + triggerAbsolutePixels) {
                             // swipe down
index ab28ca16d05a2ff43d5d57404692c17a8f021177..4b1fce945e74a1788898c0b0428bd1aa963559e6 100644 (file)
@@ -17,6 +17,7 @@
 
 package net.ktnx.mobileledger.ui.new_transaction;
 
+import android.content.Context;
 import android.content.Intent;
 import android.database.AbstractCursor;
 import android.database.Cursor;
@@ -50,6 +51,7 @@ import net.ktnx.mobileledger.db.TemplateHeader;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.LedgerTransaction;
 import net.ktnx.mobileledger.model.MatchedTemplate;
+import net.ktnx.mobileledger.ui.FabManager;
 import net.ktnx.mobileledger.ui.QR;
 import net.ktnx.mobileledger.ui.activity.ProfileThemedActivity;
 import net.ktnx.mobileledger.ui.templates.TemplatesActivity;
@@ -67,11 +69,13 @@ import static net.ktnx.mobileledger.utils.Logger.debug;
 
 public class NewTransactionActivity extends ProfileThemedActivity
         implements TaskCallback, NewTransactionFragment.OnNewTransactionFragmentInteractionListener,
-        QR.QRScanTrigger, QR.QRScanResultReceiver, DescriptionSelectedCallback {
+        QR.QRScanTrigger, QR.QRScanResultReceiver, DescriptionSelectedCallback,
+        FabManager.FabHandler {
     private NavController navController;
     private NewTransactionModel model;
     private ActivityResultLauncher<Void> qrScanLauncher;
     private ActivityNewTransactionBinding b;
+    private FabManager fabManager;
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -93,20 +97,20 @@ public class NewTransactionActivity extends ProfileThemedActivity
 
         qrScanLauncher = QR.registerLauncher(this, this);
 
+        fabManager = new FabManager(b.fabAdd);
+
         model.isSubmittable()
              .observe(this, isSubmittable -> {
                  if (isSubmittable) {
-                     b.fabAdd.show();
+                     fabManager.showFab();
                  }
                  else {
-                     b.fabAdd.hide();
+                     fabManager.hideFab();
                  }
              });
 //        viewModel.checkTransactionSubmittable(listAdapter);
 
         b.fabAdd.setOnClickListener(v -> onFabPressed());
-
-
     }
     @Override
     protected void initProfile() {
@@ -419,4 +423,18 @@ public class NewTransactionActivity extends ProfileThemedActivity
 
         onTransactionSave(tr);
     }
+    @Override
+    public Context getContext() {
+        return this;
+    }
+    @Override
+    public void showManagedFab() {
+        if (Objects.requireNonNull(model.isSubmittable()
+                                        .getValue()))
+            fabManager.showFab();
+    }
+    @Override
+    public void hideManagedFab() {
+        fabManager.hideFab();
+    }
 }
index d1f19c46bc51c7018904d874cda141e411c095cc..ca147dd262d8f74dd3801c61f71639c24a7ed115 100644 (file)
@@ -45,6 +45,7 @@ import net.ktnx.mobileledger.json.API;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.LedgerTransaction;
 import net.ktnx.mobileledger.model.MobileLedgerProfile;
+import net.ktnx.mobileledger.ui.FabManager;
 import net.ktnx.mobileledger.ui.QR;
 import net.ktnx.mobileledger.utils.Logger;
 
@@ -213,6 +214,9 @@ public class NewTransactionFragment extends Fragment {
                      else
                          p.setVisibility(View.INVISIBLE);
                  });
+
+        if (activity instanceof FabManager.FabHandler)
+            FabManager.handle((FabManager.FabHandler) activity, list);
     }
     @Override
     public void onSaveInstanceState(@NonNull Bundle outState) {
index cfd8959ee10955bd50a621e0d14c7964e6281172..995f9386c401cf713c71412feb5d4da7222d19b7 100644 (file)
@@ -97,7 +97,6 @@
         android:tint="?android:attr/colorBackground"
         android:visibility="visible"
         app:backgroundTint="?colorSecondary"
-        app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
         app:srcCompat="@drawable/ic_save_white_24dp"