Skip to content

Commit

Permalink
Box in list item context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintPatrck committed Apr 16, 2024
1 parent 612c8e8 commit c17ebc4
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ fun ItemListingScreen(
onItemClick = remember(viewModel) {
{
viewModel.trySendAction(
ItemListingAction.ItemClick(it.id)
ItemListingAction.ItemClick(it.authCode)
)
}
},
onEditItemClick = remember(viewModel) {
{
viewModel.trySendAction(
ItemListingAction.ItemClick(it.id)
ItemListingAction.EditItemClick(it.id)
)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ class ItemListingViewModel @Inject constructor(
handleItemClick(action)
}

is ItemListingAction.EditItemClick -> {
handleEditItemClick(action)
}

is ItemListingAction.DialogDismiss -> {
handleDialogDismiss()
}
Expand All @@ -117,6 +121,10 @@ class ItemListingViewModel @Inject constructor(
)
}

private fun handleEditItemClick(action: ItemListingAction.EditItemClick) {
sendEvent(ItemListingEvent.NavigateToEditItem(action.itemId))
}

private fun handleDeleteItemClick(action: ItemListingAction.DeleteItemClick) {
mutableStateFlow.update {
it.copy(
Expand Down Expand Up @@ -560,10 +568,15 @@ sealed class ItemListingAction {
data object EnterSetupKeyClick : ItemListingAction()

/**
* The user clicked a list item.
* The user clicked a list item to copy its auth code.
*/
data class ItemClick(val authCode: String) : ItemListingAction()

/**
* The user clicked edit item.
*/
data class EditItemClick(val itemId: String) : ItemListingAction()

/**
* The user dismissed the dialog.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.defaultMinSize
Expand Down Expand Up @@ -63,103 +64,105 @@ fun VaultVerificationCodeItem(
supportingLabel: String? = null,
) {
var shouldShowDropdownMenu by remember { mutableStateOf(value = false) }
Row(
modifier = Modifier
.combinedClickable(
interactionSource = remember { MutableInteractionSource() },
indication = rememberRipple(color = MaterialTheme.colorScheme.primary),
onClick = onItemClick,
onLongClick = {
shouldShowDropdownMenu = true
}
Box(modifier = modifier) {
Row(
modifier = Modifier
.combinedClickable(
interactionSource = remember { MutableInteractionSource() },
indication = rememberRipple(color = MaterialTheme.colorScheme.primary),
onClick = onItemClick,
onLongClick = {
shouldShowDropdownMenu = true
}
)
.defaultMinSize(minHeight = 72.dp)
.padding(vertical = 8.dp)
.then(modifier),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(16.dp),
) {
BitwardenIcon(
iconData = startIcon,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSurface,
modifier = Modifier.size(24.dp),
)
.defaultMinSize(minHeight = 72.dp)
.padding(vertical = 8.dp)
.then(modifier),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(16.dp),
) {
BitwardenIcon(
iconData = startIcon,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSurface,
modifier = Modifier.size(24.dp),
)

Column(
horizontalAlignment = Alignment.Start,
verticalArrangement = Arrangement.SpaceEvenly,
modifier = Modifier.weight(1f),
) {
issuer?.let {
Text(
text = it,
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
Column(
horizontalAlignment = Alignment.Start,
verticalArrangement = Arrangement.SpaceEvenly,
modifier = Modifier.weight(1f),
) {
issuer?.let {
Text(
text = it,
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}

supportingLabel?.let {
Text(
text = it,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
supportingLabel?.let {
Text(
text = it,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
}
}

BitwardenCircularCountdownIndicator(
timeLeftSeconds = timeLeftSeconds,
periodSeconds = periodSeconds,
alertThresholdSeconds = alertThresholdSeconds
)
BitwardenCircularCountdownIndicator(
timeLeftSeconds = timeLeftSeconds,
periodSeconds = periodSeconds,
alertThresholdSeconds = alertThresholdSeconds
)

Text(
text = authCode.chunked(3).joinToString(" "),
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
Text(
text = authCode.chunked(3).joinToString(" "),
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}

DropdownMenu(
expanded = shouldShowDropdownMenu,
onDismissRequest = { shouldShowDropdownMenu = false },
) {
DropdownMenuItem(
text = {
Text(text = stringResource(id = R.string.edit_item))
},
onClick = {
shouldShowDropdownMenu = false
onEditItemClick()
},
leadingIcon = {
Icon(
painter = painterResource(id = R.drawable.ic_edit_item),
contentDescription = stringResource(R.string.edit_item)
)
}
)
HorizontalDivider()
DropdownMenuItem(
text = {
Text(text = stringResource(id = R.string.delete_item))
},
onClick = {
shouldShowDropdownMenu = false
onDeleteItemClick()
},
leadingIcon = {
Icon(
painter = painterResource(id = R.drawable.ic_delete_item),
contentDescription = stringResource(id = R.string.delete_item),
)
}
)
DropdownMenu(
expanded = shouldShowDropdownMenu,
onDismissRequest = { shouldShowDropdownMenu = false },
) {
DropdownMenuItem(
text = {
Text(text = stringResource(id = R.string.edit_item))
},
onClick = {
shouldShowDropdownMenu = false
onEditItemClick()
},
leadingIcon = {
Icon(
painter = painterResource(id = R.drawable.ic_edit_item),
contentDescription = stringResource(R.string.edit_item)
)
}
)
HorizontalDivider()
DropdownMenuItem(
text = {
Text(text = stringResource(id = R.string.delete_item))
},
onClick = {
shouldShowDropdownMenu = false
onDeleteItemClick()
},
leadingIcon = {
Icon(
painter = painterResource(id = R.drawable.ic_delete_item),
contentDescription = stringResource(id = R.string.delete_item),
)
}
)
}
}
}

Expand Down

0 comments on commit c17ebc4

Please sign in to comment.