From 88e1dbc1a1427beb57611c24af255186c32c825e Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sun, 5 May 2019 16:28:29 +0300 Subject: [PATCH] disable profile list animations while the drawer is closing/closed --- .../mobileledger/ui/activity/MainActivity.java | 17 ++++++++++++++++- .../profiles/ProfilesRecyclerViewAdapter.java | 10 ++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index 4d1f07db..5a8e198f 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -290,7 +290,22 @@ public class MainActivity extends ProfileThemedActivity { profileListHeadCancel.setOnClickListener((v) -> mProfileListAdapter.flipEditingProfiles()); profileListHeadMoreAndCancel .setOnClickListener((v) -> mProfileListAdapter.flipEditingProfiles()); - + if (drawerListener == null) { + drawerListener = new DrawerLayout.SimpleDrawerListener() { + @Override + public void onDrawerClosed(View drawerView) { + super.onDrawerClosed(drawerView); + mProfileListAdapter.setAnimationsEnabled(false); + mProfileListAdapter.editingProfiles.setValue(false); + } + @Override + public void onDrawerOpened(View drawerView) { + super.onDrawerOpened(drawerView); + mProfileListAdapter.setAnimationsEnabled(true); + } + }; + drawer.addDrawerListener(drawerListener); + } setupProfile(); } private void scheduleDataRetrievalIfStale(Date lastUpdate) { diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java index 80e0dcdc..50fb32cf 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java @@ -56,6 +56,7 @@ public class ProfilesRecyclerViewAdapter public MutableLiveData editingProfiles = new MutableLiveData<>(false); private RecyclerView recyclerView; private ItemTouchHelper rearrangeHelper; + private boolean animationsEnabled = true; public ProfilesRecyclerViewAdapter() { debug("flow", "ProfilesRecyclerViewAdapter.new()"); @@ -83,6 +84,9 @@ public class ProfilesRecyclerViewAdapter }; rearrangeHelper = new ItemTouchHelper(cb); } + public void setAnimationsEnabled(boolean animationsEnabled) { + this.animationsEnabled = animationsEnabled; + } @Override public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) { rearrangeHelper.attachToRecyclerView(null); @@ -98,13 +102,11 @@ public class ProfilesRecyclerViewAdapter public void startEditingProfiles() { if (editingProfiles.getValue()) return; this.editingProfiles.setValue(true); - notifyDataSetChanged(); rearrangeHelper.attachToRecyclerView(recyclerView); } public void stopEditingProfiles() { if (!editingProfiles.getValue()) return; this.editingProfiles.setValue(false); - notifyDataSetChanged(); rearrangeHelper.attachToRecyclerView(null); } public void flipEditingProfiles() { @@ -187,7 +189,7 @@ public class ProfilesRecyclerViewAdapter boolean wasHidden = holder.mEditButton.getVisibility() == View.GONE; holder.mRearrangeHandle.setVisibility(View.VISIBLE); holder.mEditButton.setVisibility(View.VISIBLE); - if (wasHidden) { + if (wasHidden && animationsEnabled) { Animation a = AnimationUtils .loadAnimation(holder.mRearrangeHandle.getContext(), R.anim.fade_in); holder.mRearrangeHandle.startAnimation(a); @@ -198,7 +200,7 @@ public class ProfilesRecyclerViewAdapter boolean wasShown = holder.mEditButton.getVisibility() == View.VISIBLE; holder.mRearrangeHandle.setVisibility(View.INVISIBLE); holder.mEditButton.setVisibility(View.GONE); - if (wasShown) { + if (wasShown && animationsEnabled) { Animation a = AnimationUtils .loadAnimation(holder.mRearrangeHandle.getContext(), R.anim.fade_out); holder.mRearrangeHandle.startAnimation(a); -- 2.39.5