Wait for DB updates before refreshing checklist items

This commit is contained in:
Ensar Sarajčić 2023-09-20 11:49:33 +02:00
parent 886a397d23
commit 2611758758
3 changed files with 9 additions and 7 deletions
app/src/main/kotlin/com/simplemobiletools/notes/pro

@ -152,9 +152,10 @@ class ChecklistAdapter(
positions.sortDescending()
removeSelectedItems(positions)
listener?.saveChecklist()
if (items.isEmpty()) {
listener?.refreshItems()
listener?.saveChecklist {
if (items.isEmpty()) {
listener.refreshItems()
}
}
}

@ -190,7 +190,7 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
}
}
private fun saveNote(refreshIndex: Int = -1) {
private fun saveNote(refreshIndex: Int = -1, callback: () -> Unit = {}) {
if (note == null) {
return
}
@ -215,6 +215,7 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
ensureBackgroundThread {
saveNoteValue(note!!, note!!.value)
context?.updateWidgets()
activity?.runOnUiThread(callback)
}
}
}
@ -235,8 +236,8 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
fun getChecklistItems() = Gson().toJson(items)
override fun saveChecklist() {
saveNote()
override fun saveChecklist(callback: () -> Unit) {
saveNote(callback = callback)
}
override fun refreshItems() {

@ -3,5 +3,5 @@ package com.simplemobiletools.notes.pro.interfaces
interface ChecklistItemsListener {
fun refreshItems()
fun saveChecklist()
fun saveChecklist(callback: () -> Unit = {})
}