From 88d4132c9991e9a2fe2572200cfa82ddea93abde Mon Sep 17 00:00:00 2001 From: Super12138 <70494801+Super12138@users.noreply.github.com> Date: Fri, 4 Jul 2025 08:54:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E9=A1=B9=E5=92=8C=E7=BC=96=E8=BE=91=E5=99=A8?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=E6=98=BE=E7=A4=BA=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化语言表述 优化添加重复分类时的处理方案 --- .../todo/ui/pages/editor/TodoEditorPage.kt | 2 +- .../editor/components/TodoCategoryChip.kt | 45 ++++++++++--------- .../todo/ui/pages/editor/state/EditorState.kt | 2 +- .../ui/pages/settings/SettingsDataCategory.kt | 37 +++++++++++---- .../components/category/CategoryItem.kt | 6 +-- app/src/main/res/values-zh-rCN/strings.xml | 18 ++++---- app/src/main/res/values/strings.xml | 4 +- 7 files changed, 69 insertions(+), 45 deletions(-) diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/TodoEditorPage.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/TodoEditorPage.kt index 43f06d7..2335ec3 100644 --- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/TodoEditorPage.kt +++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/TodoEditorPage.kt @@ -80,7 +80,7 @@ fun TodoEditorPage( ) } + ChipItem(id = -1, name = "自定义") - var defaultIndex by remember { mutableIntStateOf(0) } + var defaultIndex by remember { mutableIntStateOf(-1) } LaunchedEffect(originalCategories, toDo) { if (originalCategories.isEmpty()) return@LaunchedEffect if (toDo == null) { diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/components/TodoCategoryChip.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/components/TodoCategoryChip.kt index c4c5707..0fde6c0 100644 --- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/components/TodoCategoryChip.kt +++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/components/TodoCategoryChip.kt @@ -1,15 +1,14 @@ package cn.super12138.todo.ui.pages.editor.components -import androidx.compose.animation.AnimatedContent -import androidx.compose.animation.core.tween -import androidx.compose.animation.fadeIn -import androidx.compose.animation.fadeOut -import androidx.compose.animation.togetherWith -import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextAlign +import cn.super12138.todo.R import cn.super12138.todo.ui.components.ChipItem import cn.super12138.todo.ui.components.FilterChipGroup @@ -21,21 +20,23 @@ fun TodoCategoryChip( isLoading: Boolean = false, onCategorySelected: (Int) -> Unit ) { - Box(modifier = modifier.fillMaxWidth()) { - AnimatedContent( - targetState = isLoading, - transitionSpec = { fadeIn(tween(100)) togetherWith fadeOut(tween(100)) } - ) { - if (it) { - CircularProgressIndicator() - } else { - FilterChipGroup( - modifier = Modifier, - items = items, - defaultSelectedItemIndex = defaultSelectedItemIndex, - onSelectedChanged = onCategorySelected - ) - } + Column(modifier = modifier.fillMaxWidth()) { + if (isLoading) { + Text( + text = stringResource(R.string.tip_no_category_chip), + style = MaterialTheme.typography.labelLarge.copy( + color = MaterialTheme.colorScheme.onSurfaceVariant + ), + textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth(), + ) } + + FilterChipGroup( + modifier = Modifier, + items = items, + defaultSelectedItemIndex = defaultSelectedItemIndex, + onSelectedChanged = onCategorySelected + ) } } \ No newline at end of file diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/state/EditorState.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/state/EditorState.kt index 46795c6..c8c54a5 100644 --- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/state/EditorState.kt +++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/state/EditorState.kt @@ -13,7 +13,7 @@ import cn.super12138.todo.logic.database.TodoEntity class EditorState(val initialTodo: TodoEntity? = null) { var toDoContent by mutableStateOf(initialTodo?.content ?: "") var isErrorContent by mutableStateOf(false) - var selectedCategoryIndex by mutableIntStateOf(0) + var selectedCategoryIndex by mutableIntStateOf(-1) var categoryContent by mutableStateOf(initialTodo?.category ?: "") var isErrorCategory by mutableStateOf(false) var priorityState by mutableFloatStateOf(initialTodo?.priority ?: 0f) diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/settings/SettingsDataCategory.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/settings/SettingsDataCategory.kt index 58e7734..3c05589 100644 --- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/settings/SettingsDataCategory.kt +++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/settings/SettingsDataCategory.kt @@ -1,6 +1,11 @@ package cn.super12138.todo.ui.pages.settings +import androidx.compose.animation.core.Spring +import androidx.compose.animation.core.VisibilityThreshold +import androidx.compose.animation.core.spring +import androidx.compose.animation.core.tween import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items @@ -8,6 +13,7 @@ import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Add import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.Text @@ -23,8 +29,9 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.input.nestedscroll.nestedScroll -import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.unit.IntOffset import cn.super12138.todo.R import cn.super12138.todo.logic.datastore.DataStoreManager import cn.super12138.todo.ui.components.AnimatedExtendedFloatingActionButton @@ -44,7 +51,6 @@ fun SettingsDataCategory( val snackbarHostState = remember { SnackbarHostState() } val scope = rememberCoroutineScope() val listState = rememberLazyListState() - val context = LocalContext.current var showDialog by rememberSaveable { mutableStateOf(false) } val categories by DataStoreManager.categoriesFlow.collectAsState(initial = emptyList()) @@ -74,18 +80,28 @@ fun SettingsDataCategory( ) { if (categories.isEmpty()) { item { - Text("空") + Text( + text = stringResource(R.string.tip_no_category_page), + style = MaterialTheme.typography.bodyLarge, + textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth(), + ) } } else { items(items = categories, key = { it }) { CategoryItem( name = it, onDelete = { it -> - scope.launch { - DataStoreManager.setCategories(categories - it) - } + scope.launch { DataStoreManager.setCategories(categories - it) } }, - modifier = Modifier.animateItem() + modifier = Modifier.animateItem( + fadeInSpec = tween(100), + placementSpec = spring( + stiffness = Spring.StiffnessMediumLow, + visibilityThreshold = IntOffset.VisibilityThreshold + ), + fadeOutSpec = tween(100) + ) ) } } @@ -102,9 +118,12 @@ fun SettingsDataCategory( } } else { scope.launch { - snackbarHostState.showSnackbar( + /*snackbarHostState.showSnackbar( message = context.getString(R.string.error_category_duplicate) - ) + )*/ + // 调换分类位置 + val tempList = categories - it + DataStoreManager.setCategories(tempList + it) } } }, diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/settings/components/category/CategoryItem.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/settings/components/category/CategoryItem.kt index 1367653..e300df6 100644 --- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/settings/components/category/CategoryItem.kt +++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/settings/components/category/CategoryItem.kt @@ -1,5 +1,6 @@ package cn.super12138.todo.ui.pages.settings.components.category +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding @@ -36,7 +37,7 @@ fun CategoryItem( .clip(MaterialTheme.shapes.large) .padding( horizontal = TodoDefaults.settingsItemHorizontalPadding, - vertical = TodoDefaults.settingsItemVerticalPadding + vertical = TodoDefaults.settingsItemVerticalPadding / 2 ), verticalAlignment = Alignment.CenterVertically ) { @@ -44,9 +45,8 @@ fun CategoryItem( text = name, maxLines = 1, overflow = TextOverflow.Ellipsis, - style = MaterialTheme.typography.titleLarge.copy( + style = MaterialTheme.typography.bodyLarge.copy( color = MaterialTheme.colorScheme.onSurface, - fontSize = 20.sp ), modifier = Modifier.weight(1f) ) diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 8b088d0..04fba0a 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -29,7 +29,7 @@ 开发者 开放源代码许可 查看应用使用的开源库及其许可 - 类别 + 分类 不紧急 不重要 默认 @@ -72,7 +72,7 @@ 查看源代码、提交错误报告和改进建议 退出编辑后将无法找回你修改过的数据。确定退出编辑吗? 添加先后顺序 - 类别 + 分类 优先级 完成状态 首字母(升序) @@ -96,16 +96,18 @@ 安全模式 阻止截屏并保护后台预览图 更多 - 输入类别名称 + 输入分类名称 当前共有 %1$d 项任务,其中 %2$d 项已完成,%3$d 项未完成 当前没有任务 - 类别管理 + 分类管理 数据管理 - 管理任务的类别标签 - 添加类别 + 管理任务的分类标签 + 添加分类 输入内容 不超过 5 个字 超过 5 个字 - 输入你想添加的类别 - 该类别已经存在 + 输入你想添加的分类名称 + + 当前暂无自定义分类,你可以在设置中添加分类 + 当前暂无自定义分类 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a9b4560..67dcd2b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -108,5 +108,7 @@ Up to 5 characters Exceeds 5 characters Enter the category you want to add - The category is duplicate + + There are currently no custom categories. You can add categories in the settings. + There are no custom categories at the moment. \ No newline at end of file