From 4cac496edf89c9a7261145b0ea946c8483eaea69 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 13 Mar 2024 13:42:05 +1030 Subject: [PATCH] Extract strings --- .../onboarding/LinkDeviceActivity.kt | 19 +++++++++---------- .../onboarding/LinkDeviceViewModel.kt | 19 ++++++++++--------- app/src/main/res/values/strings.xml | 11 +++++++++++ 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceActivity.kt index 32932e30a5..555ca42a4d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceActivity.kt @@ -105,7 +105,7 @@ class LinkDeviceActivity : BaseActionBarActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - supportActionBar?.title = "Load Account" + supportActionBar?.setTitle(R.string.activity_link_load_account) prefs.setHasViewedSeed(true) prefs.setConfigurationMessageSynced(false) prefs.setRestorationTime(System.currentTimeMillis()) @@ -186,12 +186,12 @@ class LinkDeviceActivity : BaseActionBarActivity() { .padding(horizontal = 60.dp) ) { Text( - "Camera Permission permanently denied. Configure in settings.", + stringResource(R.string.activity_link_camera_permission_permanently_denied_configure_in_settings), textAlign = TextAlign.Center ) Spacer(modifier = Modifier.size(20.dp)) OutlineButton( - text = "Settings", + text = stringResource(R.string.activity_link_settings), modifier = Modifier.align(Alignment.CenterHorizontally) ) { Intent(ACTION_APPLICATION_DETAILS_SETTINGS).apply { @@ -201,7 +201,7 @@ class LinkDeviceActivity : BaseActionBarActivity() { } } else { OutlineButton( - text = "Grant Camera Permission", + text = stringResource(R.string.activity_link_grant_camera_permission), modifier = Modifier.align(Alignment.Center) ) { cameraPermissionState.run { launchPermissionRequest() } @@ -218,8 +218,7 @@ class LinkDeviceActivity : BaseActionBarActivity() { errors.collect { error -> lifecycleScope.launch { scaffoldState.snackbarHostState.showSnackbar( - message = error, - actionLabel = "Dismiss" + message = error ) } } @@ -269,20 +268,20 @@ fun RecoveryPassword(state: LinkDeviceState, onChange: (String) -> Unit = {}, on ) { Spacer(Modifier.weight(1f)) Row { - Text("Recovery Password", style = MaterialTheme.typography.h4) + Text(stringResource(R.string.activity_link_recovery_password), style = MaterialTheme.typography.h4) Spacer(Modifier.width(6.dp)) Icon( painter = painterResource(id = R.drawable.ic_recovery_phrase), - contentDescription = "", + contentDescription = null, ) } Spacer(Modifier.size(28.dp)) - Text("Enter your recovery password to load your account. If you haven't saved it, you can find it in your app settings.") + Text(stringResource(R.string.activity_link_enter_your_recovery_password_to_load_your_account_if_you_haven_t_saved_it_you_can_find_it_in_your_app_settings)) Spacer(Modifier.size(24.dp)) OutlinedTextField( value = state.recoveryPhrase, onValueChange = { onChange(it) }, - placeholder = { Text("Enter your recovery password") }, + placeholder = { Text(stringResource(R.string.activity_link_enter_your_recovery_password)) }, colors = TextFieldDefaults.outlinedTextFieldColors( textColor = state.error?.let { colorDestructive } ?: LocalContentColor.current.copy(LocalContentAlpha.current), focusedBorderColor = Color(0xff414141), diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceViewModel.kt index c91939a386..c4a04c0b57 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceViewModel.kt @@ -17,6 +17,7 @@ import kotlinx.coroutines.flow.take import kotlinx.coroutines.flow.takeWhile import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch +import network.loki.messenger.R import org.session.libsignal.crypto.MnemonicCodec import org.session.libsignal.crypto.MnemonicCodec.DecodingError.InputTooShort import org.session.libsignal.crypto.MnemonicCodec.DecodingError.InvalidWord @@ -29,7 +30,7 @@ class LinkDeviceEvent(val mnemonic: ByteArray) @HiltViewModel class LinkDeviceViewModel @Inject constructor( - application: Application + private val application: Application ): AndroidViewModel(application) { private val QR_ERROR_TIME = 3.seconds private val state = MutableStateFlow(LinkDeviceState()) @@ -38,9 +39,10 @@ class LinkDeviceViewModel @Inject constructor( private val event = Channel() val eventFlow = event.receiveAsFlow().take(1) private val qrErrors = Channel() - val qrErrorsFlow = qrErrors.receiveAsFlow().debounce(QR_ERROR_TIME).takeWhile { event.isEmpty }.mapNotNull { - "This QR code does not contain a Recovery Password." - } + val qrErrorsFlow = qrErrors.receiveAsFlow() + .debounce(QR_ERROR_TIME) + .takeWhile { event.isEmpty } + .mapNotNull { application.getString(R.string.activity_link_this_qr_code_does_not_contain_a_recovery_password) } private val codec by lazy { MnemonicCodec { MnemonicUtilities.loadFileContents(getApplication(), it) } } @@ -60,7 +62,6 @@ class LinkDeviceViewModel @Inject constructor( } } - fun onChange(recoveryPhrase: String) { state.value = LinkDeviceState(recoveryPhrase) } @@ -72,10 +73,10 @@ class LinkDeviceViewModel @Inject constructor( state.update { it.copy( error = when (error) { - is InputTooShort -> "The Recovery Password you entered is not long enough. Please check and try again." - is InvalidWord -> "Some of the words in your Recovery Password are incorrect. Please check and try again." - else -> "Please check your Recovery Password and try again." - } + is InputTooShort -> R.string.activity_link_the_recovery_password_you_entered_is_not_long_enough_please_check_and_try_again + is InvalidWord -> R.string.activity_link_some_of_the_words_in_your_recovery_password_are_incorrect_please_check_and_try_again + else -> R.string.activity_link_please_check_your_recovery_password_and_try_again + }.let(application::getString) ) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2f4c3da368..a15ef7bfde 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1049,5 +1049,16 @@ Create account I have an account By using this service, you agree to our Terms of Service and Privacy Policy + This QR code does not contain a Recovery Password. + The Recovery Password you entered is not long enough. Please check and try again. + Some of the words in your Recovery Password are incorrect. Please check and try again. + Please check your Recovery Password and try again. + Load Account + Camera Permission permanently denied. Configure in settings. + Settings + Grant Camera Permission + Recovery Password + Enter your recovery password to load your account. If you haven\'t saved it, you can find it in your app settings. + Enter your recovery password