mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-18 09:30:07 +01:00
Merge pull request #687 from esensar/fix/checklist-glitch
Wait for DB updates before refreshing checklist items
This commit is contained in:
commit
32909a5336
@ -78,13 +78,9 @@ class ChecklistAdapter(
|
||||
|
||||
override fun getItemKeyPosition(key: Int) = items.indexOfFirst { it.id == key }
|
||||
|
||||
override fun onActionModeCreated() {
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
override fun onActionModeCreated() {}
|
||||
|
||||
override fun onActionModeDestroyed() {
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
override fun onActionModeDestroyed() {}
|
||||
|
||||
override fun prepareActionMode(menu: Menu) {
|
||||
val selectedItems = getSelectedItems()
|
||||
@ -152,35 +148,44 @@ class ChecklistAdapter(
|
||||
positions.sortDescending()
|
||||
removeSelectedItems(positions)
|
||||
|
||||
listener?.saveChecklist()
|
||||
if (items.isEmpty()) {
|
||||
listener?.refreshItems()
|
||||
listener?.saveChecklist {
|
||||
if (items.isEmpty()) {
|
||||
listener.refreshItems()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun moveSelectedItemsToTop() {
|
||||
activity.config.sorting = SORT_BY_CUSTOM
|
||||
val movedPositions = mutableListOf<Int>()
|
||||
selectedKeys.reversed().forEach { checklistId ->
|
||||
val position = items.indexOfFirst { it.id == checklistId }
|
||||
val tempItem = items[position]
|
||||
items.removeAt(position)
|
||||
movedPositions.add(position)
|
||||
items.add(0, tempItem)
|
||||
}
|
||||
|
||||
notifyDataSetChanged()
|
||||
movedPositions.forEach {
|
||||
notifyItemMoved(it, 0)
|
||||
}
|
||||
listener?.saveChecklist()
|
||||
}
|
||||
|
||||
private fun moveSelectedItemsToBottom() {
|
||||
activity.config.sorting = SORT_BY_CUSTOM
|
||||
val movedPositions = mutableListOf<Int>()
|
||||
selectedKeys.forEach { checklistId ->
|
||||
val position = items.indexOfFirst { it.id == checklistId }
|
||||
val tempItem = items[position]
|
||||
items.removeAt(position)
|
||||
movedPositions.add(position)
|
||||
items.add(items.size, tempItem)
|
||||
}
|
||||
|
||||
notifyDataSetChanged()
|
||||
movedPositions.forEach {
|
||||
notifyItemMoved(it, items.size - 1)
|
||||
}
|
||||
listener?.saveChecklist()
|
||||
}
|
||||
|
||||
|
@ -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 = {})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user