mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +02:00
Add option to move checklist item all the way top or bottom #370
This commit is contained in:
@ -60,6 +60,8 @@ class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<Checkl
|
||||
}
|
||||
|
||||
when (id) {
|
||||
R.id.cab_move_to_top -> moveSelectedItems(true)
|
||||
R.id.cab_move_to_bottom -> moveSelectedItems(false)
|
||||
R.id.cab_rename -> renameChecklistItem()
|
||||
R.id.cab_delete -> deleteSelection()
|
||||
}
|
||||
@ -145,6 +147,21 @@ class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<Checkl
|
||||
}
|
||||
}
|
||||
|
||||
private fun moveSelectedItems(isMoveToTop: Boolean) {
|
||||
selectedKeys.withIndex()
|
||||
.forEach { keys ->
|
||||
val position = items.indexOfFirst { it.id == keys.value }
|
||||
val tempItem = items[position]
|
||||
items.remove(tempItem)
|
||||
if (isMoveToTop)
|
||||
items.add(0, tempItem)
|
||||
else
|
||||
items.add(items.size, tempItem)
|
||||
}
|
||||
notifyDataSetChanged()
|
||||
listener?.saveChecklist()
|
||||
}
|
||||
|
||||
private fun getItemWithKey(key: Int): ChecklistItem? = items.firstOrNull { it.id == key }
|
||||
|
||||
private fun getSelectedItems() = items.filter { selectedKeys.contains(it.id) } as ArrayList<ChecklistItem>
|
||||
|
Reference in New Issue
Block a user