Skip to content

Commit

Permalink
[feature|optimize] Support Traditional Chinese; optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyD666 committed Nov 16, 2023
1 parent 12d1abb commit d3707df
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 104 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {
minSdk 24
targetSdk 34
versionCode 43
versionName "1.6-beta28"
versionName "1.6-beta29"
flavorDimensions = ["versionName"]

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ class ImportExportFilesRepository @Inject constructor(
// 添加最后四个字节 0x0D000721
appContext.contentResolver.openOutputStream(zipFileUri, "wa").use { fos ->
check(fos != null) {
appContext.getString(
R.string.import_export_files_repo_error,
"Zip file OutputStream is null!"
)
appContext.getString(R.string.failed_info, "Zip file OutputStream is null!")
}
fos.write(byteArrayOf(0x0D, 0x00, 0x07, 0x21))
}
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/com/skyd/rays/ui/screen/add/AddScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavHostController
import com.skyd.rays.R
import com.skyd.rays.appContext
import com.skyd.rays.base.LoadUiIntent
import com.skyd.rays.config.refreshStickerData
import com.skyd.rays.ext.addAllDistinctly
Expand Down Expand Up @@ -233,7 +232,7 @@ fun AddScreen(
if (currentSticker() == null) {
snackbarHostState.showSnackbar(
scope = scope,
message = appContext.getString(R.string.add_screen_sticker_is_not_set),
message = context.getString(R.string.add_screen_sticker_is_not_set),
)
} else {
keyboardController?.hide()
Expand Down Expand Up @@ -369,7 +368,7 @@ fun AddScreen(
when (it) {
is LoadUiIntent.Error -> {
snackbarHostState.showSnackbarWithLaunchedEffect(
context.getString(R.string.add_screen_error, it.msg),
context.getString(R.string.failed_info, it.msg),
key2 = it,
)
}
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/com/skyd/rays/ui/screen/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ fun HomeScreen(viewModel: HomeViewModel = hiltViewModel()) {
when (loadUiIntent) {
is LoadUiIntent.Error -> {
snackbarHostState.showSnackbarWithLaunchedEffect(
message = context.getString(
R.string.home_screen_failed, loadUiIntent.msg
),
message = context.getString(R.string.failed_info, loadUiIntent.msg),
key2 = loadUiIntent,
)
}
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/skyd/rays/ui/screen/main/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Egg
import androidx.compose.material.icons.filled.Extension
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.outlined.Egg
import androidx.compose.material.icons.filled.Widgets
import androidx.compose.material.icons.outlined.Extension
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material.icons.outlined.Widgets
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
Expand Down Expand Up @@ -107,8 +107,8 @@ private fun NavigationBarOrRail(navController: NavController) {
)
val icons = remember {
mapOf(
true to listOf(Icons.Filled.Home, Icons.Filled.Extension, Icons.Filled.Egg),
false to listOf(Icons.Outlined.Home, Icons.Outlined.Extension, Icons.Outlined.Egg),
true to listOf(Icons.Filled.Home, Icons.Filled.Extension, Icons.Filled.Widgets),
false to listOf(Icons.Outlined.Home, Icons.Outlined.Extension, Icons.Outlined.Widgets),
)
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/skyd/rays/ui/screen/more/MoreScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package com.skyd.rays.ui.screen.more
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Egg
import androidx.compose.material.icons.filled.ImportExport
import androidx.compose.material.icons.filled.Info
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.filled.Widgets
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
Expand Down Expand Up @@ -57,7 +57,7 @@ fun MoreScreen() {
title = { Text(text = stringResource(id = R.string.more_screen_name)) },
navigationIcon = {
RaysIconButton(
imageVector = Icons.Default.Egg,
imageVector = Icons.Default.Widgets,
onClick = {
snackbarHostState.showSnackbar(
message = "\uD83D\uDC31 Nya~",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ fun ApiGrantScreen(viewModel: ApiGrantViewModel = hiltViewModel()) {
when (addPackageNameUiEvent) {
is AddPackageNameUiEvent.Failed -> {
snackbarHostState.showSnackbarWithLaunchedEffect(
message = context.getString(
R.string.uri_string_share_screen_failed, addPackageNameUiEvent.msg
),
message = context.getString(R.string.failed_info, addPackageNameUiEvent.msg),
key2 = addPackageNameUiEvent,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.skyd.rays.R
import com.skyd.rays.appContext
import com.skyd.rays.base.LoadUiIntent
import com.skyd.rays.ext.showSnackbarWithLaunchedEffect
import com.skyd.rays.ui.component.BaseSettingsItem
Expand All @@ -40,6 +40,7 @@ const val DATA_SCREEN_ROUTE = "dataScreen"
fun DataScreen(viewModel: DataViewModel = hiltViewModel()) {
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
val navController = LocalNavController.current
val context = LocalContext.current
val snackbarHostState = remember { SnackbarHostState() }
var openDeleteWarningDialog by rememberSaveable { mutableStateOf(false) }
var openWaitingDialog by rememberSaveable { mutableStateOf(false) }
Expand Down Expand Up @@ -82,9 +83,7 @@ fun DataScreen(viewModel: DataViewModel = hiltViewModel()) {
when (loadUiIntent) {
is LoadUiIntent.Error -> {
snackbarHostState.showSnackbarWithLaunchedEffect(
message = appContext.getString(
R.string.data_screen_failed, loadUiIntent.msg
),
message = context.getString(R.string.failed_info, loadUiIntent.msg),
key2 = loadUiIntent,
)
}
Expand All @@ -98,7 +97,7 @@ fun DataScreen(viewModel: DataViewModel = hiltViewModel()) {
when (deleteAllResultUiEvent) {
is DeleteAllResultUiEvent.Success -> {
snackbarHostState.showSnackbarWithLaunchedEffect(
message = appContext.getString(
message = context.getString(
R.string.data_screen_delete_all_success,
deleteAllResultUiEvent.time / 1000.0f
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.skyd.rays.R
import com.skyd.rays.appContext
import com.skyd.rays.base.LoadUiIntent
import com.skyd.rays.ext.dateTime
import com.skyd.rays.ext.editor
Expand Down Expand Up @@ -125,7 +124,7 @@ fun WebDavScreen(viewModel: WebDavViewModel = hiltViewModel()) {
{
scope.launch {
snackbarHostState.showSnackbar(
message = appContext.getString(R.string.webdav_screen_info_incomplete),
message = context.getString(R.string.webdav_screen_info_incomplete),
withDismissAction = true
)
}
Expand All @@ -144,7 +143,7 @@ fun WebDavScreen(viewModel: WebDavViewModel = hiltViewModel()) {
password = password,
onServerItemClick = {
inputDialogInfo = Triple(
appContext.getString(R.string.webdav_screen_input_server), server
context.getString(R.string.webdav_screen_input_server), server
) {
openInputDialog = false
WebDavServerPreference.put(
Expand All @@ -158,7 +157,7 @@ fun WebDavScreen(viewModel: WebDavViewModel = hiltViewModel()) {
},
onAccountItemClick = {
inputDialogInfo = Triple(
appContext.getString(R.string.webdav_screen_input_account), account
context.getString(R.string.webdav_screen_input_account), account
) {
account = it
openInputDialog = false
Expand All @@ -169,7 +168,7 @@ fun WebDavScreen(viewModel: WebDavViewModel = hiltViewModel()) {
},
onPasswordItemClick = {
inputDialogInfo = Triple(
appContext.getString(R.string.webdav_screen_input_password), password
context.getString(R.string.webdav_screen_input_password), password
) {
password = it
openInputDialog = false
Expand Down Expand Up @@ -221,10 +220,7 @@ fun WebDavScreen(viewModel: WebDavViewModel = hiltViewModel()) {
when (loadUiIntent) {
is LoadUiIntent.Error -> {
snackbarHostState.showSnackbarWithLaunchedEffect(
message = appContext.getString(
R.string.webdav_screen_failed,
loadUiIntent.msg
),
message = context.getString(R.string.failed_info, loadUiIntent.msg),
key2 = loadUiIntent,
)
openWaitingDialog = false
Expand Down Expand Up @@ -319,7 +315,7 @@ fun WebDavScreen(viewModel: WebDavViewModel = hiltViewModel()) {
when (val result = uploadResultUiEvent.result) {
is WebDavResultInfo -> {
snackbarHostState.showSnackbarWithLaunchedEffect(
message = appContext.resources.getQuantityString(
message = context.resources.getQuantityString(
R.plurals.webdav_screen_upload_success,
result.count,
result.time / 1000.0f, result.count
Expand All @@ -341,7 +337,7 @@ fun WebDavScreen(viewModel: WebDavViewModel = hiltViewModel()) {
when (val result = downloadResultUiEvent.result) {
is WebDavResultInfo -> {
snackbarHostState.showSnackbarWithLaunchedEffect(
message = appContext.resources.getQuantityString(
message = context.resources.getQuantityString(
R.plurals.webdav_screen_download_success,
result.count,
result.time / 1000.0f, result.count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.skyd.rays.R
import com.skyd.rays.appContext
import com.skyd.rays.base.LoadUiIntent
import com.skyd.rays.ext.plus
import com.skyd.rays.ext.showSnackbarWithLaunchedEffect
Expand Down Expand Up @@ -160,7 +159,7 @@ fun ExportFilesScreen(viewModel: ExportFilesViewModel = hiltViewModel()) {
when (val loadUi = loadUiIntent) {
is LoadUiIntent.Error -> {
snackbarHostState.showSnackbarWithLaunchedEffect(
message = appContext.getString(R.string.export_files_screen_failed, loadUi.msg),
message = context.getString(R.string.failed_info, loadUi.msg),
key2 = loadUiIntent,
)
openWaitingDialog = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.skyd.rays.R
import com.skyd.rays.appContext
import com.skyd.rays.base.LoadUiIntent
import com.skyd.rays.ext.plus
import com.skyd.rays.ext.showSnackbarWithLaunchedEffect
Expand Down Expand Up @@ -191,7 +190,7 @@ fun ImportFilesScreen(viewModel: ImportFilesViewModel = hiltViewModel()) {
when (val loadUi = loadUiIntent) {
is LoadUiIntent.Error -> {
snackbarHostState.showSnackbarWithLaunchedEffect(
message = appContext.getString(R.string.import_files_screen_failed, loadUi.msg),
message = context.getString(R.string.failed_info, loadUi.msg),
key2 = loadUiIntent,
)
openWaitingDialog = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ fun ClassificationModelScreen(viewModel: ClassificationModelViewModel = hiltView
when (it) {
is LoadUiIntent.Error -> {
snackbarHostState.showSnackbarWithLaunchedEffect(
message = context.getString(
R.string.classification_model_screen_failed,
it.msg
),
message = context.getString(R.string.failed_info, it.msg),
key2 = it,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fun ShareConfigScreen() {
item {
SwitchSettingsItem(
icon = Icons.Default.FileCopy,
checked = LocalCopyStickerToClipboard.current,
checked = LocalStickerExtName.current && LocalCopyStickerToClipboard.current,
text = stringResource(R.string.share_config_screen_copy_sticker_to_clipboard),
description = stringResource(R.string.share_config_screen_copy_sticker_to_clipboard_description),
onCheckedChange = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ fun UriStringShareScreen(viewModel: UriStringShareViewModel = hiltViewModel()) {
when (addPackageNameUiEvent) {
is AddPackageNameUiEvent.Failed -> {
snackbarHostState.showSnackbarWithLaunchedEffect(
message = context.getString(
R.string.uri_string_share_screen_failed, addPackageNameUiEvent.msg
),
message = context.getString(R.string.failed_info, addPackageNameUiEvent.msg),
key2 = addPackageNameUiEvent,
)
}
Expand Down
Loading

0 comments on commit d3707df

Please sign in to comment.