Skip to content

Commit

Permalink
翻译
Browse files Browse the repository at this point in the history
  • Loading branch information
guozhiqiang123 committed Nov 13, 2022
1 parent fea789d commit ce13380
Show file tree
Hide file tree
Showing 13 changed files with 275 additions and 64 deletions.
6 changes: 5 additions & 1 deletion app/src/main/java/com/gzq/wanandroid/exit_app/ExitApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.gzq.wanandroid.R
import com.gzq.wanandroid.features.main.LocalSnackbarHostState
import kotlinx.coroutines.launch

Expand All @@ -18,11 +20,13 @@ fun MyBackHandler(snackbarHostState: SnackbarHostState = LocalSnackbarHostState.

val scope = rememberCoroutineScope()

val exitApp = stringResource(id = R.string.exit_app_tips)

BackHandler(enabled = true) {
val curTime = System.currentTimeMillis()
if (curTime - lastBackTime > 2000) {
scope.launch {
snackbarHostState.showSnackbar("再按一次退出程序")
snackbarHostState.showSnackbar(exitApp)
}
lastBackTime = curTime
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ 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 androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import androidx.navigation.compose.composable
import com.gzq.wanandroid.MainActivity
import com.gzq.wanandroid.R
import com.gzq.wanandroid.router.Router
import com.gzq.wanandroid.widget.MyTopAppBar
import com.yariksoffice.lingver.Lingver
Expand Down Expand Up @@ -67,7 +69,7 @@ fun ChangeThemePage(clickBack: () -> Unit) {
}

Scaffold(topBar = {
MyTopAppBar(titleStr = "切换语言", clickBack = clickBack)
MyTopAppBar(titleStr = stringResource(id = R.string.change_language), clickBack = clickBack)
}) { paddingValues ->
Column(
modifier = Modifier
Expand All @@ -91,7 +93,10 @@ fun ChangeThemePage(clickBack: () -> Unit) {
.padding(horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(text = "跟随系统", modifier = Modifier.weight(1.0f))
Text(
text = stringResource(id = R.string.follow_system),
modifier = Modifier.weight(1.0f)
)
RadioButton(
selected = Lingver.getInstance().isFollowingSystemLocale(),
onClick = null
Expand Down Expand Up @@ -140,7 +145,10 @@ fun ChangeThemePage(clickBack: () -> Unit) {
.padding(horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(text = "英文", modifier = Modifier.weight(1.0f))
Text(
text = stringResource(id = R.string.language_english),
modifier = Modifier.weight(1.0f)
)
RadioButton(selected = language == Locale.ENGLISH, onClick = null)
}
Divider(Modifier.padding(horizontal = 16.dp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import androidx.navigation.compose.composable
import com.gzq.wanandroid.LocalKey
import com.gzq.wanandroid.R
import com.gzq.wanandroid.core.quality.LogCompositions
import com.gzq.wanandroid.router.Router
import com.gzq.wanandroid.ui.theme.Theme
Expand Down Expand Up @@ -51,7 +53,7 @@ fun ChangeThemePage(clickBack: () -> Unit) {
LogCompositions(msg = "ChangeThemePage")

Scaffold(topBar = {
MyTopAppBar(titleStr = "切换主题", clickBack = clickBack)
MyTopAppBar(titleStr = stringResource(id = R.string.change_theme), clickBack = clickBack)
}) { paddingValues ->


Expand All @@ -74,7 +76,10 @@ fun ChangeThemePage(clickBack: () -> Unit) {
.padding(horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(text = "默认", modifier = Modifier.weight(1.0f))
Text(
text = stringResource(id = R.string.theme_default),
modifier = Modifier.weight(1.0f)
)
RadioButton(selected = theme == Theme.Default, onClick = null)
}
Divider(Modifier.padding(horizontal = 16.dp))
Expand All @@ -86,7 +91,10 @@ fun ChangeThemePage(clickBack: () -> Unit) {
.padding(horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(text = "绿色", modifier = Modifier.weight(1.0f))
Text(
text = stringResource(id = R.string.theme_green),
modifier = Modifier.weight(1.0f)
)
RadioButton(selected = theme == Theme.Green, onClick = null)
}
Divider(Modifier.padding(horizontal = 16.dp))
Expand All @@ -98,7 +106,10 @@ fun ChangeThemePage(clickBack: () -> Unit) {
.padding(horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(text = "紫色", modifier = Modifier.weight(1.0f))
Text(
text = stringResource(id = R.string.theme_purple),
modifier = Modifier.weight(1.0f)
)
RadioButton(selected = theme == Theme.Purple, onClick = null)
}
Divider(Modifier.padding(horizontal = 16.dp))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gzq.wanandroid.features.home.profile

import androidx.annotation.StringRes
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -40,7 +41,9 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand Down Expand Up @@ -193,7 +196,7 @@ fun ProfileMainPage(

//用户名
ProfileUserNameC(
if (userInfo == null) "登录/注册"
if (userInfo == null) stringResource(id = R.string.sign_in_up)
else userInfo!!.nickname ?: ""
) { scroll.value }
}
Expand Down Expand Up @@ -242,16 +245,16 @@ fun BaseUserInfo() {
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.tertiaryContainer)
) {
Row(Modifier.height(80.dp)) {
BaseUserInfoItem(label = "收藏", value = "4")
BaseUserInfoItem(label = "分享", value = "1")
BaseUserInfoItem(label = "积分", value = "541")
BaseUserInfoItem(label = "历史", value = "41")
BaseUserInfoItem(labelId = R.string.collection, value = "4")
BaseUserInfoItem(labelId = R.string.share, value = "1")
BaseUserInfoItem(labelId = R.string.rewards_points, value = "541")
BaseUserInfoItem(labelId = R.string.history, value = "41")
}
}
}

@Composable
fun RowScope.BaseUserInfoItem(label: String, value: String) {
fun RowScope.BaseUserInfoItem(@StringRes labelId: Int, value: String) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
Expand All @@ -265,7 +268,7 @@ fun RowScope.BaseUserInfoItem(label: String, value: String) {
style = MaterialTheme.typography.titleLarge.copy(fontWeight = FontWeight.Bold)
)
Spacer(modifier = Modifier.height(10.dp))
Text(text = label)
Text(text = stringResource(id = labelId), maxLines = 1, overflow = TextOverflow.Ellipsis)
}
}

Expand Down Expand Up @@ -321,18 +324,21 @@ fun MenuNormal() {
.padding(horizontal = 16.dp)
) {
Text(
text = "常规",
text = stringResource(id = R.string.menu_normal),
style = MaterialTheme.typography.titleMedium.copy(color = MaterialTheme.colorScheme.onSurface)
)
Spacer(modifier = Modifier.height(12.dp))
Card {
ProfileMenuItemC(iconRes = R.drawable.icon_001, title = "隐私政策") {
ProfileMenuItemC(iconRes = R.drawable.icon_001, title = R.string.privacy_policy) {

}
ProfileMenuItemC(iconRes = R.drawable.icon_002, title = "用户协议") {
ProfileMenuItemC(iconRes = R.drawable.icon_002, title = R.string.user_service) {

}
ProfileMenuItemC(iconRes = R.drawable.icon_004, title = "开源项目") {
ProfileMenuItemC(
iconRes = R.drawable.icon_004,
title = R.string.open_source_libraries
) {

}
}
Expand All @@ -348,15 +354,15 @@ fun MenuSetup(launchChangeLanguagePage: () -> Unit, launchChangeThemePage: () ->
.padding(horizontal = 16.dp)
) {
Text(
text = "设置",
text = stringResource(id = R.string.menu_settings),
style = MaterialTheme.typography.titleMedium.copy(color = MaterialTheme.colorScheme.onSurface)
)
Spacer(modifier = Modifier.height(12.dp))
Card {
ProfileMenuItemC(iconRes = R.drawable.icon_001, title = "切换语言") {
ProfileMenuItemC(iconRes = R.drawable.icon_001, title = R.string.change_language) {
launchChangeLanguagePage()
}
ProfileMenuItemC(iconRes = R.drawable.icon_002, title = "切换主题") {
ProfileMenuItemC(iconRes = R.drawable.icon_002, title = R.string.change_theme) {
launchChangeThemePage()
}
}
Expand All @@ -372,21 +378,21 @@ fun MenuAccount(exitLogin: () -> Unit, checkUpdate: () -> Unit) {
.padding(horizontal = 16.dp)
) {
Text(
text = "账户",
text = stringResource(id = R.string.menu_account),
style = MaterialTheme.typography.titleMedium.copy(color = MaterialTheme.colorScheme.onSurface)
)
Spacer(modifier = Modifier.height(12.dp))
Card {
if (LocalLoginState.current) {
ProfileMenuItemC(
iconRes = R.drawable.icon_001,
title = "退出登录",
title = R.string.sign_out,
onClick = exitLogin
)
}
ProfileMenuItemC(
iconRes = R.drawable.icon_002,
title = "检查更新",
title = R.string.check_update,
onClick = checkUpdate
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import com.gzq.wanandroid.R

@Composable
fun LogoutDialogC(onDismiss: () -> Unit, confirm: () -> Unit) {
AlertDialog(
onDismissRequest = onDismiss,
text = {
Text(
text = "确定退出登录吗?",
text = stringResource(id = R.string.sure_sign_out),
style = MaterialTheme.typography.titleMedium
)
},
dismissButton = {
TextButton(onClick = onDismiss) {
Text(text = "取消")
Text(text = stringResource(id = R.string.cancel))
}
},
confirmButton = {
TextButton(onClick = confirm) {
Text(text = "确定")
Text(text = stringResource(id = R.string.confirm))
}
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gzq.wanandroid.features.home.profile.components

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
Expand All @@ -15,11 +16,12 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.gzq.wanandroid.R

@Composable
fun ProfileMenuItemC(@DrawableRes iconRes: Int, title: String, onClick: () -> Unit) {
fun ProfileMenuItemC(@DrawableRes iconRes: Int, @StringRes title: Int, onClick: () -> Unit) {
Row(
Modifier
.height(54.dp)
Expand All @@ -34,7 +36,7 @@ fun ProfileMenuItemC(@DrawableRes iconRes: Int, title: String, onClick: () -> Un
tint = Color.Unspecified
)
Spacer(modifier = Modifier.width(12.dp))
Text(text = title, style = MaterialTheme.typography.bodyMedium)
Text(text = stringResource(id = title), style = MaterialTheme.typography.bodyMedium)
Spacer(modifier = Modifier.weight(1.0f))
Icon(
painter = painterResource(id = R.drawable.navigate_next),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import androidx.navigation.compose.composable
import com.gzq.wanandroid.R
import com.gzq.wanandroid.core.preview.DevicePreviews
import com.gzq.wanandroid.core.preview.ThemePreviews
import com.gzq.wanandroid.exit_app.MyBackHandler
Expand All @@ -22,7 +24,7 @@ fun NavGraphBuilder.projectMainPage(
navController: NavHostController,
) {
composable(Router.ProjectPage.route) {
ProjectMainPage( routeGlideImagePage = {
ProjectMainPage(routeGlideImagePage = {
navController.navigate(Router.GlideImagePage.route)
}, routeCoilImagePage = {
navController.navigate(Router.CoilImagePage.route)
Expand All @@ -34,8 +36,6 @@ fun NavGraphBuilder.projectMainPage(
}
}

@ThemePreviews
@DevicePreviews
@Composable
fun ProjectMainPage(
modifier: Modifier = Modifier,
Expand All @@ -55,31 +55,31 @@ fun ProjectMainPage(
onClick = routeGlideImagePage ?: {},
Modifier.fillMaxWidth()
) {
Text(text = "Glide加载图片")
Text(text = stringResource(id = R.string.glide_load_image))
}
}
item {
Button(
onClick = routeCoilImagePage ?: {},
Modifier.fillMaxWidth()
) {
Text(text = "Coil加载图片")
Text(text = stringResource(id = R.string.coil_load_image))
}
}
item {
Button(
onClick = routeSketchImagePage ?: {},
Modifier.fillMaxWidth()
) {
Text(text = "Sketch加载图片")
Text(text = stringResource(id = R.string.sketch_load_image))
}
}
item {
Button(
onClick = routeFreeStylePage ?: {},
Modifier.fillMaxWidth()
) {
Text(text = "自由测试项目")
Text(text = stringResource(id = R.string.free_style_projects))
}
}
}
Expand Down
Loading

0 comments on commit ce13380

Please sign in to comment.