Hide add contact button when scrolling down the contacts list
This commit is contained in:
parent
b3501a3a89
commit
bd0bbfa802
2 changed files with 21 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue