Skip to content

Commit ec668ad

Browse files
committed
Remove notifyDataSetChanged uses to restore item animations
1 parent 2611758 commit ec668ad

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/ChecklistAdapter.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,9 @@ class ChecklistAdapter(
7878

7979
override fun getItemKeyPosition(key: Int) = items.indexOfFirst { it.id == key }
8080

81-
override fun onActionModeCreated() {
82-
notifyDataSetChanged()
83-
}
81+
override fun onActionModeCreated() {}
8482

85-
override fun onActionModeDestroyed() {
86-
notifyDataSetChanged()
87-
}
83+
override fun onActionModeDestroyed() {}
8884

8985
override fun prepareActionMode(menu: Menu) {
9086
val selectedItems = getSelectedItems()
@@ -161,27 +157,35 @@ class ChecklistAdapter(
161157

162158
private fun moveSelectedItemsToTop() {
163159
activity.config.sorting = SORT_BY_CUSTOM
160+
val movedPositions = mutableListOf<Int>()
164161
selectedKeys.reversed().forEach { checklistId ->
165162
val position = items.indexOfFirst { it.id == checklistId }
166163
val tempItem = items[position]
167164
items.removeAt(position)
165+
movedPositions.add(position)
168166
items.add(0, tempItem)
169167
}
170168

171-
notifyDataSetChanged()
169+
movedPositions.forEach {
170+
notifyItemMoved(it, 0)
171+
}
172172
listener?.saveChecklist()
173173
}
174174

175175
private fun moveSelectedItemsToBottom() {
176176
activity.config.sorting = SORT_BY_CUSTOM
177+
val movedPositions = mutableListOf<Int>()
177178
selectedKeys.forEach { checklistId ->
178179
val position = items.indexOfFirst { it.id == checklistId }
179180
val tempItem = items[position]
180181
items.removeAt(position)
182+
movedPositions.add(position)
181183
items.add(items.size, tempItem)
182184
}
183185

184-
notifyDataSetChanged()
186+
movedPositions.forEach {
187+
notifyItemMoved(it, items.size - 1)
188+
}
185189
listener?.saveChecklist()
186190
}
187191

0 commit comments

Comments
 (0)