Moving recovery password dialogs to compose for QA

This commit is contained in:
ThomasSession 2024-10-04 14:20:55 +10:00
parent 390757fe50
commit d257a1a072
2 changed files with 56 additions and 32 deletions

View File

@ -26,7 +26,10 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import network.loki.messenger.R import network.loki.messenger.R
import org.thoughtcrime.securesms.ui.AlertDialog
import org.thoughtcrime.securesms.ui.Cell 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.SessionShieldIcon
import org.thoughtcrime.securesms.ui.components.QrImage import org.thoughtcrime.securesms.ui.components.QrImage
import org.thoughtcrime.securesms.ui.components.SlimOutlineButton import org.thoughtcrime.securesms.ui.components.SlimOutlineButton
@ -45,8 +48,8 @@ import org.thoughtcrime.securesms.ui.theme.monospace
internal fun RecoveryPasswordScreen( internal fun RecoveryPasswordScreen(
mnemonic: String, mnemonic: String,
seed: String? = null, seed: String? = null,
copyMnemonic:() -> Unit = {}, confirmHideRecovery: () -> Unit,
onHide:() -> Unit = {} copyMnemonic:() -> Unit = {}
) { ) {
Column( Column(
verticalArrangement = Arrangement.spacedBy(LocalDimensions.current.smallSpacing), verticalArrangement = Arrangement.spacedBy(LocalDimensions.current.smallSpacing),
@ -57,7 +60,7 @@ internal fun RecoveryPasswordScreen(
.padding(horizontal = LocalDimensions.current.spacing) .padding(horizontal = LocalDimensions.current.spacing)
) { ) {
RecoveryPasswordCell(mnemonic, seed, copyMnemonic) RecoveryPasswordCell(mnemonic, seed, copyMnemonic)
HideRecoveryPasswordCell(onHide) HideRecoveryPasswordCell(confirmHideRecovery = confirmHideRecovery)
} }
} }
@ -151,7 +154,12 @@ private fun RecoveryPassword(mnemonic: String) {
} }
@Composable @Composable
private fun HideRecoveryPasswordCell(onHide: () -> Unit = {}) { private fun HideRecoveryPasswordCell(
confirmHideRecovery:() -> Unit
) {
var showHideRecoveryDialog by remember { mutableStateOf(false) }
var showHideRecoveryConfirmationDialog by remember { mutableStateOf(false) }
Cell { Cell {
Row( Row(
modifier = Modifier.padding(LocalDimensions.current.smallSpacing) modifier = Modifier.padding(LocalDimensions.current.smallSpacing)
@ -176,10 +184,44 @@ private fun HideRecoveryPasswordCell(onHide: () -> Unit = {}) {
.align(Alignment.CenterVertically) .align(Alignment.CenterVertically)
.contentDescription(R.string.AccessibilityId_recoveryPasswordHideRecoveryPassword), .contentDescription(R.string.AccessibilityId_recoveryPasswordHideRecoveryPassword),
color = LocalColors.current.danger, 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 @Preview
@ -188,6 +230,9 @@ private fun PreviewRecoveryPasswordScreen(
@PreviewParameter(SessionColorsParameterProvider::class) colors: ThemeColors @PreviewParameter(SessionColorsParameterProvider::class) colors: ThemeColors
) { ) {
PreviewTheme(colors) { 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 = {}
)
} }
} }

View File

@ -24,33 +24,12 @@ class RecoveryPasswordActivity : BaseActionBarActivity() {
RecoveryPasswordScreen( RecoveryPasswordScreen(
mnemonic = mnemonic, mnemonic = mnemonic,
seed = seed, seed = seed,
copyMnemonic = viewModel::copyMnemonic, confirmHideRecovery = {
onHide = ::onHide 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()
}
}
}
} }