From: Damyan Ivanov Date: Mon, 31 Dec 2018 19:05:11 +0000 (+0000) Subject: show/hide new transaction fab when transaction list is scrolled too X-Git-Tag: v0.3~154 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=f1150ad05454cf3469b035adf97adce558c0401c;p=mobile-ledger.git show/hide new transaction fab when transaction list is scrolled too --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java index 4ea48ab9..7c7756b6 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java @@ -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);