]> git.ktnx.net Git - mobile-ledger.git/commitdiff
Profile list: block change notifications while moving items around
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 4 Apr 2019 13:00:01 +0000 (16:00 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 4 Apr 2019 13:00:01 +0000 (16:00 +0300)
this avoids a refresh of the adapter, making the recycler view stop
the swapping dance

app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java

index eb3d0c85db5d0f87fb9012ce71a85e5701b9c12f..8e8d3812a671297b2d92a6e8290a2b7f8b38b7f3 100644 (file)
@@ -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