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
// It will only apply in Debug builds
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(
val npub: String,
@@ -114,7 +114,7 @@ object LocalPreferences {
private fun encryptedPreferences(npub: String? = null): SharedPreferences {
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)
} else {
return EncryptedStorage.preferences(npub)

View File

@@ -80,7 +80,7 @@ fun AccountSwitchBottomSheet(
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically
) {
Text("Select Account", fontWeight = FontWeight.Bold)
Text(stringResource(R.string.account_switch_select_account), fontWeight = FontWeight.Bold)
}
accounts.forEach { acc ->
val current = accountUser.pubkeyNpub() == acc.npub
@@ -92,20 +92,24 @@ fun AccountSwitchBottomSheet(
verticalAlignment = Alignment.CenterVertically
) {
Row(
modifier = Modifier.weight(1f).clickable {
accountStateViewModel.switchUser(acc.npub)
},
modifier = Modifier
.weight(1f)
.clickable {
accountStateViewModel.switchUser(acc.npub)
},
verticalAlignment = Alignment.CenterVertically
) {
Box(
modifier = Modifier.width(55.dp).padding(0.dp)
modifier = Modifier
.width(55.dp)
.padding(0.dp)
) {
AsyncImageProxy(
model = ResizeImage(acc.profilePicture, 55.dp),
placeholder = BitmapPainter(RoboHashCache.get(context, acc.npub)),
fallback = 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
.width(55.dp)
.height(55.dp)
@@ -113,19 +117,21 @@ fun AccountSwitchBottomSheet(
)
Box(
modifier = Modifier.size(20.dp).align(Alignment.TopEnd)
modifier = Modifier
.size(20.dp)
.align(Alignment.TopEnd)
) {
if (acc.hasPrivKey) {
Icon(
imageVector = Icons.Default.Key,
contentDescription = "Has private key",
contentDescription = stringResource(R.string.account_switch_has_private_key),
modifier = Modifier.size(20.dp),
tint = MaterialTheme.colors.primary
)
} else {
Icon(
imageVector = Icons.Default.Visibility,
contentDescription = "Read only, no private key",
contentDescription = stringResource(R.string.account_switch_pubkey_only),
modifier = Modifier.size(20.dp),
tint = MaterialTheme.colors.primary
)
@@ -146,7 +152,7 @@ fun AccountSwitchBottomSheet(
if (current) {
Icon(
imageVector = Icons.Default.RadioButtonChecked,
contentDescription = "Active account",
contentDescription = stringResource(R.string.account_switch_active_account),
tint = MaterialTheme.colors.secondary
)
}
@@ -158,7 +164,7 @@ fun AccountSwitchBottomSheet(
) {
Icon(
imageVector = Icons.Default.Logout,
contentDescription = "Logout",
contentDescription = stringResource(R.string.log_out),
tint = MaterialTheme.colors.onSurface
)
}
@@ -172,7 +178,7 @@ fun AccountSwitchBottomSheet(
verticalAlignment = Alignment.CenterVertically
) {
TextButton(onClick = { popupExpanded = true }) {
Text("Add New Account")
Text(stringResource(R.string.account_switch_add_account_btn))
}
}
}
@@ -186,12 +192,12 @@ fun AccountSwitchBottomSheet(
Box {
LoginPage(accountStateViewModel, isFirstLogin = false)
TopAppBar(
title = { Text(text = "Add New Account") },
title = { Text(text = stringResource(R.string.account_switch_add_account_dialog_title)) },
navigationIcon = {
IconButton(onClick = { popupExpanded = false }) {
Icon(
imageVector = Icons.Default.ArrowBack,
contentDescription = "Back",
contentDescription = stringResource(R.string.back),
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.ui.components.AsyncImageProxy
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.AccountViewModel
import kotlinx.coroutines.launch
@@ -64,8 +63,7 @@ fun DrawerContent(
navController: NavHostController,
scaffoldState: ScaffoldState,
sheetState: ModalBottomSheetState,
accountViewModel: AccountViewModel,
accountStateViewModel: AccountStateViewModel
accountViewModel: AccountViewModel
) {
val accountState by accountViewModel.accountLiveData.observeAsState()
val account = accountState?.account ?: return
@@ -95,8 +93,7 @@ fun DrawerContent(
sheetState,
modifier = Modifier
.fillMaxWidth()
.weight(1F),
accountStateViewModel,
.weight(1f),
account
)
@@ -227,7 +224,6 @@ fun ListContent(
scaffoldState: ScaffoldState,
sheetState: ModalBottomSheetState,
modifier: Modifier,
accountViewModel: AccountStateViewModel,
account: Account
) {
val coroutineScope = rememberCoroutineScope()
@@ -268,18 +264,11 @@ fun ListContent(
Spacer(modifier = Modifier.weight(1f))
IconRow(
title = "Accounts",
title = stringResource(R.string.drawer_accounts),
icon = R.drawable.manage_accounts,
tint = MaterialTheme.colors.onBackground,
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) {

View File

@@ -61,7 +61,7 @@ fun MainScreen(accountViewModel: AccountViewModel, accountStateViewModel: Accoun
AppTopBar(navController, scaffoldState, accountViewModel)
},
drawerContent = {
DrawerContent(navController, scaffoldState, sheetState, accountViewModel, accountStateViewModel)
DrawerContent(navController, scaffoldState, sheetState, accountViewModel)
},
floatingActionButton = {
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="quick_action_delete_button">Delete</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>