tweaking the way checklist items are moved to the top or bottom

This commit is contained in:
tibbi
2021-01-21 19:00:31 +01:00
parent 39e48b8977
commit 7740a3cfb8
16 changed files with 37 additions and 42 deletions

View File

@ -148,26 +148,25 @@ class ChecklistAdapter(activity: BaseSimpleActivity, var items: ArrayList<Checkl
}
private fun moveSelectedItemsToTop() {
selectedKeys.withIndex()
.reversed()
.forEach { keys ->
val position = items.indexOfFirst { it.id == keys.value }
val tempItem = items[position]
items.removeAt(position)
items.add(0, tempItem)
}
selectedKeys.reversed().forEach { checklistId ->
val position = items.indexOfFirst { it.id == checklistId }
val tempItem = items[position]
items.removeAt(position)
items.add(0, tempItem)
}
notifyDataSetChanged()
listener?.saveChecklist()
}
private fun moveSelectedItemsToBottom() {
selectedKeys.withIndex()
.forEach { keys ->
val position = items.indexOfFirst { it.id == keys.value }
val tempItem = items[position]
items.removeAt(position)
items.add(items.size, tempItem)
}
selectedKeys.forEach { checklistId ->
val position = items.indexOfFirst { it.id == checklistId }
val tempItem = items[position]
items.removeAt(position)
items.add(items.size, tempItem)
}
notifyDataSetChanged()
listener?.saveChecklist()
}