refactor: 编辑器文本框手动检查是否错误
This commit is contained in:
parent
74840d137f
commit
4bcf1ac959
2 changed files with 19 additions and 12 deletions
|
|
@ -205,15 +205,7 @@ fun TodoEditorPage(
|
||||||
value = uiState.categoryContent,
|
value = uiState.categoryContent,
|
||||||
onValueChange = { uiState.categoryContent = it },
|
onValueChange = { uiState.categoryContent = it },
|
||||||
isError = uiState.isErrorCategory,
|
isError = uiState.isErrorCategory,
|
||||||
supportingText = when {
|
supportingText = stringResource(uiState.categorySupportingText),
|
||||||
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)
|
|
||||||
},
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
/*.sharedBounds(
|
/*.sharedBounds(
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.saveable.SaverScope
|
import androidx.compose.runtime.saveable.SaverScope
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
|
import cn.super12138.todo.R
|
||||||
import cn.super12138.todo.logic.database.TodoEntity
|
import cn.super12138.todo.logic.database.TodoEntity
|
||||||
|
|
||||||
class EditorState(val initialTodo: TodoEntity? = null) {
|
class EditorState(val initialTodo: TodoEntity? = null) {
|
||||||
|
|
@ -19,6 +20,9 @@ class EditorState(val initialTodo: TodoEntity? = null) {
|
||||||
var priorityState by mutableFloatStateOf(initialTodo?.priority ?: 0f)
|
var priorityState by mutableFloatStateOf(initialTodo?.priority ?: 0f)
|
||||||
var isCompleted by mutableStateOf(initialTodo?.isCompleted == true)
|
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 showExitConfirmDialog by mutableStateOf(false)
|
||||||
var showDeleteConfirmDialog by mutableStateOf(false)
|
var showDeleteConfirmDialog by mutableStateOf(false)
|
||||||
|
|
||||||
|
|
@ -29,9 +33,20 @@ class EditorState(val initialTodo: TodoEntity? = null) {
|
||||||
*/
|
*/
|
||||||
fun setErrorIfNotValid(): Boolean {
|
fun setErrorIfNotValid(): Boolean {
|
||||||
isErrorContent = toDoContent.trim().isEmpty()
|
isErrorContent = toDoContent.trim().isEmpty()
|
||||||
isErrorCategory = if (selectedCategoryIndex == -1) {
|
if (selectedCategoryIndex == -1) {
|
||||||
categoryContent.trim().isEmpty() || categoryContent.trim().length > 5
|
if (categoryContent.trim().isEmpty()) {
|
||||||
} else false
|
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
|
return isErrorContent || isErrorCategory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue