Add loading dialog support to account security screen (#820)

This commit is contained in:
David Perez 2024-01-27 20:44:58 -06:00 committed by Álison Fernandes
parent f33ec6e6a3
commit e2cd1d5e98
3 changed files with 65 additions and 22 deletions

View file

@ -39,6 +39,7 @@ import com.x8bit.bitwarden.ui.platform.base.util.EventsEffect
import com.x8bit.bitwarden.ui.platform.base.util.Text
import com.x8bit.bitwarden.ui.platform.components.BitwardenExternalLinkRow
import com.x8bit.bitwarden.ui.platform.components.BitwardenListHeaderText
import com.x8bit.bitwarden.ui.platform.components.BitwardenLoadingDialog
import com.x8bit.bitwarden.ui.platform.components.BitwardenLogoutConfirmationDialog
import com.x8bit.bitwarden.ui.platform.components.BitwardenScaffold
import com.x8bit.bitwarden.ui.platform.components.BitwardenSelectionDialog
@ -48,6 +49,7 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenTextRow
import com.x8bit.bitwarden.ui.platform.components.BitwardenTopAppBar
import com.x8bit.bitwarden.ui.platform.components.BitwardenTwoButtonDialog
import com.x8bit.bitwarden.ui.platform.components.BitwardenWideSwitch
import com.x8bit.bitwarden.ui.platform.components.LoadingDialogState
import com.x8bit.bitwarden.ui.platform.components.dialog.BitwardenTimePickerDialog
import com.x8bit.bitwarden.ui.platform.manager.biometrics.BiometricsManager
import com.x8bit.bitwarden.ui.platform.manager.intent.IntentManager
@ -111,28 +113,18 @@ fun AccountSecurityScreen(
}
}
when (state.dialog) {
AccountSecurityDialog.ConfirmLogout -> BitwardenLogoutConfirmationDialog(
onDismissRequest = remember(viewModel) {
{ viewModel.trySendAction(AccountSecurityAction.DismissDialog) }
},
onConfirmClick = remember(viewModel) {
{ viewModel.trySendAction(AccountSecurityAction.ConfirmLogoutClick) }
},
)
AccountSecurityDialog.FingerprintPhrase -> FingerPrintPhraseDialog(
fingerprintPhrase = state.fingerprintPhrase,
onDismissRequest = remember(viewModel) {
{ viewModel.trySendAction(AccountSecurityAction.DismissDialog) }
},
onLearnMore = remember(viewModel) {
{ viewModel.trySendAction(AccountSecurityAction.FingerPrintLearnMoreClick) }
},
)
null -> Unit
}
AccountSecurityDialogs(
state = state,
onDismissRequest = remember(viewModel) {
{ viewModel.trySendAction(AccountSecurityAction.DismissDialog) }
},
onConfirmLogoutClick = remember(viewModel) {
{ viewModel.trySendAction(AccountSecurityAction.ConfirmLogoutClick) }
},
onFingerprintLearnMore = remember(viewModel) {
{ viewModel.trySendAction(AccountSecurityAction.FingerPrintLearnMoreClick) }
},
)
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
BitwardenScaffold(
modifier = Modifier
@ -307,6 +299,33 @@ fun AccountSecurityScreen(
}
}
@Composable
private fun AccountSecurityDialogs(
state: AccountSecurityState,
onDismissRequest: () -> Unit,
onConfirmLogoutClick: () -> Unit,
onFingerprintLearnMore: () -> Unit,
) {
when (val dialogState = state.dialog) {
AccountSecurityDialog.ConfirmLogout -> BitwardenLogoutConfirmationDialog(
onDismissRequest = onDismissRequest,
onConfirmClick = onConfirmLogoutClick,
)
AccountSecurityDialog.FingerprintPhrase -> FingerPrintPhraseDialog(
fingerprintPhrase = state.fingerprintPhrase,
onDismissRequest = onDismissRequest,
onLearnMore = onFingerprintLearnMore,
)
is AccountSecurityDialog.Loading -> BitwardenLoadingDialog(
visibilityState = LoadingDialogState.Shown(text = dialogState.message),
)
null -> Unit
}
}
@Composable
private fun UnlockWithBiometricsRow(
isChecked: Boolean,

View file

@ -323,6 +323,14 @@ sealed class AccountSecurityDialog : Parcelable {
*/
@Parcelize
data object FingerprintPhrase : AccountSecurityDialog()
/**
* Displays a loading dialog.
*/
@Parcelize
data class Loading(
val message: Text,
) : AccountSecurityDialog()
}
/**

View file

@ -1329,6 +1329,22 @@ class AccountSecurityScreenTest : BaseComposeTest() {
}
}
@Test
fun `loading dialog should be displayed according to state`() {
val loadingMessage = "Loading"
composeTestRule.onNode(isDialog()).assertDoesNotExist()
composeTestRule.onNodeWithText(loadingMessage).assertDoesNotExist()
mutableStateFlow.update {
it.copy(dialog = AccountSecurityDialog.Loading(loadingMessage.asText()))
}
composeTestRule
.onNodeWithText("Loading")
.assertIsDisplayed()
.assert(hasAnyAncestor(isDialog()))
}
companion object {
private val DEFAULT_STATE = AccountSecurityState(
dialog = null,