From 9d20e3d42b25e152bb1153c3e8689eabfa65e513 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Thu, 4 Apr 2019 16:00:01 +0300 Subject: [PATCH] Profile list: block change notifications while moving items around this avoids a refresh of the adapter, making the recycler view stop the swapping dance --- .../ui/profiles/ProfilesRecyclerViewAdapter.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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 eb3d0c85..8e8d3812 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 @@ -64,10 +64,15 @@ public class ProfilesRecyclerViewAdapter public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) { - Collections.swap(Data.profiles, viewHolder.getAdapterPosition(), - target.getAdapterPosition()); - MobileLedgerProfile.storeProfilesOrder(); - notifyItemMoved(viewHolder.getAdapterPosition(), target.getAdapterPosition()); + Data.profiles.blockNotifications(); + try { + Collections.swap(Data.profiles, viewHolder.getAdapterPosition(), target.getAdapterPosition()); + MobileLedgerProfile.storeProfilesOrder(); + notifyItemMoved(viewHolder.getAdapterPosition(), target.getAdapterPosition()); + } + finally { + Data.profiles.unblockNotifications(); + } return true; } @Override -- 2.39.5