From: Damyan Ivanov Date: Wed, 3 Mar 2021 13:30:29 +0000 (+0200) Subject: switch new transaction UI to FabManager X-Git-Tag: v0.17.0~47 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=abc2cfe2c435d10ade2533d09eccab9a32f5bba6;p=mobile-ledger.git switch new transaction UI to FabManager --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/FabManager.java b/app/src/main/java/net/ktnx/mobileledger/ui/FabManager.java index a693a25a..249c5d84 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/FabManager.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/FabManager.java @@ -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 diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionActivity.java index ab28ca16..4b1fce94 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionActivity.java @@ -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 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(); + } } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java index d1f19c46..ca147dd2 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionFragment.java @@ -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) { diff --git a/app/src/main/res/layout/activity_new_transaction.xml b/app/src/main/res/layout/activity_new_transaction.xml index cfd8959e..995f9386 100644 --- a/app/src/main/res/layout/activity_new_transaction.xml +++ b/app/src/main/res/layout/activity_new_transaction.xml @@ -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"