From 4bcf1ac959b517b817655caaf8196c8dd26158b6 Mon Sep 17 00:00:00 2001 From: Super12138 <70494801+Super12138@users.noreply.github.com> Date: Fri, 4 Jul 2025 13:15:32 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=BC=96=E8=BE=91=E5=99=A8?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E6=A1=86=E6=89=8B=E5=8A=A8=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/ui/pages/editor/TodoEditorPage.kt | 10 +-------- .../todo/ui/pages/editor/state/EditorState.kt | 21 ++++++++++++++++--- 2 files changed, 19 insertions(+), 12 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 eb2db7f..2cbbd4e 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 @@ -205,15 +205,7 @@ fun TodoEditorPage( value = uiState.categoryContent, onValueChange = { uiState.categoryContent = it }, isError = uiState.isErrorCategory, - supportingText = when { - uiState.categoryContent.trim().isEmpty() -> - stringResource(R.string.error_no_content_entered) - - uiState.categoryContent.length > 5 -> - stringResource(R.string.error_exceeds_5_chars) - - else -> stringResource(R.string.tip_max_length_5) - }, + supportingText = stringResource(uiState.categorySupportingText), modifier = Modifier .fillMaxWidth() /*.sharedBounds( 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 308a988..0513e79 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 @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.SaverScope import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue +import cn.super12138.todo.R import cn.super12138.todo.logic.database.TodoEntity class EditorState(val initialTodo: TodoEntity? = null) { @@ -19,6 +20,9 @@ class EditorState(val initialTodo: TodoEntity? = null) { var priorityState by mutableFloatStateOf(initialTodo?.priority ?: 0f) var isCompleted by mutableStateOf(initialTodo?.isCompleted == true) + var categorySupportingText by mutableIntStateOf(R.string.tip_max_length_5) + private set + var showExitConfirmDialog by mutableStateOf(false) var showDeleteConfirmDialog by mutableStateOf(false) @@ -29,9 +33,20 @@ class EditorState(val initialTodo: TodoEntity? = null) { */ fun setErrorIfNotValid(): Boolean { isErrorContent = toDoContent.trim().isEmpty() - isErrorCategory = if (selectedCategoryIndex == -1) { - categoryContent.trim().isEmpty() || categoryContent.trim().length > 5 - } else false + if (selectedCategoryIndex == -1) { + if (categoryContent.trim().isEmpty()) { + isErrorCategory = true + categorySupportingText = R.string.error_no_content_entered + } else if (categoryContent.length > 5) { + isErrorCategory = true + categorySupportingText = R.string.error_exceeds_5_chars + } else { + isErrorCategory = false + categorySupportingText = R.string.tip_max_length_5 + } + } else { + isErrorCategory = false + } return isErrorContent || isErrorCategory }