mirror of
https://github.com/bitwarden/android.git
synced 2025-12-10 19:17:16 -06:00
Showing cross instead of a back arrow when user only has one account on VerifyPasswordScreen
Cross click should cancel the operation
This commit is contained in:
parent
855c54daa0
commit
b2716cd7d2
@ -20,8 +20,12 @@ import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.credentials.providerevents.exception.ImportCredentialsCancellationException
|
||||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.bitwarden.cxf.manager.CredentialExchangeCompletionManager
|
||||
import com.bitwarden.cxf.manager.model.ExportCredentialsResult
|
||||
import com.bitwarden.cxf.ui.composition.LocalCredentialExchangeCompletionManager
|
||||
import com.bitwarden.ui.platform.base.util.EventsEffect
|
||||
import com.bitwarden.ui.platform.base.util.standardHorizontalMargin
|
||||
import com.bitwarden.ui.platform.components.button.BitwardenFilledButton
|
||||
@ -47,6 +51,8 @@ fun VerifyPasswordScreen(
|
||||
onNavigateBack: () -> Unit,
|
||||
onPasswordVerified: (userId: String) -> Unit,
|
||||
viewModel: VerifyPasswordViewModel = hiltViewModel(),
|
||||
credentialExchangeCompletionManager: CredentialExchangeCompletionManager =
|
||||
LocalCredentialExchangeCompletionManager.current,
|
||||
) {
|
||||
val state by viewModel.stateFlow.collectAsStateWithLifecycle()
|
||||
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
|
||||
@ -55,6 +61,16 @@ fun VerifyPasswordScreen(
|
||||
EventsEffect(viewModel) { event ->
|
||||
when (event) {
|
||||
VerifyPasswordEvent.NavigateBack -> onNavigateBack()
|
||||
VerifyPasswordEvent.CancelExport -> {
|
||||
credentialExchangeCompletionManager
|
||||
.completeCredentialExport(
|
||||
exportResult = ExportCredentialsResult.Failure(
|
||||
error = ImportCredentialsCancellationException(
|
||||
errorMessage = "User cancelled import.",
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
is VerifyPasswordEvent.PasswordVerified -> {
|
||||
onPasswordVerified(event.userId)
|
||||
@ -69,7 +85,11 @@ fun VerifyPasswordScreen(
|
||||
|
||||
ExportItemsScaffold(
|
||||
navIcon = rememberVectorPainter(
|
||||
BitwardenDrawable.ic_back,
|
||||
id = if (state.hasOtherAccounts) {
|
||||
BitwardenDrawable.ic_back
|
||||
} else {
|
||||
BitwardenDrawable.ic_close
|
||||
},
|
||||
),
|
||||
onNavigationIconClick = handler.onNavigateBackClick,
|
||||
navigationIconContentDescription = stringResource(BitwardenString.back),
|
||||
@ -188,6 +208,7 @@ private fun VerifyPasswordContent_Preview() {
|
||||
email = "john.doe@example.com",
|
||||
)
|
||||
val state = VerifyPasswordState(
|
||||
hasOtherAccounts = true,
|
||||
accountSummaryListItem = accountSummaryListItem,
|
||||
)
|
||||
VerifyPasswordContent(
|
||||
|
||||
@ -53,6 +53,12 @@ class VerifyPasswordViewModel @Inject constructor(
|
||||
?.firstOrNull { it.userId == args.userId }
|
||||
?: throw IllegalStateException("Account not found")
|
||||
|
||||
val singleAccount = authRepository
|
||||
.userStateFlow
|
||||
.value
|
||||
?.accounts
|
||||
?.size == 1
|
||||
|
||||
val restrictedItemPolicyOrgIds = policyManager
|
||||
.getActivePolicies(PolicyTypeJson.RESTRICT_ITEM_TYPES)
|
||||
.filter { it.isEnabled }
|
||||
@ -68,6 +74,7 @@ class VerifyPasswordViewModel @Inject constructor(
|
||||
.organizations
|
||||
.any { it.id in restrictedItemPolicyOrgIds },
|
||||
),
|
||||
hasOtherAccounts = !singleAccount,
|
||||
)
|
||||
},
|
||||
) {
|
||||
@ -111,7 +118,11 @@ class VerifyPasswordViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
private fun handleNavigateBackClick() {
|
||||
sendEvent(VerifyPasswordEvent.NavigateBack)
|
||||
if (state.hasOtherAccounts) {
|
||||
sendEvent(VerifyPasswordEvent.NavigateBack)
|
||||
} else {
|
||||
sendEvent(VerifyPasswordEvent.CancelExport)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleUnlockClick() {
|
||||
@ -304,6 +315,7 @@ class VerifyPasswordViewModel @Inject constructor(
|
||||
@Parcelize
|
||||
data class VerifyPasswordState(
|
||||
val accountSummaryListItem: AccountSelectionListItem,
|
||||
val hasOtherAccounts: Boolean,
|
||||
// We never want this saved since the input is sensitive data.
|
||||
@IgnoredOnParcel val input: String = "",
|
||||
val dialog: DialogState? = null,
|
||||
@ -356,6 +368,11 @@ sealed class VerifyPasswordEvent {
|
||||
* @param userId The ID of the user whose password was verified.
|
||||
*/
|
||||
data class PasswordVerified(val userId: String) : VerifyPasswordEvent()
|
||||
|
||||
/**
|
||||
* Cancel the export request.
|
||||
*/
|
||||
data object CancelExport : VerifyPasswordEvent()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user