Skip to content

Commit

Permalink
Ticking off tasks moves them to the bottom.
Browse files Browse the repository at this point in the history
If a tasked is un-checked, it goes back to its original position.
The order is maintained in the Nextcloud notes too.
  • Loading branch information
jsixface committed Nov 17, 2022
1 parent ea4f398 commit caec6b0
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions app/src/main/java/org/qosp/notes/ui/editor/EditorFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -945,17 +945,18 @@ class EditorFragment : BaseFragment(R.layout.fragment_editor) {
}

private fun updateTask(position: Int, content: String? = null, isDone: Boolean? = null) {
tasksAdapter.tasks = tasksAdapter.tasks
.mapIndexed { index, task ->
when (index) {
position -> task.copy(
content = content ?: task.content,
isDone = isDone ?: task.isDone
)
else -> task
}
}
.toMutableList()
val tasks = tasksAdapter.tasks
val task = tasks[position].let {
it.copy(
content = content ?: it.content,
isDone = isDone ?: it.isDone
)
}
tasks[position] = task
val notCompleted = tasks.filterNot { it.isDone }.sortedBy { it.id }
val completed = tasks.filter { it.isDone }.sortedBy { it.id }
tasksAdapter.tasks = (notCompleted + completed).toMutableList()
tasksAdapter.notifyItemMoved(position, tasksAdapter.tasks.indexOf(task))
model.updateTaskList(tasksAdapter.tasks)
}

Expand Down

0 comments on commit caec6b0

Please sign in to comment.