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 @@ -6,7 +6,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
Expand Down Expand Up @@ -110,10 +110,10 @@ fun LazyListScope.vaultAddEditAdditionalOptions(
}
}

items(
itemsIndexed(
items = commonState.customFieldData,
key = { "customField_${it.itemId}" },
) { customItem ->
key = { _, customItem -> "customField_${customItem.itemId}" },
) { index, customItem ->
Column(
modifier = Modifier
.animateItem()
Expand All @@ -125,6 +125,8 @@ fun LazyListScope.vaultAddEditAdditionalOptions(
customField = customItem,
onCustomFieldValueChange = commonTypeHandlers.onCustomFieldValueChange,
onCustomFieldAction = commonTypeHandlers.onCustomFieldActionSelect,
showMoveUpAction = index > 0,
showMoveDownAction = index < commonState.customFieldData.lastIndex,
onHiddenVisibilityChanged = commonTypeHandlers.onHiddenFieldVisibilityChange,
supportedLinkedTypes = itemType.vaultLinkedFieldTypes,
cardStyle = CardStyle.Full,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import kotlinx.collections.immutable.toImmutableList
* @param customField The field that is to be displayed.
* @param onCustomFieldValueChange Invoked when the user changes the value.
* @param onCustomFieldAction Invoked when the user chooses an action.
* @param showMoveUpAction Whether the [CustomFieldAction.MOVE_UP] is displayed in the action dialog.
* @param showMoveDownAction Whether the [CustomFieldAction.MOVE_DOWN] is displayed in the action dialog.
* @param onHiddenVisibilityChanged Emits when the visibility of a hidden custom field changes.
* @param cardStyle Indicates the type of card style to be applied.
* @param modifier Modifier for the UI elements.
Expand All @@ -45,6 +47,8 @@ fun VaultAddEditCustomField(
customField: VaultAddEditState.Custom,
onCustomFieldValueChange: (VaultAddEditState.Custom) -> Unit,
onCustomFieldAction: (CustomFieldAction, VaultAddEditState.Custom) -> Unit,
showMoveUpAction: Boolean,
showMoveDownAction: Boolean,
onHiddenVisibilityChanged: (Boolean) -> Unit,
cardStyle: CardStyle,
modifier: Modifier = Modifier,
Expand All @@ -55,6 +59,13 @@ fun VaultAddEditCustomField(

if (shouldShowChooserDialog) {
CustomFieldActionDialog(
customFieldActions = CustomFieldAction.entries.filter { action ->
when (action) {
CustomFieldAction.MOVE_UP -> showMoveUpAction
CustomFieldAction.MOVE_DOWN -> showMoveDownAction
else -> true
}
},
onCustomFieldAction = { action ->
shouldShowChooserDialog = false
onCustomFieldAction(action, customField)
Expand Down Expand Up @@ -281,6 +292,7 @@ private fun CustomFieldLinkedField(
*/
@Composable
private fun CustomFieldActionDialog(
customFieldActions: List<CustomFieldAction> = CustomFieldAction.entries,
onCustomFieldAction: (CustomFieldAction) -> Unit,
onEditAction: () -> Unit,
onDismissRequest: () -> Unit,
Expand All @@ -289,20 +301,18 @@ private fun CustomFieldActionDialog(
title = stringResource(id = R.string.options),
onDismissRequest = onDismissRequest,
) {
CustomFieldAction
.entries
.forEach { action ->
BitwardenBasicDialogRow(
text = action.actionText.invoke(),
onClick = {
if (action == CustomFieldAction.EDIT) {
onEditAction()
} else {
onCustomFieldAction(action)
}
},
)
}
customFieldActions.forEach { action ->
BitwardenBasicDialogRow(
text = action.actionText.invoke(),
onClick = {
if (action == CustomFieldAction.EDIT) {
onEditAction()
} else {
onCustomFieldAction(action)
}
},
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,9 +854,6 @@ class VaultAddEditViewModel @Inject constructor(
.toMutableList()

val index = items.lastIndexOf(action.customField)
if (index == 0) {
return
}

Collections.swap(items, index, index - 1)

Expand All @@ -875,9 +872,6 @@ class VaultAddEditViewModel @Inject constructor(
.toMutableList()

val index = items.indexOf(action.customField)
if (index == items.lastIndex) {
return
}

Collections.swap(items, index, index + 1)

Expand Down
Loading