From d257a1a07267e0c3a9a41e9661cdeb038ac9000d Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Fri, 4 Oct 2024 14:20:55 +1000 Subject: [PATCH] Moving recovery password dialogs to compose for QA --- .../recoverypassword/RecoveryPassword.kt | 57 +++++++++++++++++-- .../RecoveryPasswordActivity.kt | 31 ++-------- 2 files changed, 56 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPassword.kt b/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPassword.kt index 4bc2724d6d..56ca84efee 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPassword.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPassword.kt @@ -26,7 +26,10 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp import network.loki.messenger.R +import org.thoughtcrime.securesms.ui.AlertDialog import org.thoughtcrime.securesms.ui.Cell +import org.thoughtcrime.securesms.ui.DialogButtonModel +import org.thoughtcrime.securesms.ui.GetString import org.thoughtcrime.securesms.ui.SessionShieldIcon import org.thoughtcrime.securesms.ui.components.QrImage import org.thoughtcrime.securesms.ui.components.SlimOutlineButton @@ -45,8 +48,8 @@ import org.thoughtcrime.securesms.ui.theme.monospace internal fun RecoveryPasswordScreen( mnemonic: String, seed: String? = null, - copyMnemonic:() -> Unit = {}, - onHide:() -> Unit = {} + confirmHideRecovery: () -> Unit, + copyMnemonic:() -> Unit = {} ) { Column( verticalArrangement = Arrangement.spacedBy(LocalDimensions.current.smallSpacing), @@ -57,7 +60,7 @@ internal fun RecoveryPasswordScreen( .padding(horizontal = LocalDimensions.current.spacing) ) { RecoveryPasswordCell(mnemonic, seed, copyMnemonic) - HideRecoveryPasswordCell(onHide) + HideRecoveryPasswordCell(confirmHideRecovery = confirmHideRecovery) } } @@ -151,7 +154,12 @@ private fun RecoveryPassword(mnemonic: String) { } @Composable -private fun HideRecoveryPasswordCell(onHide: () -> Unit = {}) { +private fun HideRecoveryPasswordCell( + confirmHideRecovery:() -> Unit +) { + var showHideRecoveryDialog by remember { mutableStateOf(false) } + var showHideRecoveryConfirmationDialog by remember { mutableStateOf(false) } + Cell { Row( modifier = Modifier.padding(LocalDimensions.current.smallSpacing) @@ -176,10 +184,44 @@ private fun HideRecoveryPasswordCell(onHide: () -> Unit = {}) { .align(Alignment.CenterVertically) .contentDescription(R.string.AccessibilityId_recoveryPasswordHideRecoveryPassword), color = LocalColors.current.danger, - onClick = onHide + onClick = { showHideRecoveryDialog = true } ) } } + + // recovery hide dialog + if(showHideRecoveryDialog) { + AlertDialog( + onDismissRequest = { showHideRecoveryDialog = false }, + title = stringResource(R.string.recoveryPasswordHidePermanently), + text = stringResource(R.string.recoveryPasswordHidePermanentlyDescription1), + buttons = listOf( + DialogButtonModel( + GetString(R.string.theContinue), + color = LocalColors.current.danger, + onClick = { showHideRecoveryConfirmationDialog = true } + ), + DialogButtonModel(GetString(android.R.string.cancel)) + ) + ) + } + + // recovery hide confirmation dialog + if(showHideRecoveryConfirmationDialog) { + AlertDialog( + onDismissRequest = { showHideRecoveryConfirmationDialog = false }, + title = stringResource(R.string.recoveryPasswordHidePermanently), + text = stringResource(R.string.recoveryPasswordHidePermanentlyDescription2), + buttons = listOf( + DialogButtonModel( + GetString(R.string.yes), + color = LocalColors.current.danger, + onClick = confirmHideRecovery + ), + DialogButtonModel(GetString(android.R.string.cancel)) + ) + ) + } } @Preview @@ -188,6 +230,9 @@ private fun PreviewRecoveryPasswordScreen( @PreviewParameter(SessionColorsParameterProvider::class) colors: ThemeColors ) { PreviewTheme(colors) { - RecoveryPasswordScreen(mnemonic = "voyage urban toyed maverick peculiar tuxedo penguin tree grass building listen speak withdraw terminal plane") + RecoveryPasswordScreen( + mnemonic = "voyage urban toyed maverick peculiar tuxedo penguin tree grass building listen speak withdraw terminal plane", + confirmHideRecovery = {} + ) } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPasswordActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPasswordActivity.kt index 543938757c..a6d38c13a0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPasswordActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/recoverypassword/RecoveryPasswordActivity.kt @@ -24,33 +24,12 @@ class RecoveryPasswordActivity : BaseActionBarActivity() { RecoveryPasswordScreen( mnemonic = mnemonic, seed = seed, - copyMnemonic = viewModel::copyMnemonic, - onHide = ::onHide + confirmHideRecovery = { + viewModel.permanentlyHidePassword() + finish() + }, + copyMnemonic = viewModel::copyMnemonic ) } } - - private fun onHide() { - showSessionDialog { - title(R.string.recoveryPasswordHidePermanently) - text(R.string.recoveryPasswordHidePermanentlyDescription1) - dangerButton(R.string.theContinue, R.string.AccessibilityId_theContinue) { onHideConfirm() } - cancelButton() - } - } - - private fun onHideConfirm() { - showSessionDialog { - title(R.string.recoveryPasswordHidePermanently) - text(R.string.recoveryPasswordHidePermanentlyDescription2) - cancelButton() - dangerButton( - R.string.yes, - contentDescription = R.string.AccessibilityId_recoveryPasswordHidePermanentlyConfirm - ) { - viewModel.permanentlyHidePassword() - finish() - } - } - } }