From 01efdcf7ccfa401de4ac9cced874d3e8bbaf6317 Mon Sep 17 00:00:00 2001
From: Super12138 <70494801+Super12138@users.noreply.github.com>
Date: Sun, 12 Jan 2025 11:45:18 +0800
Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=9B=BD=E9=99=85=E5=8C=96?=
=?UTF-8?q?=E9=80=82=E9=85=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../super12138/todo/ui/pages/main/MainPage.kt | 4 +-
.../todo/ui/pages/main/ProgressFragment.kt | 4 --
.../todo/ui/pages/main/TodoBottomSheet.kt | 38 ++++++++-----------
.../ui/pages/main/components/ChipGroup.kt | 4 +-
.../todo/ui/pages/main/components/TodoCard.kt | 4 +-
app/src/main/res/values-zh-rCN/array.xml | 15 ++++++++
app/src/main/res/values-zh-rCN/strings.xml | 8 +++-
app/src/main/res/values/array.xml | 15 ++++++++
app/src/main/res/values/strings.xml | 8 +++-
9 files changed, 68 insertions(+), 32 deletions(-)
create mode 100644 app/src/main/res/values-zh-rCN/array.xml
create mode 100644 app/src/main/res/values/array.xml
diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/MainPage.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/MainPage.kt
index 1818c8a..8a45caa 100644
--- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/MainPage.kt
+++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/MainPage.kt
@@ -80,11 +80,11 @@ fun MainPage(viewModel: MainViewModel, modifier: Modifier = Modifier) {
) {
Icon(
imageVector = Icons.Outlined.Add,
- contentDescription = stringResource(R.string.action_add_todo)
+ contentDescription = stringResource(R.string.actions_add_task)
)
AnimatedVisibility(isExpanded) {
Text(
- text = stringResource(R.string.action_add_todo),
+ text = stringResource(R.string.actions_add_task),
modifier = Modifier.padding(start = 8.dp)
)
}
diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/ProgressFragment.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/ProgressFragment.kt
index eb347c8..2eb0c8d 100644
--- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/ProgressFragment.kt
+++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/ProgressFragment.kt
@@ -65,9 +65,5 @@ fun ProgressFragment(
)
}
}
- /*Slider(
- value = progress,
- onValueChange = { progress = it }
- )*/
}
}
\ No newline at end of file
diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/TodoBottomSheet.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/TodoBottomSheet.kt
index aa384b7..ce7fded 100644
--- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/TodoBottomSheet.kt
+++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/TodoBottomSheet.kt
@@ -20,10 +20,12 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
+import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import cn.super12138.todo.R
@@ -39,6 +41,8 @@ fun TodoBottomSheet(
onClose: () -> Unit,
modifier: Modifier = Modifier
) {
+ val context = LocalContext.current
+
ModalBottomSheet(
sheetState = sheetState,
onDismissRequest = onDismissRequest,
@@ -49,40 +53,30 @@ fun TodoBottomSheet(
modifier = Modifier.padding(horizontal = 16.dp)
) {
Text(
- text = stringResource(R.string.action_add_todo),
+ text = stringResource(R.string.actions_add_task),
style = MaterialTheme.typography.headlineMedium
)
Spacer(Modifier.size(25.dp))
+
var text by rememberSaveable { mutableStateOf("") }
var isError by rememberSaveable { mutableStateOf(false) }
TextField(
value = text,
onValueChange = { text = it },
- label = { Text("待办内容") },
+ label = { Text(stringResource(R.string.placeholder_add_todo)) },
isError = isError,
supportingText = {
AnimatedVisibility(isError) {
- Text("没有内容")
+ Text(stringResource(R.string.error_no_task_content))
}
},
modifier = Modifier.fillMaxWidth()
)
- Spacer(Modifier.size(5.dp))
- val subjects =
- listOf(
- "语文",
- "数学",
- "英语",
- "生物",
- "地理",
- "物理",
- "化学",
- "道法",
- "历史",
- "其它"
- )
+ Spacer(Modifier.size(5.dp))
+
+ val subjects = remember { context.resources.getStringArray(R.array.subjects).toList() }
var selectedItemIndex by rememberSaveable { mutableIntStateOf(0) }
FilterChipGroup(
items = subjects,
@@ -94,17 +88,17 @@ fun TodoBottomSheet(
Spacer(Modifier.size(20.dp))
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
- OutlinedButton(
- onClick = onClose
- ) {
- Text("取消")
+ OutlinedButton(onClick = onClose) {
+ Text(stringResource(R.string.actions_cancel))
}
FilledTonalButton(
onClick = {
+ // 文本为空
if (text.trim().isEmpty()) {
isError = true
return@FilledTonalButton
}
+
isError = false
onSave(
TodoEntity(
@@ -114,7 +108,7 @@ fun TodoBottomSheet(
)
}
) {
- Text("添加")
+ Text(stringResource(R.string.actions_save))
}
}
Spacer(Modifier.size(30.dp))
diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/components/ChipGroup.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/components/ChipGroup.kt
index e83019c..ad17a5b 100644
--- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/components/ChipGroup.kt
+++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/components/ChipGroup.kt
@@ -17,7 +17,9 @@ import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
+import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
+import cn.super12138.todo.R
/**
* 部分参考:https://github.com/Rhythamtech/FilterChipGroup-Compose-Android/blob/main/FilterChipGroup.kt
@@ -46,7 +48,7 @@ fun FilterChipGroup(
) {
Icon(
imageVector = Icons.Outlined.Check,
- contentDescription = "", // TODO: 添加字符串
+ contentDescription = stringResource(R.string.tips_select_this),
modifier = Modifier.size(FilterChipDefaults.IconSize)
)
}
diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/components/TodoCard.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/components/TodoCard.kt
index 8f4220b..22d5fd8 100644
--- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/components/TodoCard.kt
+++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/components/TodoCard.kt
@@ -18,8 +18,10 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
+import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
+import cn.super12138.todo.R
@Composable
fun TodoCard(
@@ -65,7 +67,7 @@ fun TodoCard(
Icon(
imageVector = Icons.Outlined.Check,
tint = MaterialTheme.colorScheme.primary,
- contentDescription = "" // TODO: 无障碍适配
+ contentDescription = stringResource(R.string.tips_mark_completed)
)
}
diff --git a/app/src/main/res/values-zh-rCN/array.xml b/app/src/main/res/values-zh-rCN/array.xml
new file mode 100644
index 0000000..1f20984
--- /dev/null
+++ b/app/src/main/res/values-zh-rCN/array.xml
@@ -0,0 +1,15 @@
+
+
+
+ - 语文
+ - 数学
+ - 英语
+ - 生物
+ - 地理
+ - 物理
+ - 化学
+ - 道法
+ - 历史
+ - 其它
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml
index 2e811a3..83efb4a 100644
--- a/app/src/main/res/values-zh-rCN/strings.xml
+++ b/app/src/main/res/values-zh-rCN/strings.xml
@@ -2,6 +2,12 @@
待办
设置
- 添加待办
+ 添加待办
目前没有任务要完成的,好好休息一下吧~
+ 待办内容
+ 取消
+ 保存
+ 没有输入待办内容
+ 选择该项
+ 标记为已完成
\ No newline at end of file
diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml
new file mode 100644
index 0000000..d319f9f
--- /dev/null
+++ b/app/src/main/res/values/array.xml
@@ -0,0 +1,15 @@
+
+
+
+ - Chinese
+ - Math
+ - English
+ - Biology
+ - Geography
+ - Physics
+ - Chemistry
+ - Moral Education
+ - History
+ - Others
+
+
\ 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 a212ff1..d3ce570 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,6 +1,12 @@
To Do
Settings
- Add todo
+ Add Task
There are no tasks to complete at the moment, take a good rest!
+ Task content
+ Cancel
+ Save
+ No task content entered
+ Select this
+ Mark as completed
\ No newline at end of file