Extract strings

This commit is contained in:
maxmoney21m
2023-03-12 21:57:32 +08:00
parent 32b50418de
commit cc36dcffe0
5 changed files with 34 additions and 31 deletions

View File

@@ -22,7 +22,7 @@ import java.util.Locale
// To use plaintext SharedPreferences for debugging, set this to true // To use plaintext SharedPreferences for debugging, set this to true
// It will only apply in Debug builds // It will only apply in Debug builds
private const val DEBUG_PLAINTEXT_PREFERENCES = false private const val DEBUG_PLAINTEXT_PREFERENCES = false
private const val OLD_PREFS_FILENAME = "secret_keeper" private const val DEBUG_PREFERENCES_NAME = "debug_prefs"
data class AccountInfo( data class AccountInfo(
val npub: String, val npub: String,
@@ -114,7 +114,7 @@ object LocalPreferences {
private fun encryptedPreferences(npub: String? = null): SharedPreferences { private fun encryptedPreferences(npub: String? = null): SharedPreferences {
return if (BuildConfig.DEBUG && DEBUG_PLAINTEXT_PREFERENCES) { return if (BuildConfig.DEBUG && DEBUG_PLAINTEXT_PREFERENCES) {
val preferenceFile = if (npub == null) "debug_prefs" else "debug_prefs_$npub" val preferenceFile = if (npub == null) DEBUG_PREFERENCES_NAME else "${DEBUG_PREFERENCES_NAME}_$npub"
Amethyst.instance.getSharedPreferences(preferenceFile, Context.MODE_PRIVATE) Amethyst.instance.getSharedPreferences(preferenceFile, Context.MODE_PRIVATE)
} else { } else {
return EncryptedStorage.preferences(npub) return EncryptedStorage.preferences(npub)

View File

@@ -80,7 +80,7 @@ fun AccountSwitchBottomSheet(
horizontalArrangement = Arrangement.Center, horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
Text("Select Account", fontWeight = FontWeight.Bold) Text(stringResource(R.string.account_switch_select_account), fontWeight = FontWeight.Bold)
} }
accounts.forEach { acc -> accounts.forEach { acc ->
val current = accountUser.pubkeyNpub() == acc.npub val current = accountUser.pubkeyNpub() == acc.npub
@@ -92,20 +92,24 @@ fun AccountSwitchBottomSheet(
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
Row( Row(
modifier = Modifier.weight(1f).clickable { modifier = Modifier
.weight(1f)
.clickable {
accountStateViewModel.switchUser(acc.npub) accountStateViewModel.switchUser(acc.npub)
}, },
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
Box( Box(
modifier = Modifier.width(55.dp).padding(0.dp) modifier = Modifier
.width(55.dp)
.padding(0.dp)
) { ) {
AsyncImageProxy( AsyncImageProxy(
model = ResizeImage(acc.profilePicture, 55.dp), model = ResizeImage(acc.profilePicture, 55.dp),
placeholder = BitmapPainter(RoboHashCache.get(context, acc.npub)), placeholder = BitmapPainter(RoboHashCache.get(context, acc.npub)),
fallback = BitmapPainter(RoboHashCache.get(context, acc.npub)), fallback = BitmapPainter(RoboHashCache.get(context, acc.npub)),
error = BitmapPainter(RoboHashCache.get(context, acc.npub)), error = BitmapPainter(RoboHashCache.get(context, acc.npub)),
contentDescription = stringResource(id = R.string.profile_image), contentDescription = stringResource(R.string.profile_image),
modifier = Modifier modifier = Modifier
.width(55.dp) .width(55.dp)
.height(55.dp) .height(55.dp)
@@ -113,19 +117,21 @@ fun AccountSwitchBottomSheet(
) )
Box( Box(
modifier = Modifier.size(20.dp).align(Alignment.TopEnd) modifier = Modifier
.size(20.dp)
.align(Alignment.TopEnd)
) { ) {
if (acc.hasPrivKey) { if (acc.hasPrivKey) {
Icon( Icon(
imageVector = Icons.Default.Key, imageVector = Icons.Default.Key,
contentDescription = "Has private key", contentDescription = stringResource(R.string.account_switch_has_private_key),
modifier = Modifier.size(20.dp), modifier = Modifier.size(20.dp),
tint = MaterialTheme.colors.primary tint = MaterialTheme.colors.primary
) )
} else { } else {
Icon( Icon(
imageVector = Icons.Default.Visibility, imageVector = Icons.Default.Visibility,
contentDescription = "Read only, no private key", contentDescription = stringResource(R.string.account_switch_pubkey_only),
modifier = Modifier.size(20.dp), modifier = Modifier.size(20.dp),
tint = MaterialTheme.colors.primary tint = MaterialTheme.colors.primary
) )
@@ -146,7 +152,7 @@ fun AccountSwitchBottomSheet(
if (current) { if (current) {
Icon( Icon(
imageVector = Icons.Default.RadioButtonChecked, imageVector = Icons.Default.RadioButtonChecked,
contentDescription = "Active account", contentDescription = stringResource(R.string.account_switch_active_account),
tint = MaterialTheme.colors.secondary tint = MaterialTheme.colors.secondary
) )
} }
@@ -158,7 +164,7 @@ fun AccountSwitchBottomSheet(
) { ) {
Icon( Icon(
imageVector = Icons.Default.Logout, imageVector = Icons.Default.Logout,
contentDescription = "Logout", contentDescription = stringResource(R.string.log_out),
tint = MaterialTheme.colors.onSurface tint = MaterialTheme.colors.onSurface
) )
} }
@@ -172,7 +178,7 @@ fun AccountSwitchBottomSheet(
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
TextButton(onClick = { popupExpanded = true }) { TextButton(onClick = { popupExpanded = true }) {
Text("Add New Account") Text(stringResource(R.string.account_switch_add_account_btn))
} }
} }
} }
@@ -186,12 +192,12 @@ fun AccountSwitchBottomSheet(
Box { Box {
LoginPage(accountStateViewModel, isFirstLogin = false) LoginPage(accountStateViewModel, isFirstLogin = false)
TopAppBar( TopAppBar(
title = { Text(text = "Add New Account") }, title = { Text(text = stringResource(R.string.account_switch_add_account_dialog_title)) },
navigationIcon = { navigationIcon = {
IconButton(onClick = { popupExpanded = false }) { IconButton(onClick = { popupExpanded = false }) {
Icon( Icon(
imageVector = Icons.Default.ArrowBack, imageVector = Icons.Default.ArrowBack,
contentDescription = "Back", contentDescription = stringResource(R.string.back),
tint = MaterialTheme.colors.onSurface tint = MaterialTheme.colors.onSurface
) )
} }

View File

@@ -53,7 +53,6 @@ import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.ui.components.AsyncImageProxy import com.vitorpamplona.amethyst.ui.components.AsyncImageProxy
import com.vitorpamplona.amethyst.ui.components.ResizeImage import com.vitorpamplona.amethyst.ui.components.ResizeImage
import com.vitorpamplona.amethyst.ui.screen.AccountStateViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountBackupDialog import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountBackupDialog
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@@ -64,8 +63,7 @@ fun DrawerContent(
navController: NavHostController, navController: NavHostController,
scaffoldState: ScaffoldState, scaffoldState: ScaffoldState,
sheetState: ModalBottomSheetState, sheetState: ModalBottomSheetState,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel
accountStateViewModel: AccountStateViewModel
) { ) {
val accountState by accountViewModel.accountLiveData.observeAsState() val accountState by accountViewModel.accountLiveData.observeAsState()
val account = accountState?.account ?: return val account = accountState?.account ?: return
@@ -95,8 +93,7 @@ fun DrawerContent(
sheetState, sheetState,
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.weight(1F), .weight(1f),
accountStateViewModel,
account account
) )
@@ -227,7 +224,6 @@ fun ListContent(
scaffoldState: ScaffoldState, scaffoldState: ScaffoldState,
sheetState: ModalBottomSheetState, sheetState: ModalBottomSheetState,
modifier: Modifier, modifier: Modifier,
accountViewModel: AccountStateViewModel,
account: Account account: Account
) { ) {
val coroutineScope = rememberCoroutineScope() val coroutineScope = rememberCoroutineScope()
@@ -268,18 +264,11 @@ fun ListContent(
Spacer(modifier = Modifier.weight(1f)) Spacer(modifier = Modifier.weight(1f))
IconRow( IconRow(
title = "Accounts", title = stringResource(R.string.drawer_accounts),
icon = R.drawable.manage_accounts, icon = R.drawable.manage_accounts,
tint = MaterialTheme.colors.onBackground, tint = MaterialTheme.colors.onBackground,
onClick = { coroutineScope.launch { sheetState.show() } } onClick = { coroutineScope.launch { sheetState.show() } }
) )
// IconRow(
// title = stringResource(R.string.log_out),
// icon = R.drawable.ic_logout,
// tint = MaterialTheme.colors.onBackground,
// onClick = { accountViewModel.logOff() }
// )
} }
if (backupDialogOpen) { if (backupDialogOpen) {

View File

@@ -61,7 +61,7 @@ fun MainScreen(accountViewModel: AccountViewModel, accountStateViewModel: Accoun
AppTopBar(navController, scaffoldState, accountViewModel) AppTopBar(navController, scaffoldState, accountViewModel)
}, },
drawerContent = { drawerContent = {
DrawerContent(navController, scaffoldState, sheetState, accountViewModel, accountStateViewModel) DrawerContent(navController, scaffoldState, sheetState, accountViewModel)
}, },
floatingActionButton = { floatingActionButton = {
FloatingButton(navController, accountStateViewModel) FloatingButton(navController, accountStateViewModel)

View File

@@ -220,5 +220,13 @@
<string name="private_conversation_notification">"&lt;Unable to decrypt private message&gt;\n\nYou were cited in a private/encrypted conversation between %1$s and %2$s."</string> <string name="private_conversation_notification">"&lt;Unable to decrypt private message&gt;\n\nYou were cited in a private/encrypted conversation between %1$s and %2$s."</string>
<string name="quick_action_delete_button">Delete</string> <string name="quick_action_delete_button">Delete</string>
<string name="quick_action_dont_show_again_button">Don\'t show again</string> <string name="quick_action_dont_show_again_button">Don\'t show again</string>
<string name="account_switch_add_account_dialog_title">Add New Account</string>
<string name="drawer_accounts">Accounts</string>
<string name="account_switch_select_account">Select Account</string>
<string name="account_switch_add_account_btn">Add New Account</string>
<string name="account_switch_active_account">Active account</string>
<string name="account_switch_has_private_key">Has private key</string>
<string name="account_switch_pubkey_only">Read only, no private key</string>
<string name="back">Back</string>
</resources> </resources>