summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorMatthew Wong <wongma@protonmail.ch>2015-08-11 16:59:55 -0400
committerMatthew Wong <wongma@protonmail.ch>2015-08-11 16:59:55 -0400
commit083f340f29944bc6f026af09ddb8356325c66e4c (patch)
tree9b1215ae176b6dbcc6e7a22cbc2e48082208a2d2 /app/src/main/java
parent4845300730e366821abf4f5dacf0e234d4ff9da9 (diff)
Keep selectedItems up-to-date safely (behaviour was undefined before?)
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java11
1 files changed, 9 insertions, 2 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java
index bcd869d8..b4ad1d81 100644
--- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java
+++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java
@@ -190,12 +190,19 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter<PasswordRecycl
public void remove(int position) {
this.values.remove(position);
this.notifyItemRemoved(position);
+
+ // keep selectedItems updated so we know what to notifyItemChanged
+ // (instead of just using notifyDataSetChanged)
+ Set<Integer> temp = new TreeSet<>();
for (int selected : selectedItems) {
if (selected > position) {
- selectedItems.remove(selected);
- selectedItems.add(selected - 1);
+ temp.add(selected - 1);
+ } else {
+ temp.add(selected);
}
}
+ selectedItems.clear();
+ selectedItems.addAll(temp);
}
public void toggleSelection(int position, View view) {