mirror of
https://github.com/bitwarden/android.git
synced 2026-06-07 23:58:03 -05:00
BIT-1135: Add confirmation dialog to lock-or-logout dialog (#364)
This commit is contained in:
committed by
Álison Fernandes
parent
62ab43dfd5
commit
e3a0832777
@@ -86,6 +86,7 @@ private const val MAXIMUM_ACCOUNT_LIMIT = 5
|
||||
* sync with the associated app bar.
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Suppress("LongMethod")
|
||||
@Composable
|
||||
fun BitwardenAccountSwitcher(
|
||||
isVisible: Boolean,
|
||||
@@ -104,19 +105,37 @@ fun BitwardenAccountSwitcher(
|
||||
var isVisibleActual by remember { mutableStateOf(isVisible) }
|
||||
|
||||
var lockOrLogoutAccount by remember { mutableStateOf<AccountSummary?>(null) }
|
||||
if (lockOrLogoutAccount != null && !isVisibleActual) {
|
||||
LockOrLogoutDialog(
|
||||
accountSummary = requireNotNull(lockOrLogoutAccount),
|
||||
onDismissRequest = { lockOrLogoutAccount = null },
|
||||
onLockAccountClick = {
|
||||
onLockAccountClick(it)
|
||||
lockOrLogoutAccount = null
|
||||
},
|
||||
onLogoutAccountClick = {
|
||||
onLogoutAccountClick(it)
|
||||
lockOrLogoutAccount = null
|
||||
},
|
||||
)
|
||||
var logoutConfirmationAccount by remember { mutableStateOf<AccountSummary?>(null) }
|
||||
when {
|
||||
isVisibleActual -> {
|
||||
// Can not show dialogs when the switcher itself is visible
|
||||
}
|
||||
|
||||
lockOrLogoutAccount != null -> {
|
||||
LockOrLogoutDialog(
|
||||
accountSummary = requireNotNull(lockOrLogoutAccount),
|
||||
onDismissRequest = { lockOrLogoutAccount = null },
|
||||
onLockAccountClick = {
|
||||
onLockAccountClick(it)
|
||||
lockOrLogoutAccount = null
|
||||
},
|
||||
onLogoutAccountClick = {
|
||||
lockOrLogoutAccount = null
|
||||
logoutConfirmationAccount = it
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
logoutConfirmationAccount != null -> {
|
||||
BitwardenLogoutConfirmationDialog(
|
||||
accountSummary = requireNotNull(logoutConfirmationAccount),
|
||||
onDismissRequest = { logoutConfirmationAccount = null },
|
||||
onConfirmClick = {
|
||||
onLogoutAccountClick(requireNotNull(logoutConfirmationAccount))
|
||||
logoutConfirmationAccount = null
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Box(modifier = modifier) {
|
||||
|
||||
@@ -3,21 +3,29 @@ package com.x8bit.bitwarden.ui.platform.components
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary
|
||||
|
||||
/**
|
||||
* A reusable dialog for confirming whether or not the user wants to log out.
|
||||
*
|
||||
* @param onDismissRequest A callback for when the dialog is requesting dismissal.
|
||||
* @param onConfirmClick A callback for when the log out confirmation button is clicked.
|
||||
* @param accountSummary Optional account information that may be used to provide additional
|
||||
* information.
|
||||
*/
|
||||
@Composable
|
||||
fun BitwardenLogoutConfirmationDialog(
|
||||
onDismissRequest: () -> Unit,
|
||||
onConfirmClick: () -> Unit,
|
||||
accountSummary: AccountSummary? = null,
|
||||
) {
|
||||
val baseConfirmationMessage = stringResource(id = R.string.logout_confirmation)
|
||||
val message = accountSummary
|
||||
?.let { "$baseConfirmationMessage\n\n${it.email}\n${it.environmentLabel}" }
|
||||
?: baseConfirmationMessage
|
||||
BitwardenTwoButtonDialog(
|
||||
title = stringResource(id = R.string.log_out),
|
||||
message = stringResource(id = R.string.logout_confirmation),
|
||||
message = message,
|
||||
confirmButtonText = stringResource(id = R.string.yes),
|
||||
onConfirmClick = onConfirmClick,
|
||||
dismissButtonText = stringResource(id = R.string.cancel),
|
||||
|
||||
@@ -136,6 +136,9 @@ class VaultViewModel @Inject constructor(
|
||||
|
||||
private fun handleLogoutAccountClick(action: VaultAction.LogoutAccountClick) {
|
||||
authRepository.logout(userId = action.accountSummary.userId)
|
||||
mutableStateFlow.update {
|
||||
it.copy(isSwitchingAccounts = action.accountSummary.isActive)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleSwitchAccountClick(action: VaultAction.SwitchAccountClick) {
|
||||
|
||||
Reference in New Issue
Block a user