Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
Expand All @@ -33,51 +34,36 @@ import kotlinx.collections.immutable.toPersistentList
/**
* The contents state for the search screen.
*/
@Suppress("LongMethod")
@Suppress("LongMethod", "CyclomaticComplexMethod")
@Composable
fun SearchContent(
viewState: SearchState.ViewState.Content,
searchHandlers: SearchHandlers,
searchType: SearchTypeData,
modifier: Modifier = Modifier,
) {
var showConfirmationDialog: ListingItemOverflowAction? by rememberSaveable {
mutableStateOf(null)
var overflowSpeedBumpAction by remember {
mutableStateOf<ListingItemOverflowAction?>(value = null)
}
when (val option = showConfirmationDialog) {
is ListingItemOverflowAction.SendAction.DeleteClick -> {
BitwardenTwoButtonDialog(
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now encapsulated under the speedBump in the overflow action.

title = stringResource(id = BitwardenString.delete),
message = stringResource(id = BitwardenString.are_you_sure_delete_send),
confirmButtonText = stringResource(id = BitwardenString.yes),
dismissButtonText = stringResource(id = BitwardenString.cancel),
onConfirmClick = {
showConfirmationDialog = null
searchHandlers.onOverflowItemClick(option)
},
onDismissClick = { showConfirmationDialog = null },
onDismissRequest = { showConfirmationDialog = null },
)
}

is ListingItemOverflowAction.SendAction.CopyUrlClick,
is ListingItemOverflowAction.SendAction.EditClick,
is ListingItemOverflowAction.SendAction.RemovePasswordClick,
is ListingItemOverflowAction.SendAction.ShareUrlClick,
is ListingItemOverflowAction.SendAction.ViewClick,
is ListingItemOverflowAction.VaultAction.CopyNoteClick,
is ListingItemOverflowAction.VaultAction.CopyNumberClick,
is ListingItemOverflowAction.VaultAction.CopyPasswordClick,
is ListingItemOverflowAction.VaultAction.CopyTotpClick,
is ListingItemOverflowAction.VaultAction.CopySecurityCodeClick,
is ListingItemOverflowAction.VaultAction.CopyUsernameClick,
is ListingItemOverflowAction.VaultAction.EditClick,
is ListingItemOverflowAction.VaultAction.LaunchClick,
is ListingItemOverflowAction.VaultAction.ViewClick,
is ListingItemOverflowAction.VaultAction.ArchiveClick,
is ListingItemOverflowAction.VaultAction.UnarchiveClick,
null,
-> Unit
overflowSpeedBumpAction?.let { action ->
action
.speedBump
?.let { speedBump ->
BitwardenTwoButtonDialog(
twoButtonDialogData = speedBump,
onConfirmClick = {
overflowSpeedBumpAction = null
searchHandlers.onOverflowItemClick(action)
},
onDismissClick = { overflowSpeedBumpAction = null },
onDismissRequest = { overflowSpeedBumpAction = null },
)
}
?: run {
// If we somehow get here and there is no speed bump, then we should keep on going.
overflowSpeedBumpAction = null
searchHandlers.onOverflowItemClick(action)
}
}

var autofillSelectionOptionsItem by rememberSaveable {
Expand Down Expand Up @@ -143,8 +129,12 @@ fun SearchContent(
contentDescription = option.contentDescription(),
onClick = {
when (option) {
is ListingItemOverflowAction.SendAction.DeleteClick -> {
showConfirmationDialog = option
is ListingItemOverflowAction.SendAction -> {
if (option.speedBump != null) {
overflowSpeedBumpAction = option
} else {
searchHandlers.onOverflowItemClick(option)
}
}

is ListingItemOverflowAction.VaultAction -> {
Expand All @@ -155,12 +145,12 @@ fun SearchContent(
MasterPasswordRepromptData.OverflowItem(
action = option,
)
} else if (option.speedBump != null) {
overflowSpeedBumpAction = option
} else {
searchHandlers.onOverflowItemClick(option)
}
}

else -> searchHandlers.onOverflowItemClick(option)
}
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import com.x8bit.bitwarden.ui.platform.components.listitem.BitwardenListItem
import com.x8bit.bitwarden.ui.platform.components.listitem.SelectionItemData
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.handlers.VaultItemListingHandlers
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.model.ListingItemOverflowAction
import kotlinx.collections.immutable.toPersistentList
import kotlinx.collections.immutable.toImmutableList

/**
* Content view for the [VaultItemListingScreen].
Expand All @@ -46,43 +46,29 @@ fun VaultItemListingContent(
vaultItemListingHandlers: VaultItemListingHandlers,
modifier: Modifier = Modifier,
) {
var showConfirmationDialog: ListingItemOverflowAction? by rememberSaveable {
var overflowSpeedBumpAction: ListingItemOverflowAction? by rememberSaveable {
mutableStateOf(null)
}
when (val option = showConfirmationDialog) {
is ListingItemOverflowAction.SendAction.DeleteClick -> {
BitwardenTwoButtonDialog(
title = stringResource(id = BitwardenString.delete),
message = stringResource(id = BitwardenString.are_you_sure_delete_send),
confirmButtonText = stringResource(id = BitwardenString.yes),
dismissButtonText = stringResource(id = BitwardenString.cancel),
onConfirmClick = {
showConfirmationDialog = null
vaultItemListingHandlers.overflowItemClick(option)
},
onDismissClick = { showConfirmationDialog = null },
onDismissRequest = { showConfirmationDialog = null },
)
}

is ListingItemOverflowAction.SendAction.CopyUrlClick,
is ListingItemOverflowAction.SendAction.EditClick,
is ListingItemOverflowAction.SendAction.ViewClick,
is ListingItemOverflowAction.SendAction.RemovePasswordClick,
is ListingItemOverflowAction.SendAction.ShareUrlClick,
is ListingItemOverflowAction.VaultAction.CopyNoteClick,
is ListingItemOverflowAction.VaultAction.CopyNumberClick,
is ListingItemOverflowAction.VaultAction.CopyPasswordClick,
is ListingItemOverflowAction.VaultAction.CopySecurityCodeClick,
is ListingItemOverflowAction.VaultAction.CopyUsernameClick,
is ListingItemOverflowAction.VaultAction.EditClick,
is ListingItemOverflowAction.VaultAction.LaunchClick,
is ListingItemOverflowAction.VaultAction.ViewClick,
is ListingItemOverflowAction.VaultAction.CopyTotpClick,
is ListingItemOverflowAction.VaultAction.ArchiveClick,
is ListingItemOverflowAction.VaultAction.UnarchiveClick,
null,
-> Unit
overflowSpeedBumpAction?.let { action ->
action
.speedBump
?.let { speedBump ->
BitwardenTwoButtonDialog(
twoButtonDialogData = speedBump,
onConfirmClick = {
overflowSpeedBumpAction = null
vaultItemListingHandlers.overflowItemClick(action)
},
onDismissClick = { overflowSpeedBumpAction = null },
onDismissRequest = { overflowSpeedBumpAction = null },
)
}
?: run {
// If we somehow get here and there is no speed bump, then we should keep on going.
overflowSpeedBumpAction = null
vaultItemListingHandlers.overflowItemClick(action)
}
}

var masterPasswordRepromptData by remember { mutableStateOf<MasterPasswordRepromptData?>(null) }
Expand Down Expand Up @@ -264,8 +250,12 @@ fun VaultItemListingContent(
contentDescription = option.contentDescription(),
onClick = {
when (option) {
is ListingItemOverflowAction.SendAction.DeleteClick -> {
showConfirmationDialog = option
is ListingItemOverflowAction.SendAction -> {
if (option.speedBump != null) {
overflowSpeedBumpAction = option
} else {
vaultItemListingHandlers.overflowItemClick(option)
}
}

is ListingItemOverflowAction.VaultAction -> {
Expand All @@ -276,19 +266,19 @@ fun VaultItemListingContent(
MasterPasswordRepromptData.OverflowItem(
action = option,
)
} else if (option.speedBump != null) {
overflowSpeedBumpAction = option
} else {
vaultItemListingHandlers.overflowItemClick(option)
}
}

else -> vaultItemListingHandlers.overflowItemClick(option)
}
},
)
}
// Only show options if allowed
.filter { !policyDisablesSend }
.toPersistentList(),
.toImmutableList(),
cardStyle = state
.displayItemList
.toListItemCardStyle(index = index, dividerPadding = 56.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.x8bit.bitwarden.ui.vault.feature.itemlisting.model

import android.os.Parcelable
import com.bitwarden.send.SendType
import com.bitwarden.ui.platform.components.dialog.model.BitwardenTwoButtonDialogData
import com.bitwarden.ui.platform.resource.BitwardenString
import com.bitwarden.ui.util.Text
import com.bitwarden.ui.util.asText
Expand All @@ -23,6 +24,11 @@ sealed class ListingItemOverflowAction : Parcelable {
*/
abstract val contentDescription: Text

/**
* The data to be displayed for an optional speed bump dialog.
*/
abstract val speedBump: BitwardenTwoButtonDialogData?

/**
* Represents the send actions.
*/
Expand All @@ -37,6 +43,7 @@ sealed class ListingItemOverflowAction : Parcelable {
) : SendAction() {
override val title: Text get() = BitwardenString.view.asText()
override val contentDescription: Text get() = title
override val speedBump: BitwardenTwoButtonDialogData? get() = null
}

/**
Expand All @@ -49,6 +56,7 @@ sealed class ListingItemOverflowAction : Parcelable {
) : SendAction() {
override val title: Text get() = BitwardenString.edit.asText()
override val contentDescription: Text get() = title
override val speedBump: BitwardenTwoButtonDialogData? get() = null
}

/**
Expand All @@ -58,6 +66,7 @@ sealed class ListingItemOverflowAction : Parcelable {
data class CopyUrlClick(val sendUrl: String) : SendAction() {
override val title: Text get() = BitwardenString.copy_link.asText()
override val contentDescription: Text get() = title
override val speedBump: BitwardenTwoButtonDialogData? get() = null
}

/**
Expand All @@ -68,6 +77,7 @@ sealed class ListingItemOverflowAction : Parcelable {
override val title: Text get() = BitwardenString.share_link.asText()
override val contentDescription: Text
get() = BitwardenString.external_link_format.asText(title)
override val speedBump: BitwardenTwoButtonDialogData? get() = null
}

/**
Expand All @@ -77,6 +87,7 @@ sealed class ListingItemOverflowAction : Parcelable {
data class RemovePasswordClick(val sendId: String) : SendAction() {
override val title: Text get() = BitwardenString.remove_password.asText()
override val contentDescription: Text get() = title
override val speedBump: BitwardenTwoButtonDialogData? get() = null
}

/**
Expand All @@ -86,6 +97,13 @@ sealed class ListingItemOverflowAction : Parcelable {
data class DeleteClick(val sendId: String) : SendAction() {
override val title: Text get() = BitwardenString.delete.asText()
override val contentDescription: Text get() = title
override val speedBump: BitwardenTwoButtonDialogData?
get() = BitwardenTwoButtonDialogData(
title = BitwardenString.delete.asText(),
message = BitwardenString.are_you_sure_delete_send.asText(),
confirmButtonText = BitwardenString.yes.asText(),
dismissButtonText = BitwardenString.cancel.asText(),
)
}
}

Expand All @@ -110,6 +128,7 @@ sealed class ListingItemOverflowAction : Parcelable {
) : VaultAction() {
override val title: Text get() = BitwardenString.view.asText()
override val contentDescription: Text get() = title
override val speedBump: BitwardenTwoButtonDialogData? get() = null
}

/**
Expand All @@ -123,6 +142,7 @@ sealed class ListingItemOverflowAction : Parcelable {
) : VaultAction() {
override val title: Text get() = BitwardenString.edit.asText()
override val contentDescription: Text get() = title
override val speedBump: BitwardenTwoButtonDialogData? get() = null
}

/**
Expand All @@ -133,6 +153,7 @@ sealed class ListingItemOverflowAction : Parcelable {
override val title: Text get() = BitwardenString.copy_username.asText()
override val requiresPasswordReprompt: Boolean get() = false
override val contentDescription: Text get() = title
override val speedBump: BitwardenTwoButtonDialogData? get() = null
}

/**
Expand All @@ -145,6 +166,7 @@ sealed class ListingItemOverflowAction : Parcelable {
) : VaultAction() {
override val title: Text get() = BitwardenString.copy_password.asText()
override val contentDescription: Text get() = title
override val speedBump: BitwardenTwoButtonDialogData? get() = null
}

/**
Expand All @@ -157,6 +179,7 @@ sealed class ListingItemOverflowAction : Parcelable {
) : VaultAction() {
override val title: Text get() = BitwardenString.copy_totp.asText()
override val contentDescription: Text get() = title
override val speedBump: BitwardenTwoButtonDialogData? get() = null
}

/**
Expand All @@ -169,6 +192,7 @@ sealed class ListingItemOverflowAction : Parcelable {
) : VaultAction() {
override val title: Text get() = BitwardenString.copy_number.asText()
override val contentDescription: Text get() = title
override val speedBump: BitwardenTwoButtonDialogData? get() = null
}

/**
Expand All @@ -181,6 +205,7 @@ sealed class ListingItemOverflowAction : Parcelable {
) : VaultAction() {
override val title: Text get() = BitwardenString.copy_security_code.asText()
override val contentDescription: Text get() = title
override val speedBump: BitwardenTwoButtonDialogData? get() = null
}

/**
Expand All @@ -193,6 +218,7 @@ sealed class ListingItemOverflowAction : Parcelable {
) : VaultAction() {
override val title: Text get() = BitwardenString.copy_notes.asText()
override val contentDescription: Text get() = title
override val speedBump: BitwardenTwoButtonDialogData? get() = null
}

/**
Expand All @@ -204,6 +230,7 @@ sealed class ListingItemOverflowAction : Parcelable {
override val requiresPasswordReprompt: Boolean get() = false
override val contentDescription: Text
get() = BitwardenString.external_link_format.asText(title)
override val speedBump: BitwardenTwoButtonDialogData? get() = null
}

/**
Expand All @@ -214,6 +241,13 @@ sealed class ListingItemOverflowAction : Parcelable {
override val title: Text get() = BitwardenString.archive_verb.asText()
override val requiresPasswordReprompt: Boolean get() = true
override val contentDescription: Text get() = title
override val speedBump: BitwardenTwoButtonDialogData?
get() = BitwardenTwoButtonDialogData(
title = BitwardenString.archive_item.asText(),
message = BitwardenString.once_archived_this_item_will_be_excluded.asText(),
confirmButtonText = BitwardenString.archive_verb.asText(),
dismissButtonText = BitwardenString.cancel.asText(),
)
}

/**
Expand All @@ -224,6 +258,7 @@ sealed class ListingItemOverflowAction : Parcelable {
override val title: Text get() = BitwardenString.unarchive.asText()
override val requiresPasswordReprompt: Boolean get() = true
override val contentDescription: Text get() = title
override val speedBump: BitwardenTwoButtonDialogData? get() = null
}
}
}
Loading
Loading