feat: 优化排序方式 & 增加按照截止日期排序
This commit is contained in:
parent
87cccfefc1
commit
d3cb35a631
3 changed files with 46 additions and 8 deletions
|
|
@ -38,7 +38,7 @@ android {
|
|||
applicationId = "cn.super12138.todo"
|
||||
minSdk = 24
|
||||
targetSdk = 36
|
||||
versionCode = 990
|
||||
versionCode = 991
|
||||
versionName = "2.3.3"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@ enum class SortingMethod(
|
|||
AlphabeticalAscending(id = 5, nameRes = R.string.sorting_alphabetical_ascending),
|
||||
|
||||
// 按字母降序
|
||||
AlphabeticalDescending(id = 6, nameRes = R.string.sorting_alphabetical_descending);
|
||||
AlphabeticalDescending(id = 6, nameRes = R.string.sorting_alphabetical_descending),
|
||||
|
||||
DueDate(id = 7, nameRes = R.string.sorting_alphabetical_descending);
|
||||
|
||||
companion object {
|
||||
fun fromId(id: Int) = entries.find { it.id == id } ?: Sequential
|
||||
|
|
|
|||
|
|
@ -43,12 +43,48 @@ class MainViewModel : ViewModel() {
|
|||
DataStoreManager.sortingMethodFlow.flatMapLatest { sortingMethod ->
|
||||
toDos.map { list ->
|
||||
when (SortingMethod.fromId(sortingMethod)) {
|
||||
SortingMethod.Sequential -> list.sortedBy { it.id }
|
||||
SortingMethod.Category -> list.sortedBy { it.category }
|
||||
SortingMethod.Priority -> list.sortedByDescending { it.priority } // 优先级高的在前
|
||||
SortingMethod.Completion -> list.sortedBy { it.isCompleted } // 未完成的在前
|
||||
SortingMethod.AlphabeticalAscending -> list.sortedBy { it.content }
|
||||
SortingMethod.AlphabeticalDescending -> list.sortedByDescending { it.content }
|
||||
SortingMethod.Sequential -> list.sortedWith(
|
||||
comparator = compareBy<TodoEntity> { it.isCompleted } // 必须先要按照是否完成排序
|
||||
.thenBy { it.id }
|
||||
)
|
||||
|
||||
SortingMethod.Category -> list.sortedWith(
|
||||
comparator = compareBy<TodoEntity> { it.isCompleted }
|
||||
.thenByDescending { it.priority }
|
||||
.thenBy { it.category }
|
||||
)
|
||||
|
||||
SortingMethod.Priority -> list.sortedWith(
|
||||
comparator = compareBy<TodoEntity> { it.isCompleted }
|
||||
.thenByDescending { it.priority }
|
||||
.thenBy { it.category }
|
||||
) // 优先级高的在前
|
||||
|
||||
SortingMethod.Completion -> list.sortedWith(
|
||||
comparator = compareBy<TodoEntity> { it.isCompleted }
|
||||
.thenBy { it.category }
|
||||
.thenBy { it.content }
|
||||
.thenByDescending { it.priority }
|
||||
) // 未完成的在前
|
||||
SortingMethod.AlphabeticalAscending -> list.sortedWith(
|
||||
comparator = compareBy<TodoEntity> { it.isCompleted }
|
||||
.thenBy { it.category }
|
||||
.thenBy { it.content }
|
||||
.thenByDescending { it.priority }
|
||||
)
|
||||
|
||||
SortingMethod.AlphabeticalDescending -> list.sortedWith(
|
||||
comparator = compareBy<TodoEntity> { it.isCompleted }
|
||||
.thenByDescending { it.category }
|
||||
.thenByDescending { it.content }
|
||||
.thenByDescending { it.priority }
|
||||
)
|
||||
|
||||
SortingMethod.DueDate -> list.sortedWith(
|
||||
comparator = compareBy<TodoEntity> { it.isCompleted }
|
||||
.thenBy { it.dueDate }
|
||||
.thenByDescending { it.priority }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue