refactor: 国际化适配
This commit is contained in:
parent
6acabb0367
commit
01efdcf7cc
9 changed files with 68 additions and 32 deletions
|
|
@ -80,11 +80,11 @@ fun MainPage(viewModel: MainViewModel, modifier: Modifier = Modifier) {
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Outlined.Add,
|
imageVector = Icons.Outlined.Add,
|
||||||
contentDescription = stringResource(R.string.action_add_todo)
|
contentDescription = stringResource(R.string.actions_add_task)
|
||||||
)
|
)
|
||||||
AnimatedVisibility(isExpanded) {
|
AnimatedVisibility(isExpanded) {
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.action_add_todo),
|
text = stringResource(R.string.actions_add_task),
|
||||||
modifier = Modifier.padding(start = 8.dp)
|
modifier = Modifier.padding(start = 8.dp)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,9 +65,5 @@ fun ProgressFragment(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*Slider(
|
|
||||||
value = progress,
|
|
||||||
onValueChange = { progress = it }
|
|
||||||
)*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,10 +20,12 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableIntStateOf
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import cn.super12138.todo.R
|
import cn.super12138.todo.R
|
||||||
|
|
@ -39,6 +41,8 @@ fun TodoBottomSheet(
|
||||||
onClose: () -> Unit,
|
onClose: () -> Unit,
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
ModalBottomSheet(
|
ModalBottomSheet(
|
||||||
sheetState = sheetState,
|
sheetState = sheetState,
|
||||||
onDismissRequest = onDismissRequest,
|
onDismissRequest = onDismissRequest,
|
||||||
|
|
@ -49,40 +53,30 @@ fun TodoBottomSheet(
|
||||||
modifier = Modifier.padding(horizontal = 16.dp)
|
modifier = Modifier.padding(horizontal = 16.dp)
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.action_add_todo),
|
text = stringResource(R.string.actions_add_task),
|
||||||
style = MaterialTheme.typography.headlineMedium
|
style = MaterialTheme.typography.headlineMedium
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(Modifier.size(25.dp))
|
Spacer(Modifier.size(25.dp))
|
||||||
|
|
||||||
var text by rememberSaveable { mutableStateOf("") }
|
var text by rememberSaveable { mutableStateOf("") }
|
||||||
var isError by rememberSaveable { mutableStateOf(false) }
|
var isError by rememberSaveable { mutableStateOf(false) }
|
||||||
TextField(
|
TextField(
|
||||||
value = text,
|
value = text,
|
||||||
onValueChange = { text = it },
|
onValueChange = { text = it },
|
||||||
label = { Text("待办内容") },
|
label = { Text(stringResource(R.string.placeholder_add_todo)) },
|
||||||
isError = isError,
|
isError = isError,
|
||||||
supportingText = {
|
supportingText = {
|
||||||
AnimatedVisibility(isError) {
|
AnimatedVisibility(isError) {
|
||||||
Text("没有内容")
|
Text(stringResource(R.string.error_no_task_content))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
modifier = Modifier.fillMaxWidth()
|
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) }
|
var selectedItemIndex by rememberSaveable { mutableIntStateOf(0) }
|
||||||
FilterChipGroup(
|
FilterChipGroup(
|
||||||
items = subjects,
|
items = subjects,
|
||||||
|
|
@ -94,17 +88,17 @@ fun TodoBottomSheet(
|
||||||
Spacer(Modifier.size(20.dp))
|
Spacer(Modifier.size(20.dp))
|
||||||
|
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||||
OutlinedButton(
|
OutlinedButton(onClick = onClose) {
|
||||||
onClick = onClose
|
Text(stringResource(R.string.actions_cancel))
|
||||||
) {
|
|
||||||
Text("取消")
|
|
||||||
}
|
}
|
||||||
FilledTonalButton(
|
FilledTonalButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
|
// 文本为空
|
||||||
if (text.trim().isEmpty()) {
|
if (text.trim().isEmpty()) {
|
||||||
isError = true
|
isError = true
|
||||||
return@FilledTonalButton
|
return@FilledTonalButton
|
||||||
}
|
}
|
||||||
|
|
||||||
isError = false
|
isError = false
|
||||||
onSave(
|
onSave(
|
||||||
TodoEntity(
|
TodoEntity(
|
||||||
|
|
@ -114,7 +108,7 @@ fun TodoBottomSheet(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
Text("添加")
|
Text(stringResource(R.string.actions_save))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Spacer(Modifier.size(30.dp))
|
Spacer(Modifier.size(30.dp))
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,9 @@ import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import cn.super12138.todo.R
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部分参考:https://github.com/Rhythamtech/FilterChipGroup-Compose-Android/blob/main/FilterChipGroup.kt
|
* 部分参考:https://github.com/Rhythamtech/FilterChipGroup-Compose-Android/blob/main/FilterChipGroup.kt
|
||||||
|
|
@ -46,7 +48,7 @@ fun FilterChipGroup(
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Outlined.Check,
|
imageVector = Icons.Outlined.Check,
|
||||||
contentDescription = "", // TODO: 添加字符串
|
contentDescription = stringResource(R.string.tips_select_this),
|
||||||
modifier = Modifier.size(FilterChipDefaults.IconSize)
|
modifier = Modifier.size(FilterChipDefaults.IconSize)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,10 @@ import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import cn.super12138.todo.R
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TodoCard(
|
fun TodoCard(
|
||||||
|
|
@ -65,7 +67,7 @@ fun TodoCard(
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Outlined.Check,
|
imageVector = Icons.Outlined.Check,
|
||||||
tint = MaterialTheme.colorScheme.primary,
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
contentDescription = "" // TODO: 无障碍适配
|
contentDescription = stringResource(R.string.tips_mark_completed)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
15
app/src/main/res/values-zh-rCN/array.xml
Normal file
15
app/src/main/res/values-zh-rCN/array.xml
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string-array name="subjects">
|
||||||
|
<item>语文</item>
|
||||||
|
<item>数学</item>
|
||||||
|
<item>英语</item>
|
||||||
|
<item>生物</item>
|
||||||
|
<item>地理</item>
|
||||||
|
<item>物理</item>
|
||||||
|
<item>化学</item>
|
||||||
|
<item>道法</item>
|
||||||
|
<item>历史</item>
|
||||||
|
<item>其它</item>
|
||||||
|
</string-array>
|
||||||
|
</resources>
|
||||||
|
|
@ -2,6 +2,12 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">待办</string>
|
<string name="app_name">待办</string>
|
||||||
<string name="pages_settings">设置</string>
|
<string name="pages_settings">设置</string>
|
||||||
<string name="action_add_todo">添加待办</string>
|
<string name="actions_add_task">添加待办</string>
|
||||||
<string name="tips_no_task">目前没有任务要完成的,好好休息一下吧~</string>
|
<string name="tips_no_task">目前没有任务要完成的,好好休息一下吧~</string>
|
||||||
|
<string name="placeholder_add_todo">待办内容</string>
|
||||||
|
<string name="actions_cancel">取消</string>
|
||||||
|
<string name="actions_save">保存</string>
|
||||||
|
<string name="error_no_task_content">没有输入待办内容</string>
|
||||||
|
<string name="tips_select_this">选择该项</string>
|
||||||
|
<string name="tips_mark_completed">标记为已完成</string>
|
||||||
</resources>
|
</resources>
|
||||||
15
app/src/main/res/values/array.xml
Normal file
15
app/src/main/res/values/array.xml
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string-array name="subjects">
|
||||||
|
<item>Chinese</item>
|
||||||
|
<item>Math</item>
|
||||||
|
<item>English</item>
|
||||||
|
<item>Biology</item>
|
||||||
|
<item>Geography</item>
|
||||||
|
<item>Physics</item>
|
||||||
|
<item>Chemistry</item>
|
||||||
|
<item>Moral Education</item>
|
||||||
|
<item>History</item>
|
||||||
|
<item>Others</item>
|
||||||
|
</string-array>
|
||||||
|
</resources>
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">To Do</string>
|
<string name="app_name">To Do</string>
|
||||||
<string name="pages_settings">Settings</string>
|
<string name="pages_settings">Settings</string>
|
||||||
<string name="action_add_todo">Add todo</string>
|
<string name="actions_add_task">Add Task</string>
|
||||||
<string name="tips_no_task">There are no tasks to complete at the moment, take a good rest!</string>
|
<string name="tips_no_task">There are no tasks to complete at the moment, take a good rest!</string>
|
||||||
|
<string name="placeholder_add_todo">Task content</string>
|
||||||
|
<string name="actions_cancel">Cancel</string>
|
||||||
|
<string name="actions_save">Save</string>
|
||||||
|
<string name="error_no_task_content">No task content entered</string>
|
||||||
|
<string name="tips_select_this">Select this</string>
|
||||||
|
<string name="tips_mark_completed">Mark as completed</string>
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
Reference in a new issue