正式发布2.1.2版本

修复英文情况下字符串双引号不显示的问题
优化备份与恢复数据库逻辑(使用 GitHub Copilot)
增大待办圆环
修复部分遗留的错误变量名称
优化主页性能
This commit is contained in:
Super12138 2025-02-23 11:02:58 +08:00
parent a305d5217f
commit a8aa50f80b
6 changed files with 29 additions and 38 deletions

View file

@ -34,8 +34,8 @@ android {
applicationId = "cn.super12138.todo"
minSdk = 24
targetSdk = 35
versionCode = 564
versionName = "2.0.2"
versionCode = 567
versionName = "2.1.2"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
@ -83,7 +83,6 @@ dependencies {
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.androidx.compose.runtime.livedata)
// implementation(libs.androidx.security)
// Compose
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))

View file

@ -4,7 +4,7 @@ import android.content.Context
import cn.super12138.todo.R
enum class SortingMethod(val id: Int) {
Date(1),
Sequential(1),
Subject(2),
Priority(3),
Completion(4),
@ -13,7 +13,7 @@ enum class SortingMethod(val id: Int) {
fun getDisplayName(context: Context): String {
val resId = when (this) {
Date -> R.string.sorting_sequential
Sequential -> R.string.sorting_sequential
Subject -> R.string.sorting_subject
Priority -> R.string.sorting_priority
Completion -> R.string.sorting_completion
@ -25,7 +25,7 @@ enum class SortingMethod(val id: Int) {
companion object {
fun fromId(id: Int): SortingMethod {
return SortingMethod.entries.find { it.id == id } ?: Date
return SortingMethod.entries.find { it.id == id } ?: Sequential
}
}
}

View file

@ -80,6 +80,9 @@ fun MainPage(
val filteredTodoList =
if (showCompleted) toDoList else toDoList.filter { item -> !item.isCompleted }
val totalTasks by remember { derivedStateOf { toDoList.size } }
val completedTasks by remember { derivedStateOf { toDoList.count { it.isCompleted } } }
BackHandler(enabled = !isSelectedIdsEmpty) {
// 当按下返回键(或进行返回操作)时清空选择
viewModel.clearAllTodoSelection()
@ -126,8 +129,8 @@ fun MainPage(
if (windowSizeClass.windowWidthSizeClass == WindowWidthSizeClass.COMPACT) {
Column(modifier = Modifier.padding(innerPadding)) {
ProgressFragment(
totalTasks = toDoList.size,
completedTasks = toDoList.count { it.isCompleted },
totalTasks = totalTasks,
completedTasks = completedTasks,
modifier = Modifier
.weight(2f)
.fillMaxSize()
@ -172,8 +175,8 @@ fun MainPage(
} else {
Row(modifier = Modifier.padding(innerPadding)) {
ProgressFragment(
totalTasks = toDoList.size,
completedTasks = toDoList.count { it.isCompleted },
totalTasks = totalTasks,
completedTasks = completedTasks,
modifier = Modifier
.weight(2f)
.fillMaxSize()

View file

@ -45,8 +45,9 @@ fun ProgressFragment(
progress = { animatedProgress },
strokeWidth = 10.dp,
gapSize = 10.dp,
modifier = Modifier.size(170.dp)
modifier = Modifier.size(175.dp)
)
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(

View file

@ -30,7 +30,6 @@ import java.io.BufferedInputStream
import java.io.BufferedOutputStream
import java.io.File
import java.io.FileOutputStream
import java.util.zip.ZipEntry
import java.util.zip.ZipInputStream
import java.util.zip.ZipOutputStream
@ -40,7 +39,7 @@ class MainViewModel : ViewModel() {
var appSortingMethod by mutableStateOf(SortingMethod.fromId(GlobalValues.sortingMethod))
val sortedTodos: Flow<List<TodoEntity>> = toDos.map { list ->
when (appSortingMethod) {
SortingMethod.Date -> list.sortedBy { it.id }
SortingMethod.Sequential -> list.sortedBy { it.id }
SortingMethod.Subject -> list.sortedBy { it.subject }
SortingMethod.Priority -> list.sortedByDescending { it.priority } // 优先级高的在前
SortingMethod.Completion -> list.sortedBy { it.isCompleted } // 未完成的在前
@ -186,26 +185,21 @@ class MainViewModel : ViewModel() {
// 开启输出文件流输出位置为用户选取的文件夹URI
context.contentResolver.openOutputStream(uri)?.use { outputStream ->
ZipOutputStream(BufferedOutputStream(outputStream)).use { zipOutStream ->
val dbFile = context.getDatabasePath(Constants.DB_NAME)
val dbWal = File("$dbPath-wal")
val dbShm = File("$dbPath-shm")
FileUtils.addFileToZip(dbFile, dbFile.name, zipOutStream)
FileUtils.addFileToZip(dbWal, dbWal.name, zipOutStream)
FileUtils.addFileToZip(dbShm, dbShm.name, zipOutStream)
listOf(
context.getDatabasePath(Constants.DB_NAME),
File("$dbPath-wal"),
File("$dbPath-shm")
).forEach { file ->
FileUtils.addFileToZip(file, file.name, zipOutStream)
}
}
}
// 执行成功的回调
withContext(Dispatchers.Main) {
onResult(true) // 成功
}
withContext(Dispatchers.Main) { onResult(true) }
} catch (e: Exception) {
e.printStackTrace()
// 执行失败的回调
withContext(Dispatchers.Main) {
onResult(false) // 失败
}
withContext(Dispatchers.Main) { onResult(false) }
}
}
}
@ -213,12 +207,11 @@ class MainViewModel : ViewModel() {
fun restoreDatabase(uri: Uri, context: Context, onResult: (completed: Boolean) -> Unit) {
viewModelScope.launch(Dispatchers.IO) {
try {
// 获取数据库文件路径
// 获取数据库文件
val outputPath = context.getDatabasePath(Constants.DB_NAME).parent
context.contentResolver.openInputStream(uri)?.use { inputStream ->
ZipInputStream(BufferedInputStream(inputStream)).use { zipInputStream ->
var zipEntry: ZipEntry? = zipInputStream.nextEntry
while (zipEntry != null) {
generateSequence { zipInputStream.nextEntry }.forEach { zipEntry ->
val outputFile = File(outputPath, zipEntry.name)
if (zipEntry.isDirectory) {
outputFile.mkdirs()
@ -227,18 +220,13 @@ class MainViewModel : ViewModel() {
FileOutputStream(outputFile).use { zipInputStream.copyTo(it) }
}
zipInputStream.closeEntry()
zipEntry = zipInputStream.nextEntry
}
}
}
withContext(Dispatchers.Main) {
onResult(true) // 成功
}
withContext(Dispatchers.Main) { onResult(true) }
} catch (e: Exception) {
e.printStackTrace()
withContext(Dispatchers.Main) {
onResult(false) // 失败
}
withContext(Dispatchers.Main) { onResult(false) }
}
}
}

View file

@ -94,7 +94,7 @@
<string name="pref_haptic_feedback">Haptic Feedback</string>
<string name="pref_haptic_feedback_desc">Provide slight vibration feedback for some operations</string>
<string name="tip_tips">Tips</string>
<string name="pref_haptic_feedback_more_info">Before using this feature, you need to enable haptic feedback in the system settings (usually under the &quot;Sound &amp; Vibration&quot; section in the &quot;Haptic Feedback&quot; option)</string>
<string name="pref_haptic_feedback_more_info">Before using this feature, you need to enable haptic feedback in the system settings (usually under the \"Sound &amp; Vibration\" section in the \"Haptic Feedback\" option)</string>
<string name="pref_data">Data</string>
<string name="pref_data_desc">Backup and Restore, Manage Data</string>
<string name="pref_backup">Backup</string>