mirror of
https://github.com/bitwarden/android.git
synced 2026-06-09 08:09:16 -05:00
BIT-1304: Options menu UI for view item (#580)
This commit is contained in:
committed by
Álison Fernandes
parent
0daf81faab
commit
e9e538db59
@@ -38,7 +38,7 @@ fun NavGraphBuilder.vaultItemDestination(
|
||||
) {
|
||||
VaultItemScreen(
|
||||
onNavigateBack = onNavigateBack,
|
||||
onNavigateToVaultEditItem = onNavigateToVaultEditItem,
|
||||
onNavigateToVaultAddEditItem = onNavigateToVaultEditItem,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,9 +39,11 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenOverflowActionItem
|
||||
import com.x8bit.bitwarden.ui.platform.components.BitwardenScaffold
|
||||
import com.x8bit.bitwarden.ui.platform.components.BitwardenTopAppBar
|
||||
import com.x8bit.bitwarden.ui.platform.components.LoadingDialogState
|
||||
import com.x8bit.bitwarden.ui.platform.components.OverflowMenuItemData
|
||||
import com.x8bit.bitwarden.ui.vault.feature.item.handlers.VaultCardItemTypeHandlers
|
||||
import com.x8bit.bitwarden.ui.vault.feature.item.handlers.VaultCommonItemTypeHandlers
|
||||
import com.x8bit.bitwarden.ui.vault.feature.item.handlers.VaultLoginItemTypeHandlers
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
|
||||
/**
|
||||
* Displays the vault item screen.
|
||||
@@ -53,7 +55,7 @@ fun VaultItemScreen(
|
||||
viewModel: VaultItemViewModel = hiltViewModel(),
|
||||
intentHandler: IntentHandler = IntentHandler(context = LocalContext.current),
|
||||
onNavigateBack: () -> Unit,
|
||||
onNavigateToVaultEditItem: (vaultItemId: String) -> Unit,
|
||||
onNavigateToVaultAddEditItem: (vaultItemId: String) -> Unit,
|
||||
) {
|
||||
val state by viewModel.stateFlow.collectAsStateWithLifecycle()
|
||||
val context = LocalContext.current
|
||||
@@ -62,14 +64,28 @@ fun VaultItemScreen(
|
||||
when (event) {
|
||||
VaultItemEvent.NavigateBack -> onNavigateBack()
|
||||
|
||||
is VaultItemEvent.NavigateToEdit -> onNavigateToVaultEditItem(event.itemId)
|
||||
is VaultItemEvent.NavigateToAddEdit -> {
|
||||
// TODO Implement cloning in BIT-526
|
||||
onNavigateToVaultAddEditItem(event.itemId)
|
||||
}
|
||||
|
||||
is VaultItemEvent.NavigateToPasswordHistory -> {
|
||||
// TODO Implement password history in BIT-617
|
||||
Toast.makeText(context, "Not yet implemented.", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
is VaultItemEvent.NavigateToUri -> intentHandler.launchUri(event.uri.toUri())
|
||||
|
||||
is VaultItemEvent.NavigateToAttachments -> {
|
||||
// TODO implement attachments in BIT-522
|
||||
Toast.makeText(context, "Not yet implemented.", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
is VaultItemEvent.NavigateToMoveToOrganization -> {
|
||||
// TODO Implement move to organization in BIT-844
|
||||
Toast.makeText(context, "Not yet implemented.", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
is VaultItemEvent.ShowToast -> {
|
||||
Toast.makeText(context, event.message(resources), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
@@ -101,7 +117,43 @@ fun VaultItemScreen(
|
||||
{ viewModel.trySendAction(VaultItemAction.Common.CloseClick) }
|
||||
},
|
||||
actions = {
|
||||
BitwardenOverflowActionItem()
|
||||
// TODO make action list dependent on item being in an organization BIT-1446
|
||||
BitwardenOverflowActionItem(
|
||||
menuItemDataList = persistentListOf(
|
||||
OverflowMenuItemData(
|
||||
text = stringResource(id = R.string.delete),
|
||||
onClick = remember(viewModel) {
|
||||
{ viewModel.trySendAction(VaultItemAction.Common.DeleteClick) }
|
||||
},
|
||||
),
|
||||
OverflowMenuItemData(
|
||||
text = stringResource(id = R.string.attachments),
|
||||
onClick = remember(viewModel) {
|
||||
{
|
||||
viewModel.trySendAction(
|
||||
VaultItemAction.Common.AttachmentsClick,
|
||||
)
|
||||
}
|
||||
},
|
||||
),
|
||||
OverflowMenuItemData(
|
||||
text = stringResource(id = R.string.clone),
|
||||
onClick = remember(viewModel) {
|
||||
{ viewModel.trySendAction(VaultItemAction.Common.CloneClick) }
|
||||
},
|
||||
),
|
||||
OverflowMenuItemData(
|
||||
text = stringResource(id = R.string.move_to_organization),
|
||||
onClick = remember(viewModel) {
|
||||
{
|
||||
viewModel.trySendAction(
|
||||
VaultItemAction.Common.MoveToOrganizationClick,
|
||||
)
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
},
|
||||
)
|
||||
},
|
||||
|
||||
@@ -97,6 +97,11 @@ class VaultItemViewModel @Inject constructor(
|
||||
is VaultItemAction.Common.HiddenFieldVisibilityClicked -> {
|
||||
handleHiddenFieldVisibilityClicked(action)
|
||||
}
|
||||
|
||||
is VaultItemAction.Common.AttachmentsClick -> handleAttachmentsClick()
|
||||
is VaultItemAction.Common.CloneClick -> handleCloneClick()
|
||||
is VaultItemAction.Common.DeleteClick -> handleDeleteClick()
|
||||
is VaultItemAction.Common.MoveToOrganizationClick -> handleMoveToOrganizationClick()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +121,12 @@ class VaultItemViewModel @Inject constructor(
|
||||
}
|
||||
return@onContent
|
||||
}
|
||||
sendEvent(VaultItemEvent.NavigateToEdit(state.vaultItemId))
|
||||
sendEvent(
|
||||
VaultItemEvent.NavigateToAddEdit(
|
||||
itemId = state.vaultItemId,
|
||||
isClone = false,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,6 +202,28 @@ class VaultItemViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleAttachmentsClick() {
|
||||
sendEvent(VaultItemEvent.NavigateToAttachments(itemId = state.vaultItemId))
|
||||
}
|
||||
|
||||
private fun handleCloneClick() {
|
||||
sendEvent(
|
||||
VaultItemEvent.NavigateToAddEdit(
|
||||
itemId = state.vaultItemId,
|
||||
isClone = true,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
private fun handleDeleteClick() {
|
||||
// TODO Implement delete in BIT-1408
|
||||
sendEvent(VaultItemEvent.ShowToast("Not yet implemented.".asText()))
|
||||
}
|
||||
|
||||
private fun handleMoveToOrganizationClick() {
|
||||
sendEvent(VaultItemEvent.NavigateToMoveToOrganization(itemId = state.vaultItemId))
|
||||
}
|
||||
|
||||
//endregion Common Handlers
|
||||
|
||||
//region Login Type Handlers
|
||||
@@ -759,8 +791,9 @@ sealed class VaultItemEvent {
|
||||
/**
|
||||
* Navigates to the edit screen.
|
||||
*/
|
||||
data class NavigateToEdit(
|
||||
data class NavigateToAddEdit(
|
||||
val itemId: String,
|
||||
val isClone: Boolean,
|
||||
) : VaultItemEvent()
|
||||
|
||||
/**
|
||||
@@ -777,6 +810,20 @@ sealed class VaultItemEvent {
|
||||
val uri: String,
|
||||
) : VaultItemEvent()
|
||||
|
||||
/**
|
||||
* Navigates to the attachments screen.
|
||||
*/
|
||||
data class NavigateToAttachments(
|
||||
val itemId: String,
|
||||
) : VaultItemEvent()
|
||||
|
||||
/**
|
||||
* Navigates to the move to organization screen.
|
||||
*/
|
||||
data class NavigateToMoveToOrganization(
|
||||
val itemId: String,
|
||||
) : VaultItemEvent()
|
||||
|
||||
/**
|
||||
* Places the given [message] in your clipboard.
|
||||
*/
|
||||
@@ -844,6 +891,26 @@ sealed class VaultItemAction {
|
||||
val field: VaultItemState.ViewState.Content.Common.Custom.HiddenField,
|
||||
val isVisible: Boolean,
|
||||
) : Common()
|
||||
|
||||
/**
|
||||
* The user has clicked the delete button.
|
||||
*/
|
||||
data object DeleteClick : Common()
|
||||
|
||||
/**
|
||||
* The user has clicked the attachments button.
|
||||
*/
|
||||
data object AttachmentsClick : Common()
|
||||
|
||||
/**
|
||||
* The user has clicked the clone button.
|
||||
*/
|
||||
data object CloneClick : Common()
|
||||
|
||||
/**
|
||||
* The user has clicked the move to organization button.
|
||||
*/
|
||||
data object MoveToOrganizationClick : Common()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user