Skip to content
Merged
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 @@ -23,6 +23,7 @@ import com.bitwarden.ui.platform.resource.BitwardenString
import com.x8bit.bitwarden.ui.platform.components.listitem.BitwardenGroupItem
import com.x8bit.bitwarden.ui.tools.feature.send.handlers.SendHandlers
import com.x8bit.bitwarden.ui.tools.feature.send.model.UpgradedToPremiumCardData
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.model.ListingItemOverflowAction

private const val SEND_TYPES_COUNT: Int = 2

Expand Down Expand Up @@ -108,10 +109,13 @@ fun SendContent(
.standardHorizontalMargin(),
)
}

item {
Spacer(modifier = Modifier.height(height = 16.dp))
}
}

item {
Spacer(modifier = Modifier.height(16.dp))
BitwardenListHeaderText(
label = stringResource(id = BitwardenString.all_sends),
supportingLabel = state.sendItems.size.toString(),
Expand All @@ -131,16 +135,34 @@ fun SendContent(
trailingLabelIcons = it.iconList,
showMoreOptions = !policyDisablesSend,
onClick = { sendHandlers.onSendClick(it) },
onViewClick = { sendHandlers.onViewSendClick(it) },
onCopyClick = { sendHandlers.onCopySendClick(it) },
onEditClick = { sendHandlers.onEditSendClick(it) },
onShareClick = { sendHandlers.onShareSendClick(it) },
onDeleteClick = { sendHandlers.onDeleteSendClick(it) },
onRemovePasswordClick = if (it.hasPassword) {
{ sendHandlers.onRemovePasswordClick(it) }
} else {
null
onOverflowAction = { action ->
when (action) {
is ListingItemOverflowAction.SendAction.CopyUrlClick -> {
sendHandlers.onCopySendClick(it)
}

is ListingItemOverflowAction.SendAction.DeleteClick -> {
sendHandlers.onDeleteSendClick(it)
}

is ListingItemOverflowAction.SendAction.EditClick -> {
sendHandlers.onEditSendClick(it)
}

is ListingItemOverflowAction.SendAction.RemovePasswordClick -> {
sendHandlers.onRemovePasswordClick(it)
}

is ListingItemOverflowAction.SendAction.ShareUrlClick -> {
sendHandlers.onShareSendClick(it)
}

is ListingItemOverflowAction.SendAction.ViewClick -> {
sendHandlers.onViewSendClick(it)
}
}
},
overflowOptions = it.overflowItems,
cardStyle = state
.sendItems
.toListItemCardStyle(index = index, dividerPadding = 56.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import com.bitwarden.core.util.persistentListOfNotNull
import com.bitwarden.ui.platform.components.dialog.BitwardenTwoButtonDialog
import com.bitwarden.ui.platform.components.icon.model.IconData
import com.bitwarden.ui.platform.components.model.CardStyle
import com.bitwarden.ui.platform.resource.BitwardenDrawable
import com.bitwarden.ui.platform.resource.BitwardenString
import com.bitwarden.ui.platform.theme.BitwardenTheme
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.model.ListingItemOverflowAction
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toPersistentList
Expand All @@ -26,8 +24,9 @@ import kotlinx.collections.immutable.toPersistentList
* A Composable function that displays a row send item.
*
* @param label The primary text label to display for the item.
* @param supportingLabel An secondary text label to display beneath the label.
* @param supportingLabel A secondary text label to display beneath the label.
* @param startIcon The [Painter] object used to draw the icon at the start of the item.
* @param isDisabled Whether the item is disabled or not.
* @param showMoreOptions Whether to show the button for the overflow options.
* @param onClick The lambda to be invoked when the item is clicked.
* @param onViewClick The lambda to be invoked when the view option is clicked from the menu.
Expand All @@ -50,74 +49,59 @@ fun SendListItem(
trailingLabelIcons: ImmutableList<IconData>,
showMoreOptions: Boolean,
onClick: () -> Unit,
onViewClick: () -> Unit,
onEditClick: () -> Unit,
onCopyClick: () -> Unit,
onShareClick: () -> Unit,
onDeleteClick: () -> Unit,
onRemovePasswordClick: (() -> Unit)?,
onOverflowAction: (ListingItemOverflowAction.SendAction) -> Unit,
overflowOptions: ImmutableList<ListingItemOverflowAction.SendAction>,
cardStyle: CardStyle,
modifier: Modifier = Modifier,
) {
var shouldShowDeleteConfirmationDialog by rememberSaveable { mutableStateOf(false) }
var speedBumpAction: ListingItemOverflowAction.SendAction? by rememberSaveable {
mutableStateOf(null)
}
BitwardenListItem(
label = label,
supportingLabel = supportingLabel,
startIcon = startIcon,
trailingLabelIcons = trailingLabelIcons,
onClick = onClick,
selectionDataList = persistentListOfNotNull(
SelectionItemData(
text = stringResource(id = BitwardenString.copy_link),
onClick = onCopyClick,
),
SelectionItemData(
text = stringResource(id = BitwardenString.share_link),
contentDescription = stringResource(
id = BitwardenString.external_link_format,
formatArgs = arrayOf(stringResource(id = BitwardenString.share_link)),
),
onClick = onShareClick,
),
SelectionItemData(
text = stringResource(id = BitwardenString.view),
onClick = onViewClick,
),
SelectionItemData(
text = stringResource(id = BitwardenString.edit),
onClick = onEditClick,
),
onRemovePasswordClick?.let {
selectionDataList = overflowOptions
.map { action ->
SelectionItemData(
text = stringResource(id = BitwardenString.remove_password),
onClick = it,
text = action.title(),
onClick = {
action
.speedBump
?.let { speedBumpAction = action }
?: onOverflowAction(action)
},
contentDescription = action.contentDescription(),
)
},
SelectionItemData(
text = stringResource(id = BitwardenString.delete),
onClick = { shouldShowDeleteConfirmationDialog = true },
),
)
}
// Only show options if allowed
.filter { showMoreOptions }
.toPersistentList(),
optionsTestTag = "Options",
cardStyle = cardStyle,
modifier = modifier,
)
if (shouldShowDeleteConfirmationDialog) {
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 = {
shouldShowDeleteConfirmationDialog = false
onDeleteClick()
},
onDismissClick = { shouldShowDeleteConfirmationDialog = false },
onDismissRequest = { shouldShowDeleteConfirmationDialog = false },
)
speedBumpAction?.let { action ->
action
.speedBump
?.let { speedBump ->
BitwardenTwoButtonDialog(
twoButtonDialogData = speedBump,
onConfirmClick = {
speedBumpAction = null
onOverflowAction(action)
},
onDismissClick = { speedBumpAction = null },
onDismissRequest = { speedBumpAction = null },
)
}
?: run {
// If we somehow get here and there is no speed bump, then we should keep on going.
speedBumpAction = null
onOverflowAction(action)
}
}
}

Expand All @@ -131,13 +115,9 @@ private fun SendListItem_preview() {
startIcon = IconData.Local(BitwardenDrawable.ic_file_text),
trailingLabelIcons = persistentListOf(),
showMoreOptions = true,
overflowOptions = persistentListOf(),
onOverflowAction = { },
onClick = {},
onCopyClick = {},
onViewClick = {},
onEditClick = {},
onShareClick = {},
onDeleteClick = {},
onRemovePasswordClick = null,
cardStyle = CardStyle.Full,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.x8bit.bitwarden.ui.tools.feature.send.model.SendItemType
import com.x8bit.bitwarden.ui.tools.feature.send.util.toSendItemType
import com.x8bit.bitwarden.ui.tools.feature.send.util.toViewState
import com.x8bit.bitwarden.ui.vault.feature.item.VaultItemScreen
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.model.ListingItemOverflowAction
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -66,7 +67,8 @@ class SendViewModel @Inject constructor(
) : BaseViewModel<SendState, SendEvent, SendAction>(
// We load the state from the savedStateHandle for testing purposes.
initialState = savedStateHandle[KEY_STATE]
?: policyManager.getEffectiveSendPolicy().let { effectiveSendPolicy ->
?: run {
val effectiveSendPolicy = policyManager.getEffectiveSendPolicy()
SendState(
viewState = SendState.ViewState.Loading,
dialogState = null,
Expand Down Expand Up @@ -565,7 +567,7 @@ data class SendState(
override val shouldDisplayFab: Boolean get() = true

/**
* Represents the an individual send item to be displayed.
* Represents an individual send item to be displayed.
*/
@Parcelize
data class SendItem(
Expand All @@ -576,6 +578,7 @@ data class SendState(
val iconList: ImmutableList<IconData>,
val shareUrl: String,
val hasPassword: Boolean,
val overflowItems: ImmutableList<ListingItemOverflowAction.SendAction>,
) : Parcelable {
/**
* Indicates the type of send this, a text or file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private fun List<SendView>.toSendContent(
iconList = sendView.toLabelIcons(),
shareUrl = sendView.toSendUrl(baseWebSendUrl),
hasPassword = sendView.hasPassword,
overflowItems = sendView.toOverflowActions(baseWebSendUrl),

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 PR migrates the SendScreen to use the common toOverflowActions function, which allows us to reuse the logic.

)
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ fun SendView.toOverflowActions(
sendUrl = toSendUrl(baseWebSendUrl = baseWebSendUrl),
),
ListingItemOverflowAction.SendAction.ViewClick(sendId = sendId, sendType = type),
ListingItemOverflowAction.SendAction.EditClick(sendId = sendId, sendType = type),
ListingItemOverflowAction.SendAction.EditClick(sendId = sendId, sendType = type)
.takeUnless { this.disabled },
ListingItemOverflowAction.SendAction.RemovePasswordClick(sendId = sendId).takeIf {
hasPassword
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ 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?
override val speedBump: BitwardenTwoButtonDialogData
get() = BitwardenTwoButtonDialogData(
title = BitwardenString.delete.asText(),
message = BitwardenString.are_you_sure_delete_send.asText(),
Expand Down Expand Up @@ -296,7 +296,7 @@ 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?
override val speedBump: BitwardenTwoButtonDialogData
get() = BitwardenTwoButtonDialogData(
title = BitwardenString.archive_item.asText(),
message = BitwardenString.once_archived_this_item_will_be_excluded.asText(),
Expand Down
Loading
Loading