From bd0bbfa8023c08b29ac300986685425564e70160 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Wed, 11 Jul 2018 16:51:15 -0500 Subject: [PATCH] Hide add contact button when scrolling down the contacts list --- .../activities/BoardActivity.java | 2 -- .../fragments/ContactsFragment.java | 21 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java index c9f5a16..6767fa1 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java @@ -26,8 +26,6 @@ import android.view.View; import android.view.animation.LinearInterpolator; import android.widget.ImageView; -import com.sjaramillo10.animatedtablayout.AnimatedTabLayout; - import java.io.File; import butterknife.BindView; diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/ContactsFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/ContactsFragment.java index 3d9d608..d17c179 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/ContactsFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/ContactsFragment.java @@ -7,6 +7,7 @@ import android.arch.paging.PagedList; import android.os.Bundle; 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.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -28,6 +29,8 @@ public class ContactsFragment extends Fragment { ContactListAdapter adapter; + FloatingActionButton fabAddContact; + public ContactsFragment() { // Required empty public constructor } @@ -56,6 +59,24 @@ public class ContactsFragment extends Fragment { adapter = new ContactListAdapter(); rvContacts.setAdapter(adapter); + fabAddContact = getActivity().findViewById(R.id.fabAddContact); + + // Hides the fab when scrolling down + rvContacts.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(RecyclerView recyclerView, int dx, int dy) { + super.onScrolled(recyclerView, dx, dy); + + // Scroll down + if(dy > 0 && fabAddContact.isShown()) + fabAddContact.hide(); + + // Scroll up + if(dy < 0 && !fabAddContact.isShown()) + fabAddContact.show(); + } + }); + // Gets contacts LiveData instance from ContactsViewModel ContactListViewModel contactListViewModel = ViewModelProviders.of(this).get(ContactListViewModel.class);