Skip to content

Commit 574b671

Browse files
committed
fix: properly switch to custom sorting when order is modified
1 parent 7af5536 commit 574b671

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

app/src/main/kotlin/org/fossify/notes/fragments/TasksFragment.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class TasksFragment : NoteFragment(), TasksActionListener {
282282
}
283283

284284
override fun moveTask(fromPosition: Int, toPosition: Int) {
285-
activity?.config?.sorting = SORT_BY_CUSTOM
285+
switchToCustomSorting()
286286
if (fromPosition < toPosition) {
287287
for (i in fromPosition until toPosition) {
288288
tasks.swap(i, i + 1)
@@ -297,12 +297,16 @@ class TasksFragment : NoteFragment(), TasksActionListener {
297297
setupAdapter()
298298
}
299299

300-
override fun moveTasksToTop(taskIds: List<Int>) = moveTasks(taskIds.reversed(), targetPosition = 0)
300+
override fun moveTasksToTop(taskIds: List<Int>) {
301+
moveTasks(taskIds.reversed(), targetPosition = 0)
302+
}
301303

302-
override fun moveTasksToBottom(taskIds: List<Int>) = moveTasks(taskIds, targetPosition = tasks.lastIndex)
304+
override fun moveTasksToBottom(taskIds: List<Int>) {
305+
moveTasks(taskIds, targetPosition = tasks.lastIndex)
306+
}
303307

304308
private fun moveTasks(taskIds: List<Int>, targetPosition: Int) {
305-
activity?.config?.sorting = SORT_BY_CUSTOM
309+
switchToCustomSorting()
306310
taskIds.forEach { id ->
307311
val position = tasks.indexOfFirst { it.id == id }
308312
if (position != -1) {
@@ -319,6 +323,15 @@ class TasksFragment : NoteFragment(), TasksActionListener {
319323
}
320324
}
321325

326+
private fun switchToCustomSorting() {
327+
val config = activity?.config ?: return
328+
if (config.hasOwnSorting(noteId) == true) {
329+
config.saveOwnSorting(noteId, SORT_BY_CUSTOM)
330+
} else {
331+
config.sorting = SORT_BY_CUSTOM
332+
}
333+
}
334+
322335
private fun FragmentChecklistBinding.toCommonBinding(): CommonNoteBinding = this.let {
323336
object : CommonNoteBinding {
324337
override val root: View = it.root

0 commit comments

Comments
 (0)