From d3cb35a63163f5b54ea104d7c6e799ee746e316a Mon Sep 17 00:00:00 2001 From: Super12138 <70494801+Super12138@users.noreply.github.com> Date: Mon, 9 Feb 2026 10:35:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=20&=20=E5=A2=9E=E5=8A=A0=E6=8C=89=E7=85=A7?= =?UTF-8?q?=E6=88=AA=E6=AD=A2=E6=97=A5=E6=9C=9F=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 2 +- .../todo/logic/model/SortingMethod.kt | 4 +- .../todo/ui/viewmodels/MainViewModel.kt | 48 ++++++++++++++++--- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 3a78738..5c5a929 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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" diff --git a/app/src/main/kotlin/cn/super12138/todo/logic/model/SortingMethod.kt b/app/src/main/kotlin/cn/super12138/todo/logic/model/SortingMethod.kt index d88614b..1eaa213 100644 --- a/app/src/main/kotlin/cn/super12138/todo/logic/model/SortingMethod.kt +++ b/app/src/main/kotlin/cn/super12138/todo/logic/model/SortingMethod.kt @@ -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 diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/viewmodels/MainViewModel.kt b/app/src/main/kotlin/cn/super12138/todo/ui/viewmodels/MainViewModel.kt index 199d388..7155a90 100644 --- a/app/src/main/kotlin/cn/super12138/todo/ui/viewmodels/MainViewModel.kt +++ b/app/src/main/kotlin/cn/super12138/todo/ui/viewmodels/MainViewModel.kt @@ -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 { it.isCompleted } // 必须先要按照是否完成排序 + .thenBy { it.id } + ) + + SortingMethod.Category -> list.sortedWith( + comparator = compareBy { it.isCompleted } + .thenByDescending { it.priority } + .thenBy { it.category } + ) + + SortingMethod.Priority -> list.sortedWith( + comparator = compareBy { it.isCompleted } + .thenByDescending { it.priority } + .thenBy { it.category } + ) // 优先级高的在前 + + SortingMethod.Completion -> list.sortedWith( + comparator = compareBy { it.isCompleted } + .thenBy { it.category } + .thenBy { it.content } + .thenByDescending { it.priority } + ) // 未完成的在前 + SortingMethod.AlphabeticalAscending -> list.sortedWith( + comparator = compareBy { it.isCompleted } + .thenBy { it.category } + .thenBy { it.content } + .thenByDescending { it.priority } + ) + + SortingMethod.AlphabeticalDescending -> list.sortedWith( + comparator = compareBy { it.isCompleted } + .thenByDescending { it.category } + .thenByDescending { it.content } + .thenByDescending { it.priority } + ) + + SortingMethod.DueDate -> list.sortedWith( + comparator = compareBy { it.isCompleted } + .thenBy { it.dueDate } + .thenByDescending { it.priority } + ) } } }