mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +02:00
Edit sorting logic
This commit is contained in:
@ -1,3 +1,24 @@
|
||||
package com.simplemobiletools.notes.pro.models
|
||||
|
||||
data class ChecklistItem(val id: Int, val dateCreated: Long = 0L, var title: String, var isDone: Boolean)
|
||||
import com.simplemobiletools.commons.helpers.AlphanumericComparator
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_TITLE
|
||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||
|
||||
data class ChecklistItem(val id: Int, val dateCreated: Long = 0L, var title: String, var isDone: Boolean) : Comparable<ChecklistItem> {
|
||||
companion object {
|
||||
var sorting = 0
|
||||
}
|
||||
|
||||
override fun compareTo(other: ChecklistItem): Int {
|
||||
var result = when {
|
||||
sorting and SORT_BY_TITLE != 0 -> AlphanumericComparator().compare(title.lowercase(), other.title.lowercase())
|
||||
else -> dateCreated.compareTo(other.dateCreated)
|
||||
}
|
||||
|
||||
if (sorting and SORT_DESCENDING != 0) {
|
||||
result *= -1
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user