]> git.ktnx.net Git - mobile-ledger.git/commitdiff
show/hide new transaction fab when transaction list is scrolled too
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 31 Dec 2018 19:05:11 +0000 (19:05 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 31 Dec 2018 19:05:11 +0000 (19:05 +0000)
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java

index 4ea48ab98f02b9c5ce151739e2a8ce3bf353323c..7c7756b67470da57c4cea54ff24e3efe7d4b7eb8 100644 (file)
@@ -25,6 +25,7 @@ import android.os.Bundle;
 import android.preference.PreferenceManager;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
+import android.support.design.widget.FloatingActionButton;
 import android.support.v4.app.Fragment;
 import android.support.v4.widget.SwipeRefreshLayout;
 import android.support.v7.widget.LinearLayoutManager;
@@ -132,9 +133,21 @@ public class TransactionListFragment extends Fragment {
 
         modelAdapter.setBoldAccountName(mShowOnlyAccountName);
 
+        FloatingActionButton fab = mActivity.findViewById(R.id.btn_add_transaction);
+
         RecyclerView root = mActivity.findViewById(R.id.transaction_root);
         root.setAdapter(modelAdapter);
 
+        root.addOnScrollListener(new RecyclerView.OnScrollListener() {
+            @Override
+            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
+                if (fab != null) {
+                    if (dy < 0) fab.show();
+                    if (dy > 0) fab.hide();
+                }
+            }
+        });
+
         LinearLayoutManager llm = new LinearLayoutManager(mActivity);
 
         llm.setOrientation(LinearLayoutManager.VERTICAL);