mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +02:00
Implement checklist sort
This commit is contained in:
@ -1,3 +1,3 @@
|
||||
package com.simplemobiletools.notes.pro.models
|
||||
|
||||
data class ChecklistItem(val id: Int, var title: String, var isDone: Boolean)
|
||||
data class ChecklistItem(val id: Int, val dateCreated: Long = 0L, var title: String, var isDone: Boolean)
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.simplemobiletools.notes.pro.models
|
||||
|
||||
data class ChecklistSort(
|
||||
val field: ChecklistSortField,
|
||||
val direction: ChecklistSortDirection,
|
||||
val separateCheckedFromUnchecked: Boolean,
|
||||
) {
|
||||
|
||||
companion object {
|
||||
val DEFAULT = ChecklistSort(ChecklistSortField.TITLE, ChecklistSortDirection.ASCENDING, false)
|
||||
}
|
||||
|
||||
fun getSortComparator(): Comparator<ChecklistItem> {
|
||||
return when (field) {
|
||||
ChecklistSortField.TITLE -> compareWithSortDirection { it.title }
|
||||
ChecklistSortField.DATE_CREATED -> compareWithSortDirection { it.dateCreated }
|
||||
}
|
||||
}
|
||||
|
||||
private fun compareWithSortDirection(compareFunc: (ChecklistItem) -> Comparable<*>): Comparator<ChecklistItem> {
|
||||
return when (direction) {
|
||||
ChecklistSortDirection.ASCENDING -> if(separateCheckedFromUnchecked) compareBy<ChecklistItem> { it.isDone }.thenBy(compareFunc) else compareBy(compareFunc)
|
||||
ChecklistSortDirection.DESCENDING -> if(separateCheckedFromUnchecked) compareByDescending<ChecklistItem> { it.isDone }.thenByDescending(compareFunc) else compareByDescending(compareFunc)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.simplemobiletools.notes.pro.models
|
||||
|
||||
enum class ChecklistSortDirection {
|
||||
ASCENDING,
|
||||
DESCENDING,
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.simplemobiletools.notes.pro.models
|
||||
|
||||
enum class ChecklistSortField {
|
||||
TITLE,
|
||||
DATE_CREATED,
|
||||
}
|
Reference in New Issue
Block a user