diff --git a/app/src/main/kotlin/cn/super12138/todo/logic/database/TodoEntity.kt b/app/src/main/kotlin/cn/super12138/todo/logic/database/TodoEntity.kt
index 001f9aa..6dc8b2d 100644
--- a/app/src/main/kotlin/cn/super12138/todo/logic/database/TodoEntity.kt
+++ b/app/src/main/kotlin/cn/super12138/todo/logic/database/TodoEntity.kt
@@ -7,7 +7,7 @@ import androidx.room.PrimaryKey
@Entity(tableName = "todo")
data class TodoEntity(
@ColumnInfo(name = "content") val content: String,
- @ColumnInfo(name = "subject") val subject: String,
+ @ColumnInfo(name = "subject") val subject: Int,
@ColumnInfo(name = "completed") val isCompleted: Boolean = false,
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "id") val id: Int = 0,
)
diff --git a/app/src/main/kotlin/cn/super12138/todo/logic/model/Subjects.kt b/app/src/main/kotlin/cn/super12138/todo/logic/model/Subjects.kt
new file mode 100644
index 0000000..5fde68e
--- /dev/null
+++ b/app/src/main/kotlin/cn/super12138/todo/logic/model/Subjects.kt
@@ -0,0 +1,40 @@
+package cn.super12138.todo.logic.model
+
+import android.content.Context
+import cn.super12138.todo.R
+
+enum class Subjects(val id: Int) {
+ Chinese(0),
+ Math(1),
+ English(2),
+ Biology(3),
+ Geography(4),
+ Physics(5),
+ Moral(6),
+ Chemistry(7),
+ History(8),
+ Others(99);
+
+ fun getDisplayName(context: Context): String {
+ val resId = when (this) {
+ Chinese -> R.string.subject_chinese
+ Math -> R.string.subject_math
+ English -> R.string.subject_english
+ Biology -> R.string.subject_biology
+ Geography -> R.string.subject_geography
+ Physics -> R.string.subject_physics
+ Moral -> R.string.subject_moral
+ Chemistry -> R.string.subject_chemistry
+ History -> R.string.subject_history
+ Others -> R.string.subject_others
+ }
+ return context.getString(resId) // 返回资源中的文本
+ }
+
+ companion object {
+ // 根据 ID 获取 Subjects
+ fun fromId(id: Int): Subjects {
+ return entries.find { it.id == id } ?: Others
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/ManagerFragment.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/ManagerFragment.kt
index e3fcb55..6b26ea9 100644
--- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/ManagerFragment.kt
+++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/main/ManagerFragment.kt
@@ -13,10 +13,12 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
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
import cn.super12138.todo.logic.database.TodoEntity
+import cn.super12138.todo.logic.model.Subjects
import cn.super12138.todo.ui.pages.main.components.TodoCard
@Composable
@@ -27,6 +29,7 @@ fun ManagerFragment(
onItemChecked: (TodoEntity) -> Unit = {},
modifier: Modifier = Modifier
) {
+ val context = LocalContext.current
LazyColumn(
modifier = modifier,
state = state,
@@ -55,7 +58,7 @@ fun ManagerFragment(
) { item ->
TodoCard(
content = item.content,
- subject = item.subject,
+ subject = Subjects.fromId(item.subject).getDisplayName(context),
onCardClick = { onItemClick(item) },
onChecked = { onItemChecked(item) },
modifier = Modifier
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 a4b9b75..c8e3f34 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
@@ -30,6 +30,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import cn.super12138.todo.R
import cn.super12138.todo.logic.database.TodoEntity
+import cn.super12138.todo.logic.model.Subjects
import cn.super12138.todo.ui.pages.main.components.FilterChipGroup
@OptIn(ExperimentalMaterial3Api::class)
@@ -76,7 +77,11 @@ fun TodoBottomSheet(
Spacer(Modifier.size(5.dp))
- val subjects = remember { context.resources.getStringArray(R.array.subjects).toList() }
+ val subjects = remember {
+ Subjects.entries.map {
+ it.getDisplayName(context)
+ }
+ }
var selectedItemIndex by rememberSaveable { mutableIntStateOf(0) }
FilterChipGroup(
items = subjects,
@@ -85,6 +90,7 @@ fun TodoBottomSheet(
},
modifier = Modifier.fillMaxWidth()
)
+
Spacer(Modifier.size(20.dp))
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
@@ -103,7 +109,7 @@ fun TodoBottomSheet(
onSave(
TodoEntity(
content = text,
- subject = subjects[selectedItemIndex]
+ subject = selectedItemIndex
)
)
}
diff --git a/app/src/main/res/values-zh-rCN/array.xml b/app/src/main/res/values-zh-rCN/array.xml
deleted file mode 100644
index 1f20984..0000000
--- a/app/src/main/res/values-zh-rCN/array.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
- - 语文
- - 数学
- - 英语
- - 生物
- - 地理
- - 物理
- - 化学
- - 道法
- - 历史
- - 其它
-
-
\ 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 d97c07a..ca79401 100644
--- a/app/src/main/res/values-zh-rCN/strings.xml
+++ b/app/src/main/res/values-zh-rCN/strings.xml
@@ -10,4 +10,14 @@
没有输入待办内容
选择该项
标记为已完成
+ 语文
+ 数学
+ 英语
+ 生物
+ 地理
+ 物理
+ 道法
+ 化学
+ 历史
+ 其它
\ No newline at end of file
diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml
deleted file mode 100644
index d319f9f..0000000
--- a/app/src/main/res/values/array.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
- - 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 f0a5eb2..b8e9dc3 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -9,4 +9,14 @@
No task content entered
Select this
Mark as completed
+ Chinese
+ Math
+ English
+ Biology
+ Geography
+ Physics
+ Morality and Rule of Law
+ Chemistry
+ History
+ Others
\ No newline at end of file