Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 32909a5

Browse files
authored
Merge pull request #687 from esensar/fix/checklist-glitch
Wait for DB updates before refreshing checklist items
2 parents 886a397 + ec668ad commit 32909a5

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

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

Lines changed: 16 additions & 11 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()
@@ -152,35 +148,44 @@ class ChecklistAdapter(
152148
positions.sortDescending()
153149
removeSelectedItems(positions)
154150

155-
listener?.saveChecklist()
156-
if (items.isEmpty()) {
157-
listener?.refreshItems()
151+
listener?.saveChecklist {
152+
if (items.isEmpty()) {
153+
listener.refreshItems()
154+
}
158155
}
159156
}
160157

161158
private fun moveSelectedItemsToTop() {
162159
activity.config.sorting = SORT_BY_CUSTOM
160+
val movedPositions = mutableListOf<Int>()
163161
selectedKeys.reversed().forEach { checklistId ->
164162
val position = items.indexOfFirst { it.id == checklistId }
165163
val tempItem = items[position]
166164
items.removeAt(position)
165+
movedPositions.add(position)
167166
items.add(0, tempItem)
168167
}
169168

170-
notifyDataSetChanged()
169+
movedPositions.forEach {
170+
notifyItemMoved(it, 0)
171+
}
171172
listener?.saveChecklist()
172173
}
173174

174175
private fun moveSelectedItemsToBottom() {
175176
activity.config.sorting = SORT_BY_CUSTOM
177+
val movedPositions = mutableListOf<Int>()
176178
selectedKeys.forEach { checklistId ->
177179
val position = items.indexOfFirst { it.id == checklistId }
178180
val tempItem = items[position]
179181
items.removeAt(position)
182+
movedPositions.add(position)
180183
items.add(items.size, tempItem)
181184
}
182185

183-
notifyDataSetChanged()
186+
movedPositions.forEach {
187+
notifyItemMoved(it, items.size - 1)
188+
}
184189
listener?.saveChecklist()
185190
}
186191

‎app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/ChecklistFragment.kt‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
190190
}
191191
}
192192

193-
private fun saveNote(refreshIndex: Int = -1) {
193+
private fun saveNote(refreshIndex: Int = -1, callback: () ->Unit = {}) {
194194
if (note == null) {
195195
return
196196
}
@@ -215,6 +215,7 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
215215
ensureBackgroundThread {
216216
saveNoteValue(note!!, note!!.value)
217217
context?.updateWidgets()
218+
activity?.runOnUiThread(callback)
218219
}
219220
}
220221
}
@@ -235,8 +236,8 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
235236

236237
fun getChecklistItems() = Gson().toJson(items)
237238

238-
override fun saveChecklist() {
239-
saveNote()
239+
override fun saveChecklist(callback: () ->Unit) {
240+
saveNote(callback = callback)
240241
}
241242

242243
override fun refreshItems() {

‎app/src/main/kotlin/com/simplemobiletools/notes/pro/interfaces/ChecklistItemsListener.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ package com.simplemobiletools.notes.pro.interfaces
33
interface ChecklistItemsListener {
44
fun refreshItems()
55

6-
fun saveChecklist()
6+
fun saveChecklist(callback: () ->Unit = {})
77
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /