Rename additem to addedit (#474)

This commit is contained in:
David Perez 2024-01-03 09:06:04 -06:00 committed by Álison Fernandes
parent a6b2357fb0
commit 4601f84140
23 changed files with 804 additions and 820 deletions

View file

@ -14,8 +14,8 @@ import com.x8bit.bitwarden.ui.tools.feature.generator.passwordhistory.navigateTo
import com.x8bit.bitwarden.ui.tools.feature.generator.passwordhistory.passwordHistoryDestination
import com.x8bit.bitwarden.ui.tools.feature.send.addsend.addSendDestination
import com.x8bit.bitwarden.ui.tools.feature.send.addsend.navigateToAddSend
import com.x8bit.bitwarden.ui.vault.feature.additem.navigateToVaultAddEditItem
import com.x8bit.bitwarden.ui.vault.feature.additem.vaultAddEditItemDestination
import com.x8bit.bitwarden.ui.vault.feature.addedit.navigateToVaultAddEdit
import com.x8bit.bitwarden.ui.vault.feature.addedit.vaultAddEditDestination
import com.x8bit.bitwarden.ui.vault.feature.item.navigateToVaultItem
import com.x8bit.bitwarden.ui.vault.feature.item.vaultItemDestination
import com.x8bit.bitwarden.ui.vault.feature.qrcodescan.navigateToQrCodeScanScreen
@ -44,18 +44,18 @@ fun NavGraphBuilder.vaultUnlockedGraph(
vaultUnlockedNavBarDestination(
onNavigateToFolders = { navController.navigateToFolders() },
onNavigateToVaultAddItem = {
navController.navigateToVaultAddEditItem(VaultAddEditType.AddItem)
navController.navigateToVaultAddEdit(VaultAddEditType.AddItem)
},
onNavigateToVaultItem = { navController.navigateToVaultItem(it) },
onNavigateToVaultEditItem = {
navController.navigateToVaultAddEditItem(VaultAddEditType.EditItem(it))
navController.navigateToVaultAddEdit(VaultAddEditType.EditItem(it))
},
onNavigateToAddSend = { navController.navigateToAddSend() },
onNavigateToDeleteAccount = { navController.navigateToDeleteAccount() },
onNavigateToPasswordHistory = { navController.navigateToPasswordHistory() },
)
deleteAccountDestination(onNavigateBack = { navController.popBackStack() })
vaultAddEditItemDestination(
vaultAddEditDestination(
onNavigateToQrCodeScanScreen = {
navController.navigateToQrCodeScanScreen()
},
@ -64,7 +64,7 @@ fun NavGraphBuilder.vaultUnlockedGraph(
vaultItemDestination(
onNavigateBack = { navController.popBackStack() },
onNavigateToVaultEditItem = {
navController.navigateToVaultAddEditItem(VaultAddEditType.EditItem(it))
navController.navigateToVaultAddEdit(VaultAddEditType.EditItem(it))
},
)
vaultQrCodeScanDestination(onNavigateBack = { navController.popBackStack() })

View file

@ -1,4 +1,4 @@
package com.x8bit.bitwarden.ui.vault.feature.additem
package com.x8bit.bitwarden.ui.vault.feature.addedit
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
@ -33,14 +33,14 @@ import kotlinx.collections.immutable.toImmutableList
*/
@Composable
@Suppress("LongMethod")
fun AddEditCustomField(
customField: VaultAddItemState.Custom,
onCustomFieldValueChange: (VaultAddItemState.Custom) -> Unit,
fun VaultAddEditCustomField(
customField: VaultAddEditState.Custom,
onCustomFieldValueChange: (VaultAddEditState.Custom) -> Unit,
modifier: Modifier = Modifier,
supportedLinkedTypes: ImmutableList<VaultLinkedFieldType> = persistentListOf(),
) {
when (customField) {
is VaultAddItemState.Custom.BooleanField -> {
is VaultAddEditState.Custom.BooleanField -> {
CustomFieldBoolean(
label = customField.name,
value = customField.value,
@ -49,7 +49,7 @@ fun AddEditCustomField(
)
}
is VaultAddItemState.Custom.HiddenField -> {
is VaultAddEditState.Custom.HiddenField -> {
CustomFieldHiddenField(
customField.name,
customField.value,
@ -60,7 +60,7 @@ fun AddEditCustomField(
)
}
is VaultAddItemState.Custom.LinkedField -> {
is VaultAddEditState.Custom.LinkedField -> {
CustomFieldLinkedField(
selectedOption = customField.vaultLinkedFieldType,
supportedLinkedTypes = supportedLinkedTypes,
@ -71,7 +71,7 @@ fun AddEditCustomField(
)
}
is VaultAddItemState.Custom.TextField -> {
is VaultAddEditState.Custom.TextField -> {
CustomFieldTextField(
label = customField.name,
value = customField.value,

View file

@ -1,4 +1,4 @@
package com.x8bit.bitwarden.ui.vault.feature.additem
package com.x8bit.bitwarden.ui.vault.feature.addedit
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
@ -12,7 +12,7 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenBasicDialogRow
import com.x8bit.bitwarden.ui.platform.components.BitwardenFilledTonalButton
import com.x8bit.bitwarden.ui.platform.components.BitwardenSelectionDialog
import com.x8bit.bitwarden.ui.platform.components.BitwardenTextEntryDialog
import com.x8bit.bitwarden.ui.vault.feature.additem.model.CustomFieldType
import com.x8bit.bitwarden.ui.vault.feature.addedit.model.CustomFieldType
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
@ -24,7 +24,7 @@ import kotlinx.collections.immutable.persistentListOf
*/
@Suppress("LongMethod")
@Composable
fun AddEditCustomFieldsButton(
fun VaultAddEditCustomFieldsButton(
onFinishNamingClick: (CustomFieldType, String) -> Unit,
modifier: Modifier = Modifier,
options: ImmutableList<CustomFieldType> = persistentListOf(

View file

@ -1,4 +1,4 @@
package com.x8bit.bitwarden.ui.vault.feature.additem
package com.x8bit.bitwarden.ui.vault.feature.addedit
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
@ -15,11 +15,11 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
/**
* The top level error UI state for the [VaultAddItemScreen].
* The top level error UI state for the [VaultAddEditScreen].
*/
@Composable
fun VaultAddEditError(
viewState: VaultAddItemState.ViewState.Error,
viewState: VaultAddEditState.ViewState.Error,
modifier: Modifier = Modifier,
) {
Column(

View file

@ -1,4 +1,4 @@
package com.x8bit.bitwarden.ui.vault.feature.additem
package com.x8bit.bitwarden.ui.vault.feature.addedit
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
@ -21,8 +21,8 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenMultiSelectButton
import com.x8bit.bitwarden.ui.platform.components.BitwardenSwitch
import com.x8bit.bitwarden.ui.platform.components.BitwardenSwitchWithActions
import com.x8bit.bitwarden.ui.platform.components.BitwardenTextField
import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddIdentityItemTypeHandlers
import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddItemCommonHandlers
import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditCommonHandlers
import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditIdentityTypeHandlers
import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
@ -31,12 +31,12 @@ import kotlinx.collections.immutable.toImmutableList
* The UI for adding and editing an identity cipher.
*/
@Suppress("LongMethod")
fun LazyListScope.addEditIdentityItems(
commonState: VaultAddItemState.ViewState.Content.Common,
identityState: VaultAddItemState.ViewState.Content.ItemType.Identity,
fun LazyListScope.vaultAddEditIdentityItems(
commonState: VaultAddEditState.ViewState.Content.Common,
identityState: VaultAddEditState.ViewState.Content.ItemType.Identity,
isAddItemMode: Boolean,
commonTypeHandlers: VaultAddItemCommonHandlers,
identityItemTypeHandlers: VaultAddIdentityItemTypeHandlers,
commonTypeHandlers: VaultAddEditCommonHandlers,
identityItemTypeHandlers: VaultAddEditIdentityTypeHandlers,
) {
item {
Spacer(modifier = Modifier.height(8.dp))
@ -337,7 +337,7 @@ fun LazyListScope.addEditIdentityItems(
}
items(commonState.customFieldData) { customItem ->
AddEditCustomField(
VaultAddEditCustomField(
customItem,
onCustomFieldValueChange = commonTypeHandlers.onCustomFieldValueChange,
modifier = Modifier
@ -352,7 +352,7 @@ fun LazyListScope.addEditIdentityItems(
item {
Spacer(modifier = Modifier.height(16.dp))
AddEditCustomFieldsButton(
VaultAddEditCustomFieldsButton(
onFinishNamingClick = commonTypeHandlers.onAddNewCustomFieldClick,
modifier = Modifier
.fillMaxWidth()
@ -391,21 +391,21 @@ fun LazyListScope.addEditIdentityItems(
@Composable
private fun TitleMultiSelectButton(
selectedTitle: VaultAddItemState.ViewState.Content.ItemType.Identity.Title,
onTitleSelected: (VaultAddItemState.ViewState.Content.ItemType.Identity.Title) -> Unit,
selectedTitle: VaultAddEditState.ViewState.Content.ItemType.Identity.Title,
onTitleSelected: (VaultAddEditState.ViewState.Content.ItemType.Identity.Title) -> Unit,
modifier: Modifier = Modifier,
) {
val resources = LocalContext.current.resources
BitwardenMultiSelectButton(
label = stringResource(id = R.string.title),
options = VaultAddItemState.ViewState.Content.ItemType.Identity.Title
options = VaultAddEditState.ViewState.Content.ItemType.Identity.Title
.entries
.map { it.value() }
.toImmutableList(),
selectedOption = selectedTitle.value(),
onOptionSelected = { selectedString ->
onTitleSelected(
VaultAddItemState.ViewState.Content.ItemType.Identity.Title
VaultAddEditState.ViewState.Content.ItemType.Identity.Title
.entries
.first { it.value.toString(resources) == selectedString },
)

View file

@ -1,4 +1,4 @@
package com.x8bit.bitwarden.ui.vault.feature.additem
package com.x8bit.bitwarden.ui.vault.feature.addedit
import android.Manifest
import androidx.compose.foundation.layout.Spacer
@ -15,35 +15,35 @@ import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.ui.platform.base.util.PermissionsManager
import com.x8bit.bitwarden.ui.platform.components.BitwardenListHeaderText
import com.x8bit.bitwarden.ui.platform.components.BitwardenMultiSelectButton
import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddIdentityItemTypeHandlers
import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddItemCommonHandlers
import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddLoginItemTypeHandlers
import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditCommonHandlers
import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditIdentityTypeHandlers
import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditLoginTypeHandlers
import kotlinx.collections.immutable.toImmutableList
/**
* The top level content UI state for the [VaultAddItemScreen].
* The top level content UI state for the [VaultAddEditScreen].
*/
@Composable
@Suppress("LongMethod")
fun AddEditItemContent(
state: VaultAddItemState.ViewState.Content,
fun VaultAddEditContent(
state: VaultAddEditState.ViewState.Content,
isAddItemMode: Boolean,
onTypeOptionClicked: (VaultAddItemState.ItemTypeOption) -> Unit,
commonTypeHandlers: VaultAddItemCommonHandlers,
loginItemTypeHandlers: VaultAddLoginItemTypeHandlers,
identityItemTypeHandlers: VaultAddIdentityItemTypeHandlers,
onTypeOptionClicked: (VaultAddEditState.ItemTypeOption) -> Unit,
commonTypeHandlers: VaultAddEditCommonHandlers,
loginItemTypeHandlers: VaultAddEditLoginTypeHandlers,
identityItemTypeHandlers: VaultAddEditIdentityTypeHandlers,
modifier: Modifier = Modifier,
permissionsManager: PermissionsManager,
) {
val launcher = permissionsManager.getLauncher(
onResult = { isGranted ->
when (state.type) {
is VaultAddItemState.ViewState.Content.ItemType.SecureNotes -> Unit
is VaultAddEditState.ViewState.Content.ItemType.SecureNotes -> Unit
// TODO: Create UI for card-type item creation BIT-507
is VaultAddItemState.ViewState.Content.ItemType.Card -> Unit
is VaultAddEditState.ViewState.Content.ItemType.Card -> Unit
// TODO: Create UI for identity-type item creation BIT-667
is VaultAddItemState.ViewState.Content.ItemType.Identity -> Unit
is VaultAddItemState.ViewState.Content.ItemType.Login -> {
is VaultAddEditState.ViewState.Content.ItemType.Identity -> Unit
is VaultAddEditState.ViewState.Content.ItemType.Login -> {
loginItemTypeHandlers.onSetupTotpClick(isGranted)
}
}
@ -73,8 +73,8 @@ fun AddEditItemContent(
}
when (state.type) {
is VaultAddItemState.ViewState.Content.ItemType.Login -> {
addEditLoginItems(
is VaultAddEditState.ViewState.Content.ItemType.Login -> {
vaultAddEditLoginItems(
commonState = state.common,
loginState = state.type,
isAddItemMode = isAddItemMode,
@ -90,12 +90,12 @@ fun AddEditItemContent(
)
}
is VaultAddItemState.ViewState.Content.ItemType.Card -> {
is VaultAddEditState.ViewState.Content.ItemType.Card -> {
// TODO(BIT-507): Create UI for card-type item creation
}
is VaultAddItemState.ViewState.Content.ItemType.Identity -> {
addEditIdentityItems(
is VaultAddEditState.ViewState.Content.ItemType.Identity -> {
vaultAddEditIdentityItems(
commonState = state.common,
identityState = state.type,
isAddItemMode = isAddItemMode,
@ -104,8 +104,8 @@ fun AddEditItemContent(
)
}
is VaultAddItemState.ViewState.Content.ItemType.SecureNotes -> {
addEditSecureNotesItems(
is VaultAddEditState.ViewState.Content.ItemType.SecureNotes -> {
vaultAddEditSecureNotesItems(
commonState = state.common,
isAddItemMode = isAddItemMode,
commonTypeHandlers = commonTypeHandlers,
@ -121,11 +121,11 @@ fun AddEditItemContent(
@Composable
private fun TypeOptionsItem(
itemType: VaultAddItemState.ViewState.Content.ItemType,
onTypeOptionClicked: (VaultAddItemState.ItemTypeOption) -> Unit,
itemType: VaultAddEditState.ViewState.Content.ItemType,
onTypeOptionClicked: (VaultAddEditState.ItemTypeOption) -> Unit,
modifier: Modifier,
) {
val possibleMainStates = VaultAddItemState.ItemTypeOption.entries.toList()
val possibleMainStates = VaultAddEditState.ItemTypeOption.entries.toList()
val optionsWithStrings = possibleMainStates.associateWith { stringResource(id = it.labelRes) }
BitwardenMultiSelectButton(

View file

@ -1,4 +1,4 @@
package com.x8bit.bitwarden.ui.vault.feature.additem
package com.x8bit.bitwarden.ui.vault.feature.addedit
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
@ -10,10 +10,10 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
/**
* The top level loading UI state for the [VaultAddItemScreen].
* The top level loading UI state for the [VaultAddEditScreen].
*/
@Composable
fun VaultAddEditItemLoading(
fun VaultAddEditLoading(
modifier: Modifier = Modifier,
) {
Column(

View file

@ -1,4 +1,4 @@
package com.x8bit.bitwarden.ui.vault.feature.additem
package com.x8bit.bitwarden.ui.vault.feature.addedit
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
@ -25,8 +25,8 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenSwitchWithActions
import com.x8bit.bitwarden.ui.platform.components.BitwardenTextField
import com.x8bit.bitwarden.ui.platform.components.BitwardenTextFieldWithActions
import com.x8bit.bitwarden.ui.platform.components.model.IconResource
import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddItemCommonHandlers
import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddLoginItemTypeHandlers
import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditCommonHandlers
import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditLoginTypeHandlers
import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
@ -35,12 +35,12 @@ import kotlinx.collections.immutable.toImmutableList
* The UI for adding and editing a login cipher.
*/
@Suppress("LongMethod", "LongParameterList")
fun LazyListScope.addEditLoginItems(
commonState: VaultAddItemState.ViewState.Content.Common,
loginState: VaultAddItemState.ViewState.Content.ItemType.Login,
fun LazyListScope.vaultAddEditLoginItems(
commonState: VaultAddEditState.ViewState.Content.Common,
loginState: VaultAddEditState.ViewState.Content.ItemType.Login,
isAddItemMode: Boolean,
commonActionHandler: VaultAddItemCommonHandlers,
loginItemTypeHandlers: VaultAddLoginItemTypeHandlers,
commonActionHandler: VaultAddEditCommonHandlers,
loginItemTypeHandlers: VaultAddEditLoginTypeHandlers,
onTotpSetupClick: () -> Unit,
) {
item {
@ -287,7 +287,7 @@ fun LazyListScope.addEditLoginItems(
}
items(commonState.customFieldData) { customItem ->
AddEditCustomField(
VaultAddEditCustomField(
customItem,
onCustomFieldValueChange = commonActionHandler.onCustomFieldValueChange,
modifier = Modifier
@ -302,7 +302,7 @@ fun LazyListScope.addEditLoginItems(
item {
Spacer(modifier = Modifier.height(16.dp))
AddEditCustomFieldsButton(
VaultAddEditCustomFieldsButton(
onFinishNamingClick = commonActionHandler.onAddNewCustomFieldClick,
modifier = Modifier
.fillMaxWidth()

View file

@ -1,4 +1,4 @@
package com.x8bit.bitwarden.ui.vault.feature.additem
package com.x8bit.bitwarden.ui.vault.feature.addedit
import androidx.lifecycle.SavedStateHandle
import androidx.navigation.NavController
@ -24,7 +24,7 @@ private const val ADD_EDIT_ITEM_ROUTE: String =
* Class to retrieve vault add & edit arguments from the [SavedStateHandle].
*/
@OmitFromCoverage
data class VaultAddEditItemArgs(
data class VaultAddEditArgs(
val vaultAddEditType: VaultAddEditType,
) {
constructor(savedStateHandle: SavedStateHandle) : this(
@ -37,9 +37,9 @@ data class VaultAddEditItemArgs(
}
/**
* Add the vault add & edit item screen to the nav graph.
* Add the vault add & edit screen to the nav graph.
*/
fun NavGraphBuilder.vaultAddEditItemDestination(
fun NavGraphBuilder.vaultAddEditDestination(
onNavigateToQrCodeScanScreen: () -> Unit,
onNavigateBack: () -> Unit,
) {
@ -49,14 +49,14 @@ fun NavGraphBuilder.vaultAddEditItemDestination(
navArgument(ADD_EDIT_ITEM_TYPE) { type = NavType.StringType },
),
) {
VaultAddItemScreen(onNavigateBack, onNavigateToQrCodeScanScreen)
VaultAddEditScreen(onNavigateBack, onNavigateToQrCodeScanScreen)
}
}
/**
* Navigate to the vault add & edit item screen.
* Navigate to the vault add & edit screen.
*/
fun NavController.navigateToVaultAddEditItem(
fun NavController.navigateToVaultAddEdit(
vaultAddEditType: VaultAddEditType,
navOptions: NavOptions? = null,
) {

View file

@ -1,4 +1,4 @@
package com.x8bit.bitwarden.ui.vault.feature.additem
package com.x8bit.bitwarden.ui.vault.feature.addedit
import android.app.Activity
import android.widget.Toast
@ -33,9 +33,9 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenScaffold
import com.x8bit.bitwarden.ui.platform.components.BitwardenTextButton
import com.x8bit.bitwarden.ui.platform.components.BitwardenTopAppBar
import com.x8bit.bitwarden.ui.platform.components.LoadingDialogState
import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddIdentityItemTypeHandlers
import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddItemCommonHandlers
import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddLoginItemTypeHandlers
import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditCommonHandlers
import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditIdentityTypeHandlers
import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditLoginTypeHandlers
/**
* Top level composable for the vault add item screen.
@ -43,10 +43,10 @@ import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddLoginItemTy
@OptIn(ExperimentalMaterial3Api::class)
@Suppress("LongMethod")
@Composable
fun VaultAddItemScreen(
fun VaultAddEditScreen(
onNavigateBack: () -> Unit,
onNavigateToQrCodeScanScreen: () -> Unit,
viewModel: VaultAddItemViewModel = hiltViewModel(),
viewModel: VaultAddEditViewModel = hiltViewModel(),
clipboardManager: ClipboardManager = LocalClipboardManager.current,
permissionsManager: PermissionsManager =
PermissionsManagerImpl(LocalContext.current as Activity),
@ -57,38 +57,38 @@ fun VaultAddItemScreen(
EventsEffect(viewModel = viewModel) { event ->
when (event) {
is VaultAddItemEvent.NavigateToQrCodeScan -> {
is VaultAddEditEvent.NavigateToQrCodeScan -> {
onNavigateToQrCodeScanScreen()
}
is VaultAddItemEvent.ShowToast -> {
is VaultAddEditEvent.ShowToast -> {
Toast.makeText(context, event.message(resources), Toast.LENGTH_SHORT).show()
}
is VaultAddItemEvent.CopyToClipboard -> {
is VaultAddEditEvent.CopyToClipboard -> {
clipboardManager.setText(event.text.toAnnotatedString())
}
VaultAddItemEvent.NavigateBack -> onNavigateBack.invoke()
VaultAddEditEvent.NavigateBack -> onNavigateBack.invoke()
}
}
val loginItemTypeHandlers = remember(viewModel) {
VaultAddLoginItemTypeHandlers.create(viewModel = viewModel)
VaultAddEditLoginTypeHandlers.create(viewModel = viewModel)
}
val commonTypeHandlers = remember(viewModel) {
VaultAddItemCommonHandlers.create(viewModel = viewModel)
VaultAddEditCommonHandlers.create(viewModel = viewModel)
}
val identityItemTypeHandlers = remember(viewModel) {
VaultAddIdentityItemTypeHandlers.create(viewModel = viewModel)
VaultAddEditIdentityTypeHandlers.create(viewModel = viewModel)
}
VaultAddEditItemDialogs(
dialogState = state.dialog,
onDismissRequest = remember(viewModel) {
{ viewModel.trySendAction(VaultAddItemAction.Common.DismissDialog) }
{ viewModel.trySendAction(VaultAddEditAction.Common.DismissDialog) }
},
)
@ -103,14 +103,14 @@ fun VaultAddItemScreen(
navigationIcon = painterResource(id = R.drawable.ic_close),
navigationIconContentDescription = stringResource(id = R.string.close),
onNavigationIconClick = remember(viewModel) {
{ viewModel.trySendAction(VaultAddItemAction.Common.CloseClick) }
{ viewModel.trySendAction(VaultAddEditAction.Common.CloseClick) }
},
scrollBehavior = scrollBehavior,
actions = {
BitwardenTextButton(
label = stringResource(id = R.string.save),
onClick = remember(viewModel) {
{ viewModel.trySendAction(VaultAddItemAction.Common.SaveClick) }
{ viewModel.trySendAction(VaultAddEditAction.Common.SaveClick) }
},
)
},
@ -118,12 +118,12 @@ fun VaultAddItemScreen(
},
) { innerPadding ->
when (val viewState = state.viewState) {
is VaultAddItemState.ViewState.Content -> {
AddEditItemContent(
is VaultAddEditState.ViewState.Content -> {
VaultAddEditContent(
state = viewState,
isAddItemMode = state.isAddItemMode,
onTypeOptionClicked = remember(viewModel) {
{ viewModel.trySendAction(VaultAddItemAction.Common.TypeOptionSelect(it)) }
{ viewModel.trySendAction(VaultAddEditAction.Common.TypeOptionSelect(it)) }
},
loginItemTypeHandlers = loginItemTypeHandlers,
commonTypeHandlers = commonTypeHandlers,
@ -136,7 +136,7 @@ fun VaultAddItemScreen(
)
}
is VaultAddItemState.ViewState.Error -> {
is VaultAddEditState.ViewState.Error -> {
VaultAddEditError(
viewState = viewState,
modifier = Modifier
@ -145,8 +145,8 @@ fun VaultAddItemScreen(
)
}
VaultAddItemState.ViewState.Loading -> {
VaultAddEditItemLoading(
VaultAddEditState.ViewState.Loading -> {
VaultAddEditLoading(
modifier = Modifier
.padding(innerPadding)
.fillMaxSize(),
@ -158,17 +158,17 @@ fun VaultAddItemScreen(
@Composable
private fun VaultAddEditItemDialogs(
dialogState: VaultAddItemState.DialogState?,
dialogState: VaultAddEditState.DialogState?,
onDismissRequest: () -> Unit,
) {
when (dialogState) {
is VaultAddItemState.DialogState.Loading -> {
is VaultAddEditState.DialogState.Loading -> {
BitwardenLoadingDialog(
visibilityState = LoadingDialogState.Shown(dialogState.label),
)
}
is VaultAddItemState.DialogState.Error -> BitwardenBasicDialog(
is VaultAddEditState.DialogState.Error -> BitwardenBasicDialog(
visibilityState = BasicDialogState.Shown(
title = R.string.an_error_has_occurred.asText(),
message = dialogState.message,

View file

@ -1,4 +1,4 @@
package com.x8bit.bitwarden.ui.vault.feature.additem
package com.x8bit.bitwarden.ui.vault.feature.addedit
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
@ -19,8 +19,8 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenMultiSelectButton
import com.x8bit.bitwarden.ui.platform.components.BitwardenSwitch
import com.x8bit.bitwarden.ui.platform.components.BitwardenSwitchWithActions
import com.x8bit.bitwarden.ui.platform.components.BitwardenTextField
import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddItemCommonHandlers
import com.x8bit.bitwarden.ui.vault.feature.additem.model.CustomFieldType
import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditCommonHandlers
import com.x8bit.bitwarden.ui.vault.feature.addedit.model.CustomFieldType
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
@ -28,10 +28,10 @@ import kotlinx.collections.immutable.toImmutableList
* The UI for adding and editing a secure notes cipher.
*/
@Suppress("LongMethod")
fun LazyListScope.addEditSecureNotesItems(
commonState: VaultAddItemState.ViewState.Content.Common,
fun LazyListScope.vaultAddEditSecureNotesItems(
commonState: VaultAddEditState.ViewState.Content.Common,
isAddItemMode: Boolean,
commonTypeHandlers: VaultAddItemCommonHandlers,
commonTypeHandlers: VaultAddEditCommonHandlers,
) {
item {
Spacer(modifier = Modifier.height(8.dp))
@ -135,7 +135,7 @@ fun LazyListScope.addEditSecureNotesItems(
)
}
items(commonState.customFieldData) { customItem ->
AddEditCustomField(
VaultAddEditCustomField(
customItem,
onCustomFieldValueChange = commonTypeHandlers.onCustomFieldValueChange,
modifier = Modifier
@ -146,7 +146,7 @@ fun LazyListScope.addEditSecureNotesItems(
item {
Spacer(modifier = Modifier.height(16.dp))
AddEditCustomFieldsButton(
VaultAddEditCustomFieldsButton(
onFinishNamingClick = commonTypeHandlers.onAddNewCustomFieldClick,
options = persistentListOf(
CustomFieldType.TEXT,

View file

@ -1,4 +1,4 @@
package com.x8bit.bitwarden.ui.vault.feature.additem
package com.x8bit.bitwarden.ui.vault.feature.addedit
import android.os.Parcelable
import androidx.lifecycle.SavedStateHandle
@ -14,9 +14,9 @@ import com.x8bit.bitwarden.ui.platform.base.BaseViewModel
import com.x8bit.bitwarden.ui.platform.base.util.Text
import com.x8bit.bitwarden.ui.platform.base.util.asText
import com.x8bit.bitwarden.ui.platform.base.util.concat
import com.x8bit.bitwarden.ui.vault.feature.additem.model.CustomFieldType
import com.x8bit.bitwarden.ui.vault.feature.additem.model.toCustomField
import com.x8bit.bitwarden.ui.vault.feature.additem.util.toViewState
import com.x8bit.bitwarden.ui.vault.feature.addedit.model.CustomFieldType
import com.x8bit.bitwarden.ui.vault.feature.addedit.model.toCustomField
import com.x8bit.bitwarden.ui.vault.feature.addedit.util.toViewState
import com.x8bit.bitwarden.ui.vault.feature.vault.util.toCipherView
import com.x8bit.bitwarden.ui.vault.model.VaultAddEditType
import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType
@ -43,23 +43,23 @@ private const val KEY_STATE = "state"
*/
@HiltViewModel
@Suppress("TooManyFunctions", "LargeClass")
class VaultAddItemViewModel @Inject constructor(
class VaultAddEditViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
private val vaultRepository: VaultRepository,
) : BaseViewModel<VaultAddItemState, VaultAddItemEvent, VaultAddItemAction>(
) : BaseViewModel<VaultAddEditState, VaultAddEditEvent, VaultAddEditAction>(
// We load the state from the savedStateHandle for testing purposes.
initialState = savedStateHandle[KEY_STATE]
?: run {
val vaultAddEditType = VaultAddEditItemArgs(savedStateHandle).vaultAddEditType
VaultAddItemState(
val vaultAddEditType = VaultAddEditArgs(savedStateHandle).vaultAddEditType
VaultAddEditState(
vaultAddEditType = vaultAddEditType,
viewState = when (vaultAddEditType) {
VaultAddEditType.AddItem -> VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(),
type = VaultAddItemState.ViewState.Content.ItemType.Login(),
VaultAddEditType.AddItem -> VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(),
type = VaultAddEditState.ViewState.Content.ItemType.Login(),
)
is VaultAddEditType.EditItem -> VaultAddItemState.ViewState.Loading
is VaultAddEditType.EditItem -> VaultAddEditState.ViewState.Loading
},
dialog = null,
)
@ -76,7 +76,7 @@ class VaultAddItemViewModel @Inject constructor(
.getVaultItemStateFlow(vaultAddEditType.vaultItemId)
// We'll stop getting updates as soon as we get some loaded data.
.takeUntilLoaded()
.map { VaultAddItemAction.Internal.VaultDataReceive(it) }
.map { VaultAddEditAction.Internal.VaultDataReceive(it) }
.onEach(::sendAction)
.launchIn(viewModelScope)
}
@ -84,17 +84,17 @@ class VaultAddItemViewModel @Inject constructor(
vaultRepository
.totpCodeFlow
.map { VaultAddItemAction.Internal.TotpCodeReceive(totpCode = it) }
.map { VaultAddEditAction.Internal.TotpCodeReceive(totpCode = it) }
.onEach(::sendAction)
.launchIn(viewModelScope)
}
override fun handleAction(action: VaultAddItemAction) {
override fun handleAction(action: VaultAddEditAction) {
when (action) {
is VaultAddItemAction.Common -> handleCommonActions(action)
is VaultAddItemAction.ItemType.LoginType -> handleAddLoginTypeAction(action)
is VaultAddItemAction.ItemType.IdentityType -> handleIdentityTypeActions(action)
is VaultAddItemAction.Internal -> handleInternalActions(action)
is VaultAddEditAction.Common -> handleCommonActions(action)
is VaultAddEditAction.ItemType.LoginType -> handleAddLoginTypeAction(action)
is VaultAddEditAction.ItemType.IdentityType -> handleIdentityTypeActions(action)
is VaultAddEditAction.Internal -> handleInternalActions(action)
}
}
@ -102,46 +102,46 @@ class VaultAddItemViewModel @Inject constructor(
//region Common Handlers
private fun handleCommonActions(action: VaultAddItemAction.Common) {
private fun handleCommonActions(action: VaultAddEditAction.Common) {
when (action) {
is VaultAddItemAction.Common.CustomFieldValueChange -> handleCustomFieldValueChange(
is VaultAddEditAction.Common.CustomFieldValueChange -> handleCustomFieldValueChange(
action,
)
is VaultAddItemAction.Common.FolderChange -> handleFolderTextInputChange(action)
is VaultAddItemAction.Common.NameTextChange -> handleNameTextInputChange(action)
is VaultAddItemAction.Common.NotesTextChange -> handleNotesTextInputChange(action)
is VaultAddItemAction.Common.OwnershipChange -> handleOwnershipTextInputChange(action)
is VaultAddItemAction.Common.ToggleFavorite -> handleToggleFavorite(action)
is VaultAddItemAction.Common.ToggleMasterPasswordReprompt -> {
is VaultAddEditAction.Common.FolderChange -> handleFolderTextInputChange(action)
is VaultAddEditAction.Common.NameTextChange -> handleNameTextInputChange(action)
is VaultAddEditAction.Common.NotesTextChange -> handleNotesTextInputChange(action)
is VaultAddEditAction.Common.OwnershipChange -> handleOwnershipTextInputChange(action)
is VaultAddEditAction.Common.ToggleFavorite -> handleToggleFavorite(action)
is VaultAddEditAction.Common.ToggleMasterPasswordReprompt -> {
handleToggleMasterPasswordReprompt(action)
}
is VaultAddItemAction.Common.CloseClick -> handleCloseClick()
is VaultAddItemAction.Common.DismissDialog -> handleDismissDialog()
is VaultAddItemAction.Common.SaveClick -> handleSaveClick()
is VaultAddItemAction.Common.TypeOptionSelect -> handleTypeOptionSelect(action)
is VaultAddItemAction.Common.AddNewCustomFieldClick -> handleAddNewCustomFieldClick(
is VaultAddEditAction.Common.CloseClick -> handleCloseClick()
is VaultAddEditAction.Common.DismissDialog -> handleDismissDialog()
is VaultAddEditAction.Common.SaveClick -> handleSaveClick()
is VaultAddEditAction.Common.TypeOptionSelect -> handleTypeOptionSelect(action)
is VaultAddEditAction.Common.AddNewCustomFieldClick -> handleAddNewCustomFieldClick(
action,
)
is VaultAddItemAction.Common.TooltipClick -> handleTooltipClick()
is VaultAddEditAction.Common.TooltipClick -> handleTooltipClick()
}
}
private fun handleTypeOptionSelect(action: VaultAddItemAction.Common.TypeOptionSelect) {
private fun handleTypeOptionSelect(action: VaultAddEditAction.Common.TypeOptionSelect) {
when (action.typeOption) {
VaultAddItemState.ItemTypeOption.LOGIN -> handleSwitchToAddLoginItem()
VaultAddItemState.ItemTypeOption.CARD -> handleSwitchToAddCardItem()
VaultAddItemState.ItemTypeOption.IDENTITY -> handleSwitchToAddIdentityItem()
VaultAddItemState.ItemTypeOption.SECURE_NOTES -> handleSwitchToAddSecureNotesItem()
VaultAddEditState.ItemTypeOption.LOGIN -> handleSwitchToAddLoginItem()
VaultAddEditState.ItemTypeOption.CARD -> handleSwitchToAddCardItem()
VaultAddEditState.ItemTypeOption.IDENTITY -> handleSwitchToAddIdentityItem()
VaultAddEditState.ItemTypeOption.SECURE_NOTES -> handleSwitchToAddSecureNotesItem()
}
}
private fun handleSwitchToAddLoginItem() {
updateContent { currentContent ->
currentContent.copy(
type = VaultAddItemState.ViewState.Content.ItemType.Login(),
type = VaultAddEditState.ViewState.Content.ItemType.Login(),
)
}
}
@ -149,7 +149,7 @@ class VaultAddItemViewModel @Inject constructor(
private fun handleSwitchToAddSecureNotesItem() {
updateContent { currentContent ->
currentContent.copy(
type = VaultAddItemState.ViewState.Content.ItemType.SecureNotes,
type = VaultAddEditState.ViewState.Content.ItemType.SecureNotes,
)
}
}
@ -157,7 +157,7 @@ class VaultAddItemViewModel @Inject constructor(
private fun handleSwitchToAddCardItem() {
updateContent { currentContent ->
currentContent.copy(
type = VaultAddItemState.ViewState.Content.ItemType.Card,
type = VaultAddEditState.ViewState.Content.ItemType.Card,
)
}
}
@ -165,7 +165,7 @@ class VaultAddItemViewModel @Inject constructor(
private fun handleSwitchToAddIdentityItem() {
updateContent { currentContent ->
currentContent.copy(
type = VaultAddItemState.ViewState.Content.ItemType.Identity(),
type = VaultAddEditState.ViewState.Content.ItemType.Identity(),
)
}
}
@ -174,7 +174,7 @@ class VaultAddItemViewModel @Inject constructor(
if (content.common.name.isBlank()) {
mutableStateFlow.update {
it.copy(
dialog = VaultAddItemState.DialogState.Error(
dialog = VaultAddEditState.DialogState.Error(
R.string.validation_field_required
.asText(R.string.name.asText()),
),
@ -185,7 +185,7 @@ class VaultAddItemViewModel @Inject constructor(
mutableStateFlow.update {
it.copy(
dialog = VaultAddItemState.DialogState.Loading(
dialog = VaultAddEditState.DialogState.Loading(
R.string.saving.asText(),
),
)
@ -195,7 +195,7 @@ class VaultAddItemViewModel @Inject constructor(
when (val vaultAddEditType = state.vaultAddEditType) {
VaultAddEditType.AddItem -> {
val result = vaultRepository.createCipher(cipherView = content.toCipherView())
sendAction(VaultAddItemAction.Internal.CreateCipherResultReceive(result))
sendAction(VaultAddEditAction.Internal.CreateCipherResultReceive(result))
}
is VaultAddEditType.EditItem -> {
@ -203,7 +203,7 @@ class VaultAddItemViewModel @Inject constructor(
cipherId = vaultAddEditType.vaultItemId,
cipherView = content.toCipherView(),
)
sendAction(VaultAddItemAction.Internal.UpdateCipherResultReceive(result))
sendAction(VaultAddEditAction.Internal.UpdateCipherResultReceive(result))
}
}
}
@ -211,7 +211,7 @@ class VaultAddItemViewModel @Inject constructor(
private fun handleCloseClick() {
sendEvent(
event = VaultAddItemEvent.NavigateBack,
event = VaultAddEditEvent.NavigateBack,
)
}
@ -222,9 +222,9 @@ class VaultAddItemViewModel @Inject constructor(
}
private fun handleAddNewCustomFieldClick(
action: VaultAddItemAction.Common.AddNewCustomFieldClick,
action: VaultAddEditAction.Common.AddNewCustomFieldClick,
) {
val newCustomData: VaultAddItemState.Custom =
val newCustomData: VaultAddEditState.Custom =
action.customFieldType.toCustomField(action.name)
updateCommonContent { loginType ->
@ -233,7 +233,7 @@ class VaultAddItemViewModel @Inject constructor(
}
private fun handleCustomFieldValueChange(
action: VaultAddItemAction.Common.CustomFieldValueChange,
action: VaultAddEditAction.Common.CustomFieldValueChange,
) {
updateCommonContent { commonContent ->
commonContent.copy(
@ -249,7 +249,7 @@ class VaultAddItemViewModel @Inject constructor(
}
private fun handleFolderTextInputChange(
action: VaultAddItemAction.Common.FolderChange,
action: VaultAddEditAction.Common.FolderChange,
) {
updateCommonContent { commonContent ->
commonContent.copy(folderName = action.folder)
@ -257,7 +257,7 @@ class VaultAddItemViewModel @Inject constructor(
}
private fun handleToggleFavorite(
action: VaultAddItemAction.Common.ToggleFavorite,
action: VaultAddEditAction.Common.ToggleFavorite,
) {
updateCommonContent { commonContent ->
commonContent.copy(favorite = action.isFavorite)
@ -265,7 +265,7 @@ class VaultAddItemViewModel @Inject constructor(
}
private fun handleToggleMasterPasswordReprompt(
action: VaultAddItemAction.Common.ToggleMasterPasswordReprompt,
action: VaultAddEditAction.Common.ToggleMasterPasswordReprompt,
) {
updateCommonContent { commonContent ->
commonContent.copy(masterPasswordReprompt = action.isMasterPasswordReprompt)
@ -273,7 +273,7 @@ class VaultAddItemViewModel @Inject constructor(
}
private fun handleNotesTextInputChange(
action: VaultAddItemAction.Common.NotesTextChange,
action: VaultAddEditAction.Common.NotesTextChange,
) {
updateCommonContent { commonContent ->
commonContent.copy(notes = action.notes)
@ -281,7 +281,7 @@ class VaultAddItemViewModel @Inject constructor(
}
private fun handleOwnershipTextInputChange(
action: VaultAddItemAction.Common.OwnershipChange,
action: VaultAddEditAction.Common.OwnershipChange,
) {
updateCommonContent { commonContent ->
commonContent.copy(ownership = action.ownership)
@ -289,7 +289,7 @@ class VaultAddItemViewModel @Inject constructor(
}
private fun handleNameTextInputChange(
action: VaultAddItemAction.Common.NameTextChange,
action: VaultAddEditAction.Common.NameTextChange,
) {
updateCommonContent { commonContent ->
commonContent.copy(name = action.name)
@ -299,7 +299,7 @@ class VaultAddItemViewModel @Inject constructor(
private fun handleTooltipClick() {
// TODO Add the text for the prompt (BIT-1079)
sendEvent(
event = VaultAddItemEvent.ShowToast(
event = VaultAddEditEvent.ShowToast(
message = "Not yet implemented".asText(),
),
)
@ -311,53 +311,53 @@ class VaultAddItemViewModel @Inject constructor(
@Suppress("LongMethod")
private fun handleAddLoginTypeAction(
action: VaultAddItemAction.ItemType.LoginType,
action: VaultAddEditAction.ItemType.LoginType,
) {
when (action) {
is VaultAddItemAction.ItemType.LoginType.UsernameTextChange -> {
is VaultAddEditAction.ItemType.LoginType.UsernameTextChange -> {
handleLoginUsernameTextInputChange(action)
}
is VaultAddItemAction.ItemType.LoginType.PasswordTextChange -> {
is VaultAddEditAction.ItemType.LoginType.PasswordTextChange -> {
handleLoginPasswordTextInputChange(action)
}
is VaultAddItemAction.ItemType.LoginType.UriTextChange -> {
is VaultAddEditAction.ItemType.LoginType.UriTextChange -> {
handleLoginUriTextInputChange(action)
}
is VaultAddItemAction.ItemType.LoginType.OpenUsernameGeneratorClick -> {
is VaultAddEditAction.ItemType.LoginType.OpenUsernameGeneratorClick -> {
handleLoginOpenUsernameGeneratorClick()
}
is VaultAddItemAction.ItemType.LoginType.PasswordCheckerClick -> {
is VaultAddEditAction.ItemType.LoginType.PasswordCheckerClick -> {
handleLoginPasswordCheckerClick()
}
is VaultAddItemAction.ItemType.LoginType.OpenPasswordGeneratorClick -> {
is VaultAddEditAction.ItemType.LoginType.OpenPasswordGeneratorClick -> {
handleLoginOpenPasswordGeneratorClick()
}
is VaultAddItemAction.ItemType.LoginType.SetupTotpClick -> {
is VaultAddEditAction.ItemType.LoginType.SetupTotpClick -> {
handleLoginSetupTotpClick(action)
}
is VaultAddItemAction.ItemType.LoginType.UriSettingsClick -> {
is VaultAddEditAction.ItemType.LoginType.UriSettingsClick -> {
handleLoginUriSettingsClick()
}
is VaultAddItemAction.ItemType.LoginType.AddNewUriClick -> {
is VaultAddEditAction.ItemType.LoginType.AddNewUriClick -> {
handleLoginAddNewUriClick()
}
is VaultAddItemAction.ItemType.LoginType.CopyTotpKeyClick -> {
is VaultAddEditAction.ItemType.LoginType.CopyTotpKeyClick -> {
handleLoginCopyTotpKeyText(action)
}
}
}
private fun handleLoginUsernameTextInputChange(
action: VaultAddItemAction.ItemType.LoginType.UsernameTextChange,
action: VaultAddEditAction.ItemType.LoginType.UsernameTextChange,
) {
updateLoginContent { loginType ->
loginType.copy(username = action.username)
@ -365,7 +365,7 @@ class VaultAddItemViewModel @Inject constructor(
}
private fun handleLoginPasswordTextInputChange(
action: VaultAddItemAction.ItemType.LoginType.PasswordTextChange,
action: VaultAddEditAction.ItemType.LoginType.PasswordTextChange,
) {
updateLoginContent { loginType ->
loginType.copy(password = action.password)
@ -373,7 +373,7 @@ class VaultAddItemViewModel @Inject constructor(
}
private fun handleLoginUriTextInputChange(
action: VaultAddItemAction.ItemType.LoginType.UriTextChange,
action: VaultAddEditAction.ItemType.LoginType.UriTextChange,
) {
updateLoginContent { loginType ->
loginType.copy(uri = action.uri)
@ -383,7 +383,7 @@ class VaultAddItemViewModel @Inject constructor(
private fun handleLoginOpenUsernameGeneratorClick() {
viewModelScope.launch {
sendEvent(
event = VaultAddItemEvent.ShowToast(
event = VaultAddEditEvent.ShowToast(
message = "Open Username Generator".asText(),
),
)
@ -393,7 +393,7 @@ class VaultAddItemViewModel @Inject constructor(
private fun handleLoginPasswordCheckerClick() {
viewModelScope.launch {
sendEvent(
event = VaultAddItemEvent.ShowToast(
event = VaultAddEditEvent.ShowToast(
message = "Password Checker".asText(),
),
)
@ -403,7 +403,7 @@ class VaultAddItemViewModel @Inject constructor(
private fun handleLoginOpenPasswordGeneratorClick() {
viewModelScope.launch {
sendEvent(
event = VaultAddItemEvent.ShowToast(
event = VaultAddEditEvent.ShowToast(
message = "Open Password Generator".asText(),
),
)
@ -411,14 +411,14 @@ class VaultAddItemViewModel @Inject constructor(
}
private fun handleLoginSetupTotpClick(
action: VaultAddItemAction.ItemType.LoginType.SetupTotpClick,
action: VaultAddEditAction.ItemType.LoginType.SetupTotpClick,
) {
if (action.isGranted) {
sendEvent(event = VaultAddItemEvent.NavigateToQrCodeScan)
sendEvent(event = VaultAddEditEvent.NavigateToQrCodeScan)
} else {
// TODO Add manual QR code entry (BIT-1114)
sendEvent(
event = VaultAddItemEvent.ShowToast(
event = VaultAddEditEvent.ShowToast(
message =
"Permission Not Granted, Manual QR Code Entry Not Implemented".asText(),
),
@ -427,10 +427,10 @@ class VaultAddItemViewModel @Inject constructor(
}
private fun handleLoginCopyTotpKeyText(
action: VaultAddItemAction.ItemType.LoginType.CopyTotpKeyClick,
action: VaultAddEditAction.ItemType.LoginType.CopyTotpKeyClick,
) {
sendEvent(
event = VaultAddItemEvent.CopyToClipboard(
event = VaultAddEditEvent.CopyToClipboard(
text = action.totpKey,
),
)
@ -439,7 +439,7 @@ class VaultAddItemViewModel @Inject constructor(
private fun handleLoginUriSettingsClick() {
viewModelScope.launch {
sendEvent(
event = VaultAddItemEvent.ShowToast(
event = VaultAddEditEvent.ShowToast(
message = "URI Settings".asText(),
),
)
@ -449,7 +449,7 @@ class VaultAddItemViewModel @Inject constructor(
private fun handleLoginAddNewUriClick() {
viewModelScope.launch {
sendEvent(
event = VaultAddItemEvent.ShowToast(
event = VaultAddEditEvent.ShowToast(
message = "Add New URI".asText(),
),
)
@ -459,186 +459,186 @@ class VaultAddItemViewModel @Inject constructor(
//endregion Add Login Item Type Handlers
//region Identity Type Handlers
private fun handleIdentityTypeActions(action: VaultAddItemAction.ItemType.IdentityType) {
private fun handleIdentityTypeActions(action: VaultAddEditAction.ItemType.IdentityType) {
when (action) {
is VaultAddItemAction.ItemType.IdentityType.FirstNameTextChange -> {
is VaultAddEditAction.ItemType.IdentityType.FirstNameTextChange -> {
handleIdentityFirstNameTextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.Address1TextChange -> {
is VaultAddEditAction.ItemType.IdentityType.Address1TextChange -> {
handleIdentityAddress1TextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.Address2TextChange -> {
is VaultAddEditAction.ItemType.IdentityType.Address2TextChange -> {
handleIdentityAddress2TextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.Address3TextChange -> {
is VaultAddEditAction.ItemType.IdentityType.Address3TextChange -> {
handleIdentityAddress3TextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.CityTextChange -> {
is VaultAddEditAction.ItemType.IdentityType.CityTextChange -> {
handleIdentityCityTextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.StateTextChange -> {
is VaultAddEditAction.ItemType.IdentityType.StateTextChange -> {
handleIdentityStateTextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.CompanyTextChange -> {
is VaultAddEditAction.ItemType.IdentityType.CompanyTextChange -> {
handleIdentityCompanyTextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.CountryTextChange -> {
is VaultAddEditAction.ItemType.IdentityType.CountryTextChange -> {
handleIdentityCountryTextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.EmailTextChange -> {
is VaultAddEditAction.ItemType.IdentityType.EmailTextChange -> {
handleIdentityEmailTextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.LastNameTextChange -> {
is VaultAddEditAction.ItemType.IdentityType.LastNameTextChange -> {
handleIdentityLastNameTextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.LicenseNumberTextChange -> {
is VaultAddEditAction.ItemType.IdentityType.LicenseNumberTextChange -> {
handleIdentityLicenseNumberTextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.MiddleNameTextChange -> {
is VaultAddEditAction.ItemType.IdentityType.MiddleNameTextChange -> {
handleIdentityMiddleNameTextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.PassportNumberTextChange -> {
is VaultAddEditAction.ItemType.IdentityType.PassportNumberTextChange -> {
handleIdentityPassportNumberTextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.PhoneTextChange -> {
is VaultAddEditAction.ItemType.IdentityType.PhoneTextChange -> {
handleIdentityPhoneTextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.ZipTextChange -> {
is VaultAddEditAction.ItemType.IdentityType.ZipTextChange -> {
handleIdentityZipTextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.SsnTextChange -> {
is VaultAddEditAction.ItemType.IdentityType.SsnTextChange -> {
handleIdentitySsnTextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.UsernameTextChange -> {
is VaultAddEditAction.ItemType.IdentityType.UsernameTextChange -> {
handleIdentityUsernameTextChange(action)
}
is VaultAddItemAction.ItemType.IdentityType.TitleSelected -> {
is VaultAddEditAction.ItemType.IdentityType.TitleSelected -> {
handleIdentityTitleSelected(action)
}
}
}
private fun handleIdentityAddress1TextChange(
action: VaultAddItemAction.ItemType.IdentityType.Address1TextChange,
action: VaultAddEditAction.ItemType.IdentityType.Address1TextChange,
) {
updateIdentityContent { it.copy(address1 = action.address1) }
}
private fun handleIdentityAddress2TextChange(
action: VaultAddItemAction.ItemType.IdentityType.Address2TextChange,
action: VaultAddEditAction.ItemType.IdentityType.Address2TextChange,
) {
updateIdentityContent { it.copy(address2 = action.address2) }
}
private fun handleIdentityAddress3TextChange(
action: VaultAddItemAction.ItemType.IdentityType.Address3TextChange,
action: VaultAddEditAction.ItemType.IdentityType.Address3TextChange,
) {
updateIdentityContent { it.copy(address3 = action.address3) }
}
private fun handleIdentityCityTextChange(
action: VaultAddItemAction.ItemType.IdentityType.CityTextChange,
action: VaultAddEditAction.ItemType.IdentityType.CityTextChange,
) {
updateIdentityContent { it.copy(city = action.city) }
}
private fun handleIdentityStateTextChange(
action: VaultAddItemAction.ItemType.IdentityType.StateTextChange,
action: VaultAddEditAction.ItemType.IdentityType.StateTextChange,
) {
updateIdentityContent { it.copy(state = action.state) }
}
private fun handleIdentityCompanyTextChange(
action: VaultAddItemAction.ItemType.IdentityType.CompanyTextChange,
action: VaultAddEditAction.ItemType.IdentityType.CompanyTextChange,
) {
updateIdentityContent { it.copy(company = action.company) }
}
private fun handleIdentityCountryTextChange(
action: VaultAddItemAction.ItemType.IdentityType.CountryTextChange,
action: VaultAddEditAction.ItemType.IdentityType.CountryTextChange,
) {
updateIdentityContent { it.copy(country = action.country) }
}
private fun handleIdentityEmailTextChange(
action: VaultAddItemAction.ItemType.IdentityType.EmailTextChange,
action: VaultAddEditAction.ItemType.IdentityType.EmailTextChange,
) {
updateIdentityContent { it.copy(email = action.email) }
}
private fun handleIdentityLastNameTextChange(
action: VaultAddItemAction.ItemType.IdentityType.LastNameTextChange,
action: VaultAddEditAction.ItemType.IdentityType.LastNameTextChange,
) {
updateIdentityContent { it.copy(lastName = action.lastName) }
}
private fun handleIdentityLicenseNumberTextChange(
action: VaultAddItemAction.ItemType.IdentityType.LicenseNumberTextChange,
action: VaultAddEditAction.ItemType.IdentityType.LicenseNumberTextChange,
) {
updateIdentityContent { it.copy(licenseNumber = action.licenseNumber) }
}
private fun handleIdentityMiddleNameTextChange(
action: VaultAddItemAction.ItemType.IdentityType.MiddleNameTextChange,
action: VaultAddEditAction.ItemType.IdentityType.MiddleNameTextChange,
) {
updateIdentityContent { it.copy(middleName = action.middleName) }
}
private fun handleIdentityPassportNumberTextChange(
action: VaultAddItemAction.ItemType.IdentityType.PassportNumberTextChange,
action: VaultAddEditAction.ItemType.IdentityType.PassportNumberTextChange,
) {
updateIdentityContent { it.copy(passportNumber = action.passportNumber) }
}
private fun handleIdentityPhoneTextChange(
action: VaultAddItemAction.ItemType.IdentityType.PhoneTextChange,
action: VaultAddEditAction.ItemType.IdentityType.PhoneTextChange,
) {
updateIdentityContent { it.copy(phone = action.phone) }
}
private fun handleIdentityZipTextChange(
action: VaultAddItemAction.ItemType.IdentityType.ZipTextChange,
action: VaultAddEditAction.ItemType.IdentityType.ZipTextChange,
) {
updateIdentityContent { it.copy(zip = action.zip) }
}
private fun handleIdentitySsnTextChange(
action: VaultAddItemAction.ItemType.IdentityType.SsnTextChange,
action: VaultAddEditAction.ItemType.IdentityType.SsnTextChange,
) {
updateIdentityContent { it.copy(ssn = action.ssn) }
}
private fun handleIdentityUsernameTextChange(
action: VaultAddItemAction.ItemType.IdentityType.UsernameTextChange,
action: VaultAddEditAction.ItemType.IdentityType.UsernameTextChange,
) {
updateIdentityContent { it.copy(username = action.username) }
}
private fun handleIdentityFirstNameTextChange(
action: VaultAddItemAction.ItemType.IdentityType.FirstNameTextChange,
action: VaultAddEditAction.ItemType.IdentityType.FirstNameTextChange,
) {
updateIdentityContent { it.copy(firstName = action.firstName) }
}
private fun handleIdentityTitleSelected(
action: VaultAddItemAction.ItemType.IdentityType.TitleSelected,
action: VaultAddEditAction.ItemType.IdentityType.TitleSelected,
) {
updateIdentityContent { it.copy(selectedTitle = action.title) }
}
@ -646,23 +646,23 @@ class VaultAddItemViewModel @Inject constructor(
//region Internal Type Handlers
private fun handleInternalActions(action: VaultAddItemAction.Internal) {
private fun handleInternalActions(action: VaultAddEditAction.Internal) {
when (action) {
is VaultAddItemAction.Internal.CreateCipherResultReceive -> {
is VaultAddEditAction.Internal.CreateCipherResultReceive -> {
handleCreateCipherResultReceive(action)
}
is VaultAddItemAction.Internal.UpdateCipherResultReceive -> {
is VaultAddEditAction.Internal.UpdateCipherResultReceive -> {
handleUpdateCipherResultReceive(action)
}
is VaultAddItemAction.Internal.VaultDataReceive -> handleVaultDataReceive(action)
is VaultAddItemAction.Internal.TotpCodeReceive -> handleVaultTotpCodeReceive(action)
is VaultAddEditAction.Internal.TotpCodeReceive -> handleVaultTotpCodeReceive(action)
is VaultAddEditAction.Internal.VaultDataReceive -> handleVaultDataReceive(action)
}
}
private fun handleCreateCipherResultReceive(
action: VaultAddItemAction.Internal.CreateCipherResultReceive,
action: VaultAddEditAction.Internal.CreateCipherResultReceive,
) {
mutableStateFlow.update {
it.copy(dialog = null)
@ -672,7 +672,7 @@ class VaultAddItemViewModel @Inject constructor(
is CreateCipherResult.Error -> {
// TODO Display error dialog BIT-501
sendEvent(
event = VaultAddItemEvent.ShowToast(
event = VaultAddEditEvent.ShowToast(
message = "Save Item Failure".asText(),
),
)
@ -680,34 +680,34 @@ class VaultAddItemViewModel @Inject constructor(
is CreateCipherResult.Success -> {
sendEvent(
event = VaultAddItemEvent.NavigateBack,
event = VaultAddEditEvent.NavigateBack,
)
}
}
}
private fun handleUpdateCipherResultReceive(
action: VaultAddItemAction.Internal.UpdateCipherResultReceive,
action: VaultAddEditAction.Internal.UpdateCipherResultReceive,
) {
mutableStateFlow.update { it.copy(dialog = null) }
when (action.updateCipherResult) {
is UpdateCipherResult.Error -> {
// TODO Display error dialog BIT-501
sendEvent(VaultAddItemEvent.ShowToast(message = "Save Item Failure".asText()))
sendEvent(VaultAddEditEvent.ShowToast(message = "Save Item Failure".asText()))
}
is UpdateCipherResult.Success -> {
sendEvent(VaultAddItemEvent.NavigateBack)
sendEvent(VaultAddEditEvent.NavigateBack)
}
}
}
private fun handleVaultDataReceive(action: VaultAddItemAction.Internal.VaultDataReceive) {
private fun handleVaultDataReceive(action: VaultAddEditAction.Internal.VaultDataReceive) {
when (val vaultDataState = action.vaultDataState) {
is DataState.Error -> {
mutableStateFlow.update {
it.copy(
viewState = VaultAddItemState.ViewState.Error(
viewState = VaultAddEditState.ViewState.Error(
message = R.string.generic_error_message.asText(),
),
)
@ -720,7 +720,7 @@ class VaultAddItemViewModel @Inject constructor(
viewState = vaultDataState
.data
?.toViewState()
?: VaultAddItemState.ViewState.Error(
?: VaultAddEditState.ViewState.Error(
message = R.string.generic_error_message.asText(),
),
)
@ -729,14 +729,14 @@ class VaultAddItemViewModel @Inject constructor(
DataState.Loading -> {
mutableStateFlow.update {
it.copy(viewState = VaultAddItemState.ViewState.Loading)
it.copy(viewState = VaultAddEditState.ViewState.Loading)
}
}
is DataState.NoNetwork -> {
mutableStateFlow.update {
it.copy(
viewState = VaultAddItemState.ViewState.Error(
viewState = VaultAddEditState.ViewState.Error(
message = R.string.internet_connection_required_title
.asText()
.concat(R.string.internet_connection_required_message.asText()),
@ -751,7 +751,7 @@ class VaultAddItemViewModel @Inject constructor(
viewState = vaultDataState
.data
?.toViewState()
?: VaultAddItemState.ViewState.Error(
?: VaultAddEditState.ViewState.Error(
message = R.string.generic_error_message.asText(),
),
)
@ -760,13 +760,13 @@ class VaultAddItemViewModel @Inject constructor(
}
}
private fun handleVaultTotpCodeReceive(action: VaultAddItemAction.Internal.TotpCodeReceive) {
private fun handleVaultTotpCodeReceive(action: VaultAddEditAction.Internal.TotpCodeReceive) {
updateLoginContent { loginType ->
loginType.copy(totp = action.totpCode)
}
sendEvent(
event = VaultAddItemEvent.ShowToast(
event = VaultAddEditEvent.ShowToast(
message = R.string.authenticator_key_added.asText(),
),
)
@ -777,26 +777,26 @@ class VaultAddItemViewModel @Inject constructor(
//region Utility Functions
private inline fun onContent(
crossinline block: (VaultAddItemState.ViewState.Content) -> Unit,
crossinline block: (VaultAddEditState.ViewState.Content) -> Unit,
) {
(state.viewState as? VaultAddItemState.ViewState.Content)?.let(block)
(state.viewState as? VaultAddEditState.ViewState.Content)?.let(block)
}
private inline fun updateContent(
crossinline block: (
VaultAddItemState.ViewState.Content,
) -> VaultAddItemState.ViewState.Content?,
VaultAddEditState.ViewState.Content,
) -> VaultAddEditState.ViewState.Content?,
) {
val currentViewState = state.viewState
val updatedContent = (currentViewState as? VaultAddItemState.ViewState.Content)
val updatedContent = (currentViewState as? VaultAddEditState.ViewState.Content)
?.let(block)
?: return
mutableStateFlow.update { it.copy(viewState = updatedContent) }
}
private inline fun updateCommonContent(
crossinline block: (VaultAddItemState.ViewState.Content.Common) ->
VaultAddItemState.ViewState.Content.Common,
crossinline block: (VaultAddEditState.ViewState.Content.Common) ->
VaultAddEditState.ViewState.Content.Common,
) {
updateContent { currentContent ->
currentContent.copy(common = block(currentContent.common))
@ -804,21 +804,21 @@ class VaultAddItemViewModel @Inject constructor(
}
private inline fun updateLoginContent(
crossinline block: (VaultAddItemState.ViewState.Content.ItemType.Login) ->
VaultAddItemState.ViewState.Content.ItemType.Login,
crossinline block: (VaultAddEditState.ViewState.Content.ItemType.Login) ->
VaultAddEditState.ViewState.Content.ItemType.Login,
) {
updateContent { currentContent ->
(currentContent.type as? VaultAddItemState.ViewState.Content.ItemType.Login)
(currentContent.type as? VaultAddEditState.ViewState.Content.ItemType.Login)
?.let { currentContent.copy(type = block(it)) }
}
}
private inline fun updateIdentityContent(
crossinline block: (VaultAddItemState.ViewState.Content.ItemType.Identity) ->
VaultAddItemState.ViewState.Content.ItemType.Identity,
crossinline block: (VaultAddEditState.ViewState.Content.ItemType.Identity) ->
VaultAddEditState.ViewState.Content.ItemType.Identity,
) {
updateContent { currentContent ->
(currentContent.type as? VaultAddItemState.ViewState.Content.ItemType.Identity)
(currentContent.type as? VaultAddEditState.ViewState.Content.ItemType.Identity)
?.let { currentContent.copy(type = block(it)) }
}
}
@ -834,7 +834,7 @@ class VaultAddItemViewModel @Inject constructor(
* @property dialog the state for the dialogs that can be displayed
*/
@Parcelize
data class VaultAddItemState(
data class VaultAddEditState(
val vaultAddEditType: VaultAddEditType,
val viewState: ViewState,
val dialog: DialogState?,
@ -867,11 +867,11 @@ data class VaultAddItemState(
}
/**
* Represents the specific view states for the [VaultAddItemScreen].
* Represents the specific view states for the [VaultAddEditScreen].
*/
sealed class ViewState : Parcelable {
/**
* Represents an error state for the [VaultAddItemScreen].
* Represents an error state for the [VaultAddEditScreen].
*/
@Parcelize
data class Error(
@ -879,14 +879,14 @@ data class VaultAddItemState(
) : ViewState()
/**
* Loading state for the [VaultAddItemScreen], signifying that the content is being
* Loading state for the [VaultAddEditScreen], signifying that the content is being
* processed.
*/
@Parcelize
data object Loading : ViewState()
/**
* Represents a loaded content state for the [VaultAddItemScreen].
* Represents a loaded content state for the [VaultAddEditScreen].
*/
@Parcelize
data class Content(
@ -1119,38 +1119,38 @@ data class VaultAddItemState(
* Represents a set of events that can be emitted during the process of adding an item to the vault.
* Each subclass of this sealed class denotes a distinct event that can occur.
*/
sealed class VaultAddItemEvent {
sealed class VaultAddEditEvent {
/**
* Shows a toast with the given [message].
*/
data class ShowToast(val message: Text) : VaultAddItemEvent()
data class ShowToast(val message: Text) : VaultAddEditEvent()
/**
* Copy the given [text] to the clipboard.
*/
data class CopyToClipboard(val text: String) : VaultAddItemEvent()
data class CopyToClipboard(val text: String) : VaultAddEditEvent()
/**
* Navigate back to previous screen.
*/
data object NavigateBack : VaultAddItemEvent()
data object NavigateBack : VaultAddEditEvent()
/**
* Navigate to the QR code scan screen.
*/
data object NavigateToQrCodeScan : VaultAddItemEvent()
data object NavigateToQrCodeScan : VaultAddEditEvent()
}
/**
* Represents a set of actions related to the process of adding an item to the vault.
* Each subclass of this sealed class denotes a distinct action that can be taken.
*/
sealed class VaultAddItemAction {
sealed class VaultAddEditAction {
/**
* Represents actions common across all item types.
*/
sealed class Common : VaultAddItemAction() {
sealed class Common : VaultAddEditAction() {
/**
* Represents the action when the save button is clicked.
@ -1173,7 +1173,7 @@ sealed class VaultAddItemAction {
* @property typeOption The selected type option.
*/
data class TypeOptionSelect(
val typeOption: VaultAddItemState.ItemTypeOption,
val typeOption: VaultAddEditState.ItemTypeOption,
) : Common()
/**
@ -1230,7 +1230,7 @@ sealed class VaultAddItemAction {
/**
* Fired when the custom field data is changed.
*/
data class CustomFieldValueChange(val customField: VaultAddItemState.Custom) : Common()
data class CustomFieldValueChange(val customField: VaultAddEditState.Custom) : Common()
/**
* Represents the action to open tooltip
@ -1241,7 +1241,7 @@ sealed class VaultAddItemAction {
/**
* Represents actions specific to an item type.
*/
sealed class ItemType : VaultAddItemAction() {
sealed class ItemType : VaultAddEditAction() {
/**
* Represents actions specific to the Login type.
@ -1439,15 +1439,15 @@ sealed class VaultAddItemAction {
* @property title The selected title.
*/
data class TitleSelected(
val title: VaultAddItemState.ViewState.Content.ItemType.Identity.Title,
val title: VaultAddEditState.ViewState.Content.ItemType.Identity.Title,
) : IdentityType()
}
}
/**
* Models actions that the [VaultAddItemViewModel] itself might send.
* Models actions that the [VaultAddEditViewModel] itself might send.
*/
sealed class Internal : VaultAddItemAction() {
sealed class Internal : VaultAddEditAction() {
/**
* Indicates that the vault totp code has been received.

View file

@ -1,10 +1,10 @@
package com.x8bit.bitwarden.ui.vault.feature.additem.handlers
package com.x8bit.bitwarden.ui.vault.feature.addedit.handlers
import com.x8bit.bitwarden.ui.platform.base.util.asText
import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemAction
import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemState
import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemViewModel
import com.x8bit.bitwarden.ui.vault.feature.additem.model.CustomFieldType
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditAction
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditState
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditViewModel
import com.x8bit.bitwarden.ui.vault.feature.addedit.model.CustomFieldType
/**
* A collection of handler functions for managing actions common
@ -23,7 +23,7 @@ import com.x8bit.bitwarden.ui.vault.feature.additem.model.CustomFieldType
* @property onCustomFieldValueChange Handles the action when the field's value changes
*/
@Suppress("LongParameterList")
class VaultAddItemCommonHandlers(
class VaultAddEditCommonHandlers(
val onNameTextChange: (String) -> Unit,
val onFolderTextChange: (String) -> Unit,
val onToggleFavorite: (Boolean) -> Unit,
@ -32,59 +32,59 @@ class VaultAddItemCommonHandlers(
val onOwnershipTextChange: (String) -> Unit,
val onTooltipClick: () -> Unit,
val onAddNewCustomFieldClick: (CustomFieldType, String) -> Unit,
val onCustomFieldValueChange: (VaultAddItemState.Custom) -> Unit,
val onCustomFieldValueChange: (VaultAddEditState.Custom) -> Unit,
) {
companion object {
/**
* Creates an instance of [VaultAddItemCommonHandlers] by binding actions
* to the provided [VaultAddItemViewModel].
* Creates an instance of [VaultAddEditCommonHandlers] by binding actions
* to the provided [VaultAddEditViewModel].
*/
@Suppress("LongMethod")
fun create(viewModel: VaultAddItemViewModel): VaultAddItemCommonHandlers {
return VaultAddItemCommonHandlers(
fun create(viewModel: VaultAddEditViewModel): VaultAddEditCommonHandlers {
return VaultAddEditCommonHandlers(
onNameTextChange = { newName ->
viewModel.trySendAction(
VaultAddItemAction.Common.NameTextChange(newName),
VaultAddEditAction.Common.NameTextChange(newName),
)
},
onFolderTextChange = { newFolder ->
viewModel.trySendAction(
VaultAddItemAction.Common.FolderChange(
VaultAddEditAction.Common.FolderChange(
newFolder.asText(),
),
)
},
onToggleFavorite = { isFavorite ->
viewModel.trySendAction(
VaultAddItemAction.Common.ToggleFavorite(isFavorite),
VaultAddEditAction.Common.ToggleFavorite(isFavorite),
)
},
onToggleMasterPasswordReprompt = { isMasterPasswordReprompt ->
viewModel.trySendAction(
VaultAddItemAction.Common.ToggleMasterPasswordReprompt(
VaultAddEditAction.Common.ToggleMasterPasswordReprompt(
isMasterPasswordReprompt,
),
)
},
onNotesTextChange = { newNotes ->
viewModel.trySendAction(
VaultAddItemAction.Common.NotesTextChange(newNotes),
VaultAddEditAction.Common.NotesTextChange(newNotes),
)
},
onOwnershipTextChange = { newOwnership ->
viewModel.trySendAction(
VaultAddItemAction.Common.OwnershipChange(newOwnership),
VaultAddEditAction.Common.OwnershipChange(newOwnership),
)
},
onTooltipClick = {
viewModel.trySendAction(
VaultAddItemAction.Common.TooltipClick,
VaultAddEditAction.Common.TooltipClick,
)
},
onAddNewCustomFieldClick = { newCustomFieldType, name ->
viewModel.trySendAction(
VaultAddItemAction.Common.AddNewCustomFieldClick(
VaultAddEditAction.Common.AddNewCustomFieldClick(
newCustomFieldType,
name,
),
@ -92,7 +92,7 @@ class VaultAddItemCommonHandlers(
},
onCustomFieldValueChange = { newValue ->
viewModel.trySendAction(
VaultAddItemAction.Common.CustomFieldValueChange(
VaultAddEditAction.Common.CustomFieldValueChange(
newValue,
),
)

View file

@ -1,8 +1,8 @@
package com.x8bit.bitwarden.ui.vault.feature.additem.handlers
package com.x8bit.bitwarden.ui.vault.feature.addedit.handlers
import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemAction
import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemState
import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemViewModel
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditAction
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditState
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditViewModel
/**
* A collection of handler functions specifically tailored for managing actions
@ -26,8 +26,8 @@ import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemViewModel
* @property onCountryTextChange Handles the action when the country text is changed.
*/
@Suppress("LongParameterList")
class VaultAddIdentityItemTypeHandlers(
val onTitleSelected: (VaultAddItemState.ViewState.Content.ItemType.Identity.Title) -> Unit,
class VaultAddEditIdentityTypeHandlers(
val onTitleSelected: (VaultAddEditState.ViewState.Content.ItemType.Identity.Title) -> Unit,
val onFirstNameTextChange: (String) -> Unit,
val onMiddleNameTextChange: (String) -> Unit,
val onLastNameTextChange: (String) -> Unit,
@ -49,134 +49,134 @@ class VaultAddIdentityItemTypeHandlers(
companion object {
/**
* Creates an instance of [VaultAddIdentityItemTypeHandlers] by binding actions
* to the provided [VaultAddItemViewModel].
* Creates an instance of [VaultAddEditIdentityTypeHandlers] by binding actions
* to the provided [VaultAddEditViewModel].
*/
@Suppress("LongMethod")
fun create(viewModel: VaultAddItemViewModel): VaultAddIdentityItemTypeHandlers {
return VaultAddIdentityItemTypeHandlers(
fun create(viewModel: VaultAddEditViewModel): VaultAddEditIdentityTypeHandlers {
return VaultAddEditIdentityTypeHandlers(
onTitleSelected = { newTitle ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.TitleSelected(
VaultAddEditAction.ItemType.IdentityType.TitleSelected(
title = newTitle,
),
)
},
onFirstNameTextChange = { newFirstName ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.FirstNameTextChange(
VaultAddEditAction.ItemType.IdentityType.FirstNameTextChange(
firstName = newFirstName,
),
)
},
onMiddleNameTextChange = { newMiddleName ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.MiddleNameTextChange(
VaultAddEditAction.ItemType.IdentityType.MiddleNameTextChange(
middleName = newMiddleName,
),
)
},
onLastNameTextChange = { newLastName ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.LastNameTextChange(
VaultAddEditAction.ItemType.IdentityType.LastNameTextChange(
lastName = newLastName,
),
)
},
onUsernameTextChange = { newUsername ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.UsernameTextChange(
VaultAddEditAction.ItemType.IdentityType.UsernameTextChange(
username = newUsername,
),
)
},
onCompanyTextChange = { newCompany ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.CompanyTextChange(
VaultAddEditAction.ItemType.IdentityType.CompanyTextChange(
company = newCompany,
),
)
},
onSsnTextChange = { newSsn ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.SsnTextChange(
VaultAddEditAction.ItemType.IdentityType.SsnTextChange(
ssn = newSsn,
),
)
},
onPassportNumberTextChange = { newPassportNumber ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.PassportNumberTextChange(
VaultAddEditAction.ItemType.IdentityType.PassportNumberTextChange(
passportNumber = newPassportNumber,
),
)
},
onLicenseNumberTextChange = { newLicenseNumber ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.LicenseNumberTextChange(
VaultAddEditAction.ItemType.IdentityType.LicenseNumberTextChange(
licenseNumber = newLicenseNumber,
),
)
},
onEmailTextChange = { newEmail ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.EmailTextChange(
VaultAddEditAction.ItemType.IdentityType.EmailTextChange(
email = newEmail,
),
)
},
onPhoneTextChange = { newPhone ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.PhoneTextChange(
VaultAddEditAction.ItemType.IdentityType.PhoneTextChange(
phone = newPhone,
),
)
},
onAddress1TextChange = { newAddress1 ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.Address1TextChange(
VaultAddEditAction.ItemType.IdentityType.Address1TextChange(
address1 = newAddress1,
),
)
},
onAddress2TextChange = { newAddress2 ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.Address2TextChange(
VaultAddEditAction.ItemType.IdentityType.Address2TextChange(
address2 = newAddress2,
),
)
},
onAddress3TextChange = { newAddress3 ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.Address3TextChange(
VaultAddEditAction.ItemType.IdentityType.Address3TextChange(
address3 = newAddress3,
),
)
},
onCityTextChange = { newCity ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.CityTextChange(
VaultAddEditAction.ItemType.IdentityType.CityTextChange(
city = newCity,
),
)
},
onStateTextChange = { newState ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.StateTextChange(
VaultAddEditAction.ItemType.IdentityType.StateTextChange(
state = newState,
),
)
},
onZipTextChange = { newZip ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.ZipTextChange(
VaultAddEditAction.ItemType.IdentityType.ZipTextChange(
zip = newZip,
),
)
},
onCountryTextChange = { newCountry ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.CountryTextChange(
VaultAddEditAction.ItemType.IdentityType.CountryTextChange(
country = newCountry,
),
)

View file

@ -1,7 +1,7 @@
package com.x8bit.bitwarden.ui.vault.feature.additem.handlers
package com.x8bit.bitwarden.ui.vault.feature.addedit.handlers
import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemAction
import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemViewModel
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditAction
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditViewModel
/**
* A collection of handler functions specifically tailored for managing actions
@ -22,7 +22,7 @@ import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemViewModel
* @property onAddNewUriClick Handles the action when the add new URI button is clicked.
*/
@Suppress("LongParameterList")
class VaultAddLoginItemTypeHandlers(
class VaultAddEditLoginTypeHandlers(
val onUsernameTextChange: (String) -> Unit,
val onPasswordTextChange: (String) -> Unit,
val onUriTextChange: (String) -> Unit,
@ -37,59 +37,59 @@ class VaultAddLoginItemTypeHandlers(
companion object {
/**
* Creates an instance of [VaultAddLoginItemTypeHandlers] by binding actions
* to the provided [VaultAddItemViewModel].
* Creates an instance of [VaultAddEditLoginTypeHandlers] by binding actions
* to the provided [VaultAddEditViewModel].
*
* @param viewModel The [VaultAddItemViewModel] to which actions will be sent.
* @return A fully initialized [VaultAddLoginItemTypeHandlers] object.
* @param viewModel The [VaultAddEditViewModel] to which actions will be sent.
* @return A fully initialized [VaultAddEditLoginTypeHandlers] object.
*/
@Suppress("LongMethod")
fun create(viewModel: VaultAddItemViewModel): VaultAddLoginItemTypeHandlers {
return VaultAddLoginItemTypeHandlers(
fun create(viewModel: VaultAddEditViewModel): VaultAddEditLoginTypeHandlers {
return VaultAddEditLoginTypeHandlers(
onUsernameTextChange = { newUsername ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.UsernameTextChange(newUsername),
VaultAddEditAction.ItemType.LoginType.UsernameTextChange(newUsername),
)
},
onPasswordTextChange = { newPassword ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.PasswordTextChange(newPassword),
VaultAddEditAction.ItemType.LoginType.PasswordTextChange(newPassword),
)
},
onUriTextChange = { newUri ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.UriTextChange(newUri),
VaultAddEditAction.ItemType.LoginType.UriTextChange(newUri),
)
},
onOpenUsernameGeneratorClick = {
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.OpenUsernameGeneratorClick,
VaultAddEditAction.ItemType.LoginType.OpenUsernameGeneratorClick,
)
},
onPasswordCheckerClick = {
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.PasswordCheckerClick,
VaultAddEditAction.ItemType.LoginType.PasswordCheckerClick,
)
},
onOpenPasswordGeneratorClick = {
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.OpenPasswordGeneratorClick,
VaultAddEditAction.ItemType.LoginType.OpenPasswordGeneratorClick,
)
},
onSetupTotpClick = { isGranted ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.SetupTotpClick(isGranted),
VaultAddEditAction.ItemType.LoginType.SetupTotpClick(isGranted),
)
},
onUriSettingsClick = {
viewModel.trySendAction(VaultAddItemAction.ItemType.LoginType.UriSettingsClick)
viewModel.trySendAction(VaultAddEditAction.ItemType.LoginType.UriSettingsClick)
},
onAddNewUriClick = {
viewModel.trySendAction(VaultAddItemAction.ItemType.LoginType.AddNewUriClick)
viewModel.trySendAction(VaultAddEditAction.ItemType.LoginType.AddNewUriClick)
},
onCopyTotpKeyClick = { totpKey ->
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.CopyTotpKeyClick(
VaultAddEditAction.ItemType.LoginType.CopyTotpKeyClick(
totpKey,
),
)

View file

@ -1,9 +1,9 @@
package com.x8bit.bitwarden.ui.vault.feature.additem.model
package com.x8bit.bitwarden.ui.vault.feature.addedit.model
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.ui.platform.base.util.Text
import com.x8bit.bitwarden.ui.platform.base.util.asText
import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemState
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditState
import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType
import java.util.UUID
@ -18,14 +18,14 @@ enum class CustomFieldType(val typeText: Text) {
}
/**
* A function that converts [CustomFieldType] and a string to [VaultAddItemState.Custom].
* A function that converts [CustomFieldType] and a string to [VaultAddEditState.Custom].
*/
fun CustomFieldType.toCustomField(
name: String,
): VaultAddItemState.Custom {
): VaultAddEditState.Custom {
return when (this) {
CustomFieldType.BOOLEAN -> {
VaultAddItemState.Custom.BooleanField(
VaultAddEditState.Custom.BooleanField(
itemId = UUID.randomUUID().toString(),
name = name,
value = false,
@ -33,7 +33,7 @@ fun CustomFieldType.toCustomField(
}
CustomFieldType.LINKED -> {
VaultAddItemState.Custom.LinkedField(
VaultAddEditState.Custom.LinkedField(
itemId = UUID.randomUUID().toString(),
name = name,
vaultLinkedFieldType = VaultLinkedFieldType.USERNAME,
@ -41,7 +41,7 @@ fun CustomFieldType.toCustomField(
}
CustomFieldType.HIDDEN -> {
VaultAddItemState.Custom.HiddenField(
VaultAddEditState.Custom.HiddenField(
itemId = UUID.randomUUID().toString(),
name = name,
value = "",
@ -49,7 +49,7 @@ fun CustomFieldType.toCustomField(
}
CustomFieldType.TEXT -> {
VaultAddItemState.Custom.TextField(
VaultAddEditState.Custom.TextField(
itemId = UUID.randomUUID().toString(),
name = name,
value = "",

View file

@ -1,4 +1,4 @@
package com.x8bit.bitwarden.ui.vault.feature.additem.util
package com.x8bit.bitwarden.ui.vault.feature.addedit.util
import com.bitwarden.core.CipherRepromptType
import com.bitwarden.core.CipherType
@ -7,18 +7,18 @@ import com.bitwarden.core.FieldType
import com.bitwarden.core.FieldView
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.ui.platform.base.util.asText
import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemState
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditState
import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType.Companion.fromId
import java.util.UUID
/**
* Transforms [CipherView] into [VaultAddItemState.ViewState].
* Transforms [CipherView] into [VaultAddEditState.ViewState].
*/
fun CipherView.toViewState(): VaultAddItemState.ViewState =
VaultAddItemState.ViewState.Content(
fun CipherView.toViewState(): VaultAddEditState.ViewState =
VaultAddEditState.ViewState.Content(
type = when (type) {
CipherType.LOGIN -> {
VaultAddItemState.ViewState.Content.ItemType.Login(
VaultAddEditState.ViewState.Content.ItemType.Login(
username = login?.username.orEmpty(),
password = login?.password.orEmpty(),
uri = login?.uris?.firstOrNull()?.uri.orEmpty(),
@ -26,9 +26,9 @@ fun CipherView.toViewState(): VaultAddItemState.ViewState =
)
}
CipherType.SECURE_NOTE -> VaultAddItemState.ViewState.Content.ItemType.SecureNotes
CipherType.CARD -> VaultAddItemState.ViewState.Content.ItemType.Card
CipherType.IDENTITY -> VaultAddItemState.ViewState.Content.ItemType.Identity(
CipherType.SECURE_NOTE -> VaultAddEditState.ViewState.Content.ItemType.SecureNotes
CipherType.CARD -> VaultAddEditState.ViewState.Content.ItemType.Card
CipherType.IDENTITY -> VaultAddEditState.ViewState.Content.ItemType.Identity(
selectedTitle = identity?.title.toTitleOrDefault(),
firstName = identity?.firstName.orEmpty(),
middleName = identity?.middleName.orEmpty(),
@ -48,7 +48,7 @@ fun CipherView.toViewState(): VaultAddItemState.ViewState =
country = identity?.country.orEmpty(),
)
},
common = VaultAddItemState.ViewState.Content.Common(
common = VaultAddEditState.ViewState.Content.Common(
originalCipher = this,
name = this.name,
favorite = this.favorite,
@ -67,25 +67,25 @@ fun CipherView.toViewState(): VaultAddItemState.ViewState =
private fun FieldView.toCustomField() =
when (this.type) {
FieldType.TEXT -> VaultAddItemState.Custom.TextField(
FieldType.TEXT -> VaultAddEditState.Custom.TextField(
itemId = UUID.randomUUID().toString(),
name = this.name.orEmpty(),
value = this.value.orEmpty(),
)
FieldType.HIDDEN -> VaultAddItemState.Custom.HiddenField(
FieldType.HIDDEN -> VaultAddEditState.Custom.HiddenField(
itemId = UUID.randomUUID().toString(),
name = this.name.orEmpty(),
value = this.value.orEmpty(),
)
FieldType.BOOLEAN -> VaultAddItemState.Custom.BooleanField(
FieldType.BOOLEAN -> VaultAddEditState.Custom.BooleanField(
itemId = UUID.randomUUID().toString(),
name = this.name.orEmpty(),
value = this.value.toBoolean(),
)
FieldType.LINKED -> VaultAddItemState.Custom.LinkedField(
FieldType.LINKED -> VaultAddEditState.Custom.LinkedField(
itemId = UUID.randomUUID().toString(),
name = this.name.orEmpty(),
vaultLinkedFieldType = fromId(requireNotNull(this.linkedId)),
@ -93,8 +93,8 @@ private fun FieldView.toCustomField() =
}
@Suppress("MaxLineLength")
private fun String?.toTitleOrDefault(): VaultAddItemState.ViewState.Content.ItemType.Identity.Title =
VaultAddItemState.ViewState.Content.ItemType.Identity.Title
private fun String?.toTitleOrDefault(): VaultAddEditState.ViewState.Content.ItemType.Identity.Title =
VaultAddEditState.ViewState.Content.ItemType.Identity.Title
.entries
.find { it.name == this }
?: VaultAddItemState.ViewState.Content.ItemType.Identity.Title.MR
?: VaultAddEditState.ViewState.Content.ItemType.Identity.Title.MR

View file

@ -13,13 +13,13 @@ import com.bitwarden.core.SecureNoteType
import com.bitwarden.core.SecureNoteView
import com.bitwarden.core.UriMatchType
import com.x8bit.bitwarden.ui.platform.base.util.orNullIfBlank
import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemState
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditState
import java.time.Instant
/**
* Transforms a [VaultAddItemState.ViewState.ItemType] into [CipherView].
* Transforms a [VaultAddEditState.ViewState.ItemType] into [CipherView].
*/
fun VaultAddItemState.ViewState.Content.toCipherView(): CipherView =
fun VaultAddEditState.ViewState.Content.toCipherView(): CipherView =
CipherView(
// Pulled from original cipher when editing, otherwise uses defaults
id = common.originalCipher?.id,
@ -54,16 +54,16 @@ fun VaultAddItemState.ViewState.Content.toCipherView(): CipherView =
fields = common.customFieldData.map { it.toFieldView() },
)
private fun VaultAddItemState.ViewState.Content.ItemType.toCipherType(): CipherType =
private fun VaultAddEditState.ViewState.Content.ItemType.toCipherType(): CipherType =
when (this) {
is VaultAddItemState.ViewState.Content.ItemType.Card -> CipherType.CARD
is VaultAddItemState.ViewState.Content.ItemType.Identity -> CipherType.IDENTITY
is VaultAddItemState.ViewState.Content.ItemType.Login -> CipherType.LOGIN
is VaultAddItemState.ViewState.Content.ItemType.SecureNotes -> CipherType.SECURE_NOTE
is VaultAddEditState.ViewState.Content.ItemType.Card -> CipherType.CARD
is VaultAddEditState.ViewState.Content.ItemType.Identity -> CipherType.IDENTITY
is VaultAddEditState.ViewState.Content.ItemType.Login -> CipherType.LOGIN
is VaultAddEditState.ViewState.Content.ItemType.SecureNotes -> CipherType.SECURE_NOTE
}
private fun VaultAddItemState.ViewState.Content.ItemType.toCardView(): CardView? =
(this as? VaultAddItemState.ViewState.Content.ItemType.Card)?.let {
private fun VaultAddEditState.ViewState.Content.ItemType.toCardView(): CardView? =
(this as? VaultAddEditState.ViewState.Content.ItemType.Card)?.let {
// TODO Create real CardView from Content (BIT-668)
CardView(
cardholderName = null,
@ -75,8 +75,8 @@ private fun VaultAddItemState.ViewState.Content.ItemType.toCardView(): CardView?
)
}
private fun VaultAddItemState.ViewState.Content.ItemType.toIdentityView(): IdentityView? =
(this as? VaultAddItemState.ViewState.Content.ItemType.Identity)?.let {
private fun VaultAddEditState.ViewState.Content.ItemType.toIdentityView(): IdentityView? =
(this as? VaultAddEditState.ViewState.Content.ItemType.Identity)?.let {
IdentityView(
title = it.selectedTitle.name,
firstName = it.firstName.orNullIfBlank(),
@ -99,10 +99,10 @@ private fun VaultAddItemState.ViewState.Content.ItemType.toIdentityView(): Ident
)
}
private fun VaultAddItemState.ViewState.Content.ItemType.toLoginView(
common: VaultAddItemState.ViewState.Content.Common,
private fun VaultAddEditState.ViewState.Content.ItemType.toLoginView(
common: VaultAddEditState.ViewState.Content.Common,
): LoginView? =
(this as? VaultAddItemState.ViewState.Content.ItemType.Login)?.let {
(this as? VaultAddEditState.ViewState.Content.ItemType.Login)?.let {
LoginView(
username = it.username,
password = it.password,
@ -120,12 +120,12 @@ private fun VaultAddItemState.ViewState.Content.ItemType.toLoginView(
)
}
private fun VaultAddItemState.ViewState.Content.ItemType.toSecureNotesView(): SecureNoteView? =
(this as? VaultAddItemState.ViewState.Content.ItemType.SecureNotes)?.let {
private fun VaultAddEditState.ViewState.Content.ItemType.toSecureNotesView(): SecureNoteView? =
(this as? VaultAddEditState.ViewState.Content.ItemType.SecureNotes)?.let {
SecureNoteView(type = SecureNoteType.GENERIC)
}
private fun VaultAddItemState.ViewState.Content.Common.toCipherRepromptType(): CipherRepromptType =
private fun VaultAddEditState.ViewState.Content.Common.toCipherRepromptType(): CipherRepromptType =
if (masterPasswordReprompt) {
CipherRepromptType.PASSWORD
} else {
@ -135,9 +135,9 @@ private fun VaultAddItemState.ViewState.Content.Common.toCipherRepromptType(): C
/**
* Transforms [VaultAddItemState.Custom into [FieldView].
*/
private fun VaultAddItemState.Custom.toFieldView(): FieldView =
private fun VaultAddEditState.Custom.toFieldView(): FieldView =
when (val item = this) {
is VaultAddItemState.Custom.BooleanField -> {
is VaultAddEditState.Custom.BooleanField -> {
FieldView(
name = item.name,
value = item.value.toString(),
@ -146,7 +146,7 @@ private fun VaultAddItemState.Custom.toFieldView(): FieldView =
)
}
is VaultAddItemState.Custom.HiddenField -> {
is VaultAddEditState.Custom.HiddenField -> {
FieldView(
name = item.name,
value = item.value,
@ -155,7 +155,7 @@ private fun VaultAddItemState.Custom.toFieldView(): FieldView =
)
}
is VaultAddItemState.Custom.LinkedField -> {
is VaultAddEditState.Custom.LinkedField -> {
FieldView(
name = item.name,
value = null,
@ -164,7 +164,7 @@ private fun VaultAddItemState.Custom.toFieldView(): FieldView =
)
}
is VaultAddItemState.Custom.TextField -> {
is VaultAddEditState.Custom.TextField -> {
FieldView(
name = item.name,
value = item.value,

View file

@ -1,4 +1,4 @@
package com.x8bit.bitwarden.ui.vault.feature.additem
package com.x8bit.bitwarden.ui.vault.feature.addedit
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.platform.ClipboardManager
@ -34,7 +34,7 @@ import com.x8bit.bitwarden.ui.util.isProgressBar
import com.x8bit.bitwarden.ui.util.onAllNodesWithTextAfterScroll
import com.x8bit.bitwarden.ui.util.onNodeWithContentDescriptionAfterScroll
import com.x8bit.bitwarden.ui.util.onNodeWithTextAfterScroll
import com.x8bit.bitwarden.ui.vault.feature.additem.model.CustomFieldType
import com.x8bit.bitwarden.ui.vault.feature.addedit.model.CustomFieldType
import com.x8bit.bitwarden.ui.vault.model.VaultAddEditType
import io.mockk.every
import io.mockk.just
@ -48,19 +48,19 @@ import org.junit.Before
import org.junit.Test
@Suppress("LargeClass")
class VaultAddItemScreenTest : BaseComposeTest() {
class VaultAddEditScreenTest : BaseComposeTest() {
private var onNavigateBackCalled = false
private var onNavigateQrCodeScanScreenCalled = false
private val clipboardManager = mockk<ClipboardManager>()
private val mutableEventFlow = bufferedMutableSharedFlow<VaultAddItemEvent>()
private val mutableEventFlow = bufferedMutableSharedFlow<VaultAddEditEvent>()
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE_LOGIN)
private val fakePermissionManager: FakePermissionManager = FakePermissionManager()
private val viewModel = mockk<VaultAddItemViewModel>(relaxed = true) {
private val viewModel = mockk<VaultAddEditViewModel>(relaxed = true) {
every { eventFlow } returns mutableEventFlow
every { stateFlow } returns mutableStateFlow
}
@ -68,7 +68,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
@Before
fun setup() {
composeTestRule.setContent {
VaultAddItemScreen(
VaultAddEditScreen(
viewModel = viewModel,
onNavigateBack = { onNavigateBackCalled = true },
permissionsManager = fakePermissionManager,
@ -82,14 +82,14 @@ class VaultAddItemScreenTest : BaseComposeTest() {
@Test
fun `on NavigateBack event should invoke onNavigateBack`() {
mutableEventFlow.tryEmit(VaultAddItemEvent.NavigateBack)
mutableEventFlow.tryEmit(VaultAddEditEvent.NavigateBack)
assertTrue(onNavigateBackCalled)
}
@Suppress("MaxLineLength")
@Test
fun `on NavigateToQrCodeScan event should invoke NavigateToQrCodeScan`() {
mutableEventFlow.tryEmit(VaultAddItemEvent.NavigateToQrCodeScan)
mutableEventFlow.tryEmit(VaultAddEditEvent.NavigateToQrCodeScan)
assertTrue(onNavigateQrCodeScanScreenCalled)
}
@ -99,7 +99,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
every { clipboardManager.setText(textString.toAnnotatedString()) } just runs
mutableEventFlow.tryEmit(VaultAddItemEvent.CopyToClipboard(textString))
mutableEventFlow.tryEmit(VaultAddEditEvent.CopyToClipboard(textString))
verify(exactly = 1) {
clipboardManager.setText(textString.toAnnotatedString())
@ -114,7 +114,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.CloseClick,
VaultAddEditAction.Common.CloseClick,
)
}
}
@ -127,7 +127,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.SaveClick,
VaultAddEditAction.Common.SaveClick,
)
}
}
@ -143,7 +143,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.DismissDialog,
VaultAddEditAction.Common.DismissDialog,
)
}
}
@ -169,22 +169,22 @@ class VaultAddItemScreenTest : BaseComposeTest() {
fun `error text and retry should be displayed according to state`() {
val message = "error_message"
mutableStateFlow.update {
it.copy(viewState = VaultAddItemState.ViewState.Loading)
it.copy(viewState = VaultAddEditState.ViewState.Loading)
}
composeTestRule.onNodeWithText(message).assertIsNotDisplayed()
mutableStateFlow.update {
it.copy(
viewState = VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(),
type = VaultAddItemState.ViewState.Content.ItemType.Login(),
viewState = VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(),
type = VaultAddEditState.ViewState.Content.ItemType.Login(),
),
)
}
composeTestRule.onNodeWithText(message).assertIsNotDisplayed()
mutableStateFlow.update {
it.copy(viewState = VaultAddItemState.ViewState.Error(message.asText()))
it.copy(viewState = VaultAddEditState.ViewState.Error(message.asText()))
}
composeTestRule.onNodeWithText(message).assertIsDisplayed()
}
@ -192,20 +192,20 @@ class VaultAddItemScreenTest : BaseComposeTest() {
@Test
fun `progressbar should be displayed according to state`() {
mutableStateFlow.update {
it.copy(viewState = VaultAddItemState.ViewState.Loading)
it.copy(viewState = VaultAddEditState.ViewState.Loading)
}
composeTestRule.onNode(isProgressBar).assertIsDisplayed()
mutableStateFlow.update {
it.copy(viewState = VaultAddItemState.ViewState.Error("Fail".asText()))
it.copy(viewState = VaultAddEditState.ViewState.Error("Fail".asText()))
}
composeTestRule.onNode(isProgressBar).assertDoesNotExist()
mutableStateFlow.update {
it.copy(
viewState = VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(),
type = VaultAddItemState.ViewState.Content.ItemType.Login(),
viewState = VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(),
type = VaultAddEditState.ViewState.Content.ItemType.Login(),
),
)
}
@ -228,7 +228,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.TypeOptionSelect(VaultAddItemState.ItemTypeOption.LOGIN),
VaultAddEditAction.Common.TypeOptionSelect(VaultAddEditState.ItemTypeOption.LOGIN),
)
}
}
@ -241,9 +241,9 @@ class VaultAddItemScreenTest : BaseComposeTest() {
mutableStateFlow.update {
it.copy(
viewState = VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(),
type = VaultAddItemState.ViewState.Content.ItemType.Card,
viewState = VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(),
type = VaultAddEditState.ViewState.Content.ItemType.Card,
),
)
}
@ -261,7 +261,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.UsernameTextChange(username = "TestUsername"),
VaultAddEditAction.ItemType.LoginType.UsernameTextChange(username = "TestUsername"),
)
}
}
@ -290,7 +290,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.OpenUsernameGeneratorClick,
VaultAddEditAction.ItemType.LoginType.OpenUsernameGeneratorClick,
)
}
}
@ -305,7 +305,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
.performClick()
verify {
viewModel.trySendAction(VaultAddItemAction.ItemType.LoginType.PasswordCheckerClick)
viewModel.trySendAction(VaultAddEditAction.ItemType.LoginType.PasswordCheckerClick)
}
}
@ -320,7 +320,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.OpenPasswordGeneratorClick,
VaultAddEditAction.ItemType.LoginType.OpenPasswordGeneratorClick,
)
}
}
@ -333,7 +333,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.PasswordTextChange("TestPassword"),
VaultAddEditAction.ItemType.LoginType.PasswordTextChange("TestPassword"),
)
}
}
@ -396,7 +396,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.CopyTotpKeyClick(testCode),
VaultAddEditAction.ItemType.LoginType.CopyTotpKeyClick(testCode),
)
}
}
@ -418,7 +418,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.SetupTotpClick(
VaultAddEditAction.ItemType.LoginType.SetupTotpClick(
isGranted = fakePermissionManager.getPermissionsResult,
),
)
@ -455,7 +455,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.SetupTotpClick(true),
VaultAddEditAction.ItemType.LoginType.SetupTotpClick(true),
)
}
}
@ -472,7 +472,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.SetupTotpClick(
VaultAddEditAction.ItemType.LoginType.SetupTotpClick(
isGranted = true,
),
)
@ -491,7 +491,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.SetupTotpClick(
VaultAddEditAction.ItemType.LoginType.SetupTotpClick(
isGranted = false,
),
)
@ -506,7 +506,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.UriTextChange("TestURI"),
VaultAddEditAction.ItemType.LoginType.UriTextChange("TestURI"),
)
}
}
@ -537,7 +537,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.UriSettingsClick,
VaultAddEditAction.ItemType.LoginType.UriSettingsClick,
)
}
}
@ -550,7 +550,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.LoginType.AddNewUriClick,
VaultAddEditAction.ItemType.LoginType.AddNewUriClick,
)
}
}
@ -572,8 +572,8 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.TitleSelected(
title = VaultAddItemState.ViewState.Content.ItemType.Identity.Title.MX,
VaultAddEditAction.ItemType.IdentityType.TitleSelected(
title = VaultAddEditState.ViewState.Content.ItemType.Identity.Title.MX,
),
)
}
@ -589,7 +589,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
mutableStateFlow.update { currentState ->
updateIdentityType(currentState) {
copy(
selectedTitle = VaultAddItemState.ViewState.Content.ItemType.Identity.Title.MX,
selectedTitle = VaultAddEditState.ViewState.Content.ItemType.Identity.Title.MX,
)
}
}
@ -609,7 +609,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.FirstNameTextChange(
VaultAddEditAction.ItemType.IdentityType.FirstNameTextChange(
firstName = "TestFirstName",
),
)
@ -643,7 +643,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.MiddleNameTextChange(
VaultAddEditAction.ItemType.IdentityType.MiddleNameTextChange(
middleName = "TestMiddleName",
),
)
@ -677,7 +677,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.LastNameTextChange(
VaultAddEditAction.ItemType.IdentityType.LastNameTextChange(
lastName = "TestLastName",
),
)
@ -710,7 +710,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.UsernameTextChange(
VaultAddEditAction.ItemType.IdentityType.UsernameTextChange(
username = "TestUsername",
),
)
@ -743,7 +743,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.CompanyTextChange(
VaultAddEditAction.ItemType.IdentityType.CompanyTextChange(
company = "TestCompany",
),
)
@ -776,7 +776,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.SsnTextChange(
VaultAddEditAction.ItemType.IdentityType.SsnTextChange(
ssn = "TestSsn",
),
)
@ -809,7 +809,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.PassportNumberTextChange(
VaultAddEditAction.ItemType.IdentityType.PassportNumberTextChange(
passportNumber = "TestPassportNumber",
),
)
@ -843,7 +843,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.LicenseNumberTextChange(
VaultAddEditAction.ItemType.IdentityType.LicenseNumberTextChange(
licenseNumber = "TestLicenseNumber",
),
)
@ -876,7 +876,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.EmailTextChange(
VaultAddEditAction.ItemType.IdentityType.EmailTextChange(
email = "TestEmail",
),
)
@ -909,7 +909,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.Address1TextChange(
VaultAddEditAction.ItemType.IdentityType.Address1TextChange(
address1 = "TestAddress1",
),
)
@ -942,7 +942,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.Address2TextChange(
VaultAddEditAction.ItemType.IdentityType.Address2TextChange(
address2 = "TestAddress2",
),
)
@ -975,7 +975,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.Address3TextChange(
VaultAddEditAction.ItemType.IdentityType.Address3TextChange(
address3 = "TestAddress3",
),
)
@ -1008,7 +1008,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.CityTextChange(
VaultAddEditAction.ItemType.IdentityType.CityTextChange(
city = "TestCity",
),
)
@ -1041,7 +1041,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.ZipTextChange(
VaultAddEditAction.ItemType.IdentityType.ZipTextChange(
zip = "TestZip",
),
)
@ -1074,7 +1074,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.CountryTextChange(
VaultAddEditAction.ItemType.IdentityType.CountryTextChange(
country = "TestCountry",
),
)
@ -1090,7 +1090,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.ItemType.IdentityType.StateTextChange(
VaultAddEditAction.ItemType.IdentityType.StateTextChange(
state = "TestState",
),
)
@ -1158,7 +1158,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.AddNewCustomFieldClick(
VaultAddEditAction.Common.AddNewCustomFieldClick(
customFieldType = CustomFieldType.LINKED,
name = "TestLinked",
),
@ -1184,7 +1184,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.OwnershipChange("a@b.com"),
VaultAddEditAction.Common.OwnershipChange("a@b.com"),
)
}
}
@ -1216,7 +1216,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.NameTextChange(name = "TestName"),
VaultAddEditAction.Common.NameTextChange(name = "TestName"),
)
}
}
@ -1256,7 +1256,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.FolderChange("Folder 1".asText()),
VaultAddEditAction.Common.FolderChange("Folder 1".asText()),
)
}
}
@ -1290,7 +1290,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.ToggleFavorite(
VaultAddEditAction.Common.ToggleFavorite(
isFavorite = true,
),
)
@ -1327,7 +1327,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.ToggleMasterPasswordReprompt(
VaultAddEditAction.Common.ToggleMasterPasswordReprompt(
isMasterPasswordReprompt = true,
),
)
@ -1362,7 +1362,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.TooltipClick,
VaultAddEditAction.Common.TooltipClick,
)
}
}
@ -1378,7 +1378,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.NotesTextChange("TestNotes"),
VaultAddEditAction.Common.NotesTextChange("TestNotes"),
)
}
}
@ -1421,7 +1421,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.OwnershipChange("a@b.com"),
VaultAddEditAction.Common.OwnershipChange("a@b.com"),
)
}
}
@ -1472,7 +1472,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.AddNewCustomFieldClick(
VaultAddEditAction.Common.AddNewCustomFieldClick(
customFieldType = CustomFieldType.TEXT,
name = "TestText",
),
@ -1527,7 +1527,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.AddNewCustomFieldClick(
VaultAddEditAction.Common.AddNewCustomFieldClick(
customFieldType = CustomFieldType.BOOLEAN,
name = "TestBoolean",
),
@ -1563,7 +1563,7 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.AddNewCustomFieldClick(
VaultAddEditAction.Common.AddNewCustomFieldClick(
customFieldType = CustomFieldType.HIDDEN,
name = "TestHidden",
),
@ -1582,8 +1582,8 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.CustomFieldValueChange(
VaultAddItemState.Custom.TextField("Test ID", "TestText", ""),
VaultAddEditAction.Common.CustomFieldValueChange(
VaultAddEditState.Custom.TextField("Test ID", "TestText", ""),
),
)
}
@ -1600,8 +1600,8 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.CustomFieldValueChange(
VaultAddItemState.Custom.HiddenField("Test ID", "TestHidden", ""),
VaultAddEditAction.Common.CustomFieldValueChange(
VaultAddEditState.Custom.HiddenField("Test ID", "TestHidden", ""),
),
)
}
@ -1618,8 +1618,8 @@ class VaultAddItemScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
VaultAddItemAction.Common.CustomFieldValueChange(
VaultAddItemState.Custom.BooleanField("Test ID", "TestBoolean", true),
VaultAddEditAction.Common.CustomFieldValueChange(
VaultAddEditState.Custom.BooleanField("Test ID", "TestBoolean", true),
),
)
}
@ -1628,14 +1628,14 @@ class VaultAddItemScreenTest : BaseComposeTest() {
//region Helper functions
private fun updateLoginType(
currentState: VaultAddItemState,
transform: VaultAddItemState.ViewState.Content.ItemType.Login.() ->
VaultAddItemState.ViewState.Content.ItemType.Login,
): VaultAddItemState {
currentState: VaultAddEditState,
transform: VaultAddEditState.ViewState.Content.ItemType.Login.() ->
VaultAddEditState.ViewState.Content.ItemType.Login,
): VaultAddEditState {
val updatedType = when (val viewState = currentState.viewState) {
is VaultAddItemState.ViewState.Content -> {
is VaultAddEditState.ViewState.Content -> {
when (val type = viewState.type) {
is VaultAddItemState.ViewState.Content.ItemType.Login -> {
is VaultAddEditState.ViewState.Content.ItemType.Login -> {
viewState.copy(
type = type.transform(),
)
@ -1651,14 +1651,14 @@ class VaultAddItemScreenTest : BaseComposeTest() {
}
private fun updateIdentityType(
currentState: VaultAddItemState,
transform: VaultAddItemState.ViewState.Content.ItemType.Identity.() ->
VaultAddItemState.ViewState.Content.ItemType.Identity,
): VaultAddItemState {
currentState: VaultAddEditState,
transform: VaultAddEditState.ViewState.Content.ItemType.Identity.() ->
VaultAddEditState.ViewState.Content.ItemType.Identity,
): VaultAddEditState {
val updatedType = when (val viewState = currentState.viewState) {
is VaultAddItemState.ViewState.Content -> {
is VaultAddEditState.ViewState.Content -> {
when (val type = viewState.type) {
is VaultAddItemState.ViewState.Content.ItemType.Identity -> {
is VaultAddEditState.ViewState.Content.ItemType.Identity -> {
viewState.copy(
type = type.transform(),
)
@ -1675,12 +1675,12 @@ class VaultAddItemScreenTest : BaseComposeTest() {
@Suppress("MaxLineLength")
private fun updateCommonContent(
currentState: VaultAddItemState,
transform: VaultAddItemState.ViewState.Content.Common.()
-> VaultAddItemState.ViewState.Content.Common,
): VaultAddItemState {
currentState: VaultAddEditState,
transform: VaultAddEditState.ViewState.Content.Common.()
-> VaultAddEditState.ViewState.Content.Common,
): VaultAddEditState {
val updatedType = when (val viewState = currentState.viewState) {
is VaultAddItemState.ViewState.Content ->
is VaultAddEditState.ViewState.Content ->
viewState.copy(common = viewState.common.transform())
else -> viewState
@ -1691,58 +1691,58 @@ class VaultAddItemScreenTest : BaseComposeTest() {
//endregion Helper functions
companion object {
private val DEFAULT_STATE_LOGIN_DIALOG = VaultAddItemState(
viewState = VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(),
type = VaultAddItemState.ViewState.Content.ItemType.Login(),
private val DEFAULT_STATE_LOGIN_DIALOG = VaultAddEditState(
viewState = VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(),
type = VaultAddEditState.ViewState.Content.ItemType.Login(),
),
dialog = VaultAddItemState.DialogState.Error("test".asText()),
dialog = VaultAddEditState.DialogState.Error("test".asText()),
vaultAddEditType = VaultAddEditType.AddItem,
)
private val DEFAULT_STATE_LOGIN = VaultAddItemState(
private val DEFAULT_STATE_LOGIN = VaultAddEditState(
vaultAddEditType = VaultAddEditType.AddItem,
viewState = VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(),
type = VaultAddItemState.ViewState.Content.ItemType.Login(),
viewState = VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(),
type = VaultAddEditState.ViewState.Content.ItemType.Login(),
),
dialog = null,
)
private val DEFAULT_STATE_IDENTITY = VaultAddItemState(
private val DEFAULT_STATE_IDENTITY = VaultAddEditState(
vaultAddEditType = VaultAddEditType.AddItem,
viewState = VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(),
type = VaultAddItemState.ViewState.Content.ItemType.Identity(),
viewState = VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(),
type = VaultAddEditState.ViewState.Content.ItemType.Identity(),
),
dialog = null,
)
@Suppress("MaxLineLength")
private val DEFAULT_STATE_SECURE_NOTES_CUSTOM_FIELDS = VaultAddItemState(
viewState = VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(
private val DEFAULT_STATE_SECURE_NOTES_CUSTOM_FIELDS = VaultAddEditState(
viewState = VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(
customFieldData = listOf(
VaultAddItemState.Custom.BooleanField("Test ID", "TestBoolean", false),
VaultAddItemState.Custom.TextField("Test ID", "TestText", "TestTextVal"),
VaultAddItemState.Custom.HiddenField(
VaultAddEditState.Custom.BooleanField("Test ID", "TestBoolean", false),
VaultAddEditState.Custom.TextField("Test ID", "TestText", "TestTextVal"),
VaultAddEditState.Custom.HiddenField(
"Test ID",
"TestHidden",
"TestHiddenVal",
),
),
),
type = VaultAddItemState.ViewState.Content.ItemType.SecureNotes,
type = VaultAddEditState.ViewState.Content.ItemType.SecureNotes,
),
dialog = null,
vaultAddEditType = VaultAddEditType.AddItem,
)
private val DEFAULT_STATE_SECURE_NOTES = VaultAddItemState(
private val DEFAULT_STATE_SECURE_NOTES = VaultAddEditState(
vaultAddEditType = VaultAddEditType.AddItem,
viewState = VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(),
type = VaultAddItemState.ViewState.Content.ItemType.SecureNotes,
viewState = VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(),
type = VaultAddEditState.ViewState.Content.ItemType.SecureNotes,
),
dialog = null,
)

View file

@ -1,6 +1,6 @@
package com.x8bit.bitwarden.ui.vault.feature.additem.model
package com.x8bit.bitwarden.ui.vault.feature.addedit.model
import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemState
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditState
import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType
import io.mockk.every
import io.mockk.mockkStatic
@ -30,7 +30,7 @@ class CustomFieldTypeTests {
val name = "test"
val type = CustomFieldType.BOOLEAN
val expected = VaultAddItemState.Custom.BooleanField(TEST_ID, "test", false)
val expected = VaultAddEditState.Custom.BooleanField(TEST_ID, "test", false)
val actual = type.toCustomField(name)
assertEquals(expected, actual)
@ -42,7 +42,7 @@ class CustomFieldTypeTests {
val type = CustomFieldType.LINKED
val expected =
VaultAddItemState.Custom.LinkedField(TEST_ID, "test", VaultLinkedFieldType.USERNAME)
VaultAddEditState.Custom.LinkedField(TEST_ID, "test", VaultLinkedFieldType.USERNAME)
val actual = type.toCustomField(name)
assertEquals(expected, actual)
@ -53,7 +53,7 @@ class CustomFieldTypeTests {
val name = "test"
val type = CustomFieldType.TEXT
val expected = VaultAddItemState.Custom.TextField(TEST_ID, "test", "")
val expected = VaultAddEditState.Custom.TextField(TEST_ID, "test", "")
val actual = type.toCustomField(name)
assertEquals(expected, actual)
@ -64,7 +64,7 @@ class CustomFieldTypeTests {
val name = "test"
val type = CustomFieldType.HIDDEN
val expected = VaultAddItemState.Custom.HiddenField(TEST_ID, "test", "")
val expected = VaultAddEditState.Custom.HiddenField(TEST_ID, "test", "")
val actual = type.toCustomField(name)
assertEquals(expected, actual)

View file

@ -1,4 +1,4 @@
package com.x8bit.bitwarden.ui.vault.feature.additem.util
package com.x8bit.bitwarden.ui.vault.feature.addedit.util
import com.bitwarden.core.CardView
import com.bitwarden.core.CipherRepromptType
@ -14,7 +14,7 @@ import com.bitwarden.core.SecureNoteType
import com.bitwarden.core.SecureNoteView
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.ui.platform.base.util.asText
import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemState
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditState
import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType
import io.mockk.every
import io.mockk.mockkStatic
@ -46,8 +46,8 @@ class CipherViewExtensionsTest {
val result = cipherView.toViewState()
assertEquals(
VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(
VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(
originalCipher = cipherView,
name = "cipher",
folderName = R.string.folder_none.asText(),
@ -56,10 +56,10 @@ class CipherViewExtensionsTest {
notes = "Lots of notes",
ownership = "",
customFieldData = listOf(
VaultAddItemState.Custom.BooleanField(TEST_ID, "TestBoolean", false),
VaultAddItemState.Custom.TextField(TEST_ID, "TestText", "TestText"),
VaultAddItemState.Custom.HiddenField(TEST_ID, "TestHidden", "TestHidden"),
VaultAddItemState.Custom.LinkedField(
VaultAddEditState.Custom.BooleanField(TEST_ID, "TestBoolean", false),
VaultAddEditState.Custom.TextField(TEST_ID, "TestText", "TestText"),
VaultAddEditState.Custom.HiddenField(TEST_ID, "TestHidden", "TestHidden"),
VaultAddEditState.Custom.LinkedField(
TEST_ID,
"TestLinked",
VaultLinkedFieldType.USERNAME,
@ -68,7 +68,7 @@ class CipherViewExtensionsTest {
availableFolders = emptyList(),
availableOwners = emptyList(),
),
type = VaultAddItemState.ViewState.Content.ItemType.Card,
type = VaultAddEditState.ViewState.Content.ItemType.Card,
),
result,
)
@ -81,8 +81,8 @@ class CipherViewExtensionsTest {
val result = cipherView.toViewState()
assertEquals(
VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(
VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(
originalCipher = cipherView,
name = "cipher",
folderName = R.string.folder_none.asText(),
@ -91,10 +91,10 @@ class CipherViewExtensionsTest {
notes = "Lots of notes",
ownership = "",
customFieldData = listOf(
VaultAddItemState.Custom.BooleanField(TEST_ID, "TestBoolean", false),
VaultAddItemState.Custom.TextField(TEST_ID, "TestText", "TestText"),
VaultAddItemState.Custom.HiddenField(TEST_ID, "TestHidden", "TestHidden"),
VaultAddItemState.Custom.LinkedField(
VaultAddEditState.Custom.BooleanField(TEST_ID, "TestBoolean", false),
VaultAddEditState.Custom.TextField(TEST_ID, "TestText", "TestText"),
VaultAddEditState.Custom.HiddenField(TEST_ID, "TestHidden", "TestHidden"),
VaultAddEditState.Custom.LinkedField(
TEST_ID,
"TestLinked",
VaultLinkedFieldType.USERNAME,
@ -103,7 +103,7 @@ class CipherViewExtensionsTest {
availableFolders = emptyList(),
availableOwners = emptyList(),
),
type = VaultAddItemState.ViewState.Content.ItemType.Identity(
type = VaultAddEditState.ViewState.Content.ItemType.Identity(
firstName = "John",
middleName = "Richard",
lastName = "Smith",
@ -127,8 +127,8 @@ class CipherViewExtensionsTest {
val result = cipherView.toViewState()
assertEquals(
VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(
VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(
originalCipher = cipherView,
name = "cipher",
folderName = R.string.folder_none.asText(),
@ -139,17 +139,17 @@ class CipherViewExtensionsTest {
availableFolders = emptyList(),
availableOwners = emptyList(),
customFieldData = listOf(
VaultAddItemState.Custom.BooleanField(TEST_ID, "TestBoolean", false),
VaultAddItemState.Custom.TextField(TEST_ID, "TestText", "TestText"),
VaultAddItemState.Custom.HiddenField(TEST_ID, "TestHidden", "TestHidden"),
VaultAddItemState.Custom.LinkedField(
VaultAddEditState.Custom.BooleanField(TEST_ID, "TestBoolean", false),
VaultAddEditState.Custom.TextField(TEST_ID, "TestText", "TestText"),
VaultAddEditState.Custom.HiddenField(TEST_ID, "TestHidden", "TestHidden"),
VaultAddEditState.Custom.LinkedField(
TEST_ID,
"TestLinked",
VaultLinkedFieldType.USERNAME,
),
),
),
type = VaultAddItemState.ViewState.Content.ItemType.Login(
type = VaultAddEditState.ViewState.Content.ItemType.Login(
username = "username",
password = "password",
uri = "www.example.com",
@ -167,8 +167,8 @@ class CipherViewExtensionsTest {
val result = cipherView.toViewState()
assertEquals(
VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(
VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(
originalCipher = cipherView,
name = "cipher",
folderName = R.string.folder_none.asText(),
@ -177,14 +177,14 @@ class CipherViewExtensionsTest {
notes = "Lots of notes",
ownership = "",
customFieldData = listOf(
VaultAddItemState.Custom.BooleanField(TEST_ID, "TestBoolean", false),
VaultAddItemState.Custom.TextField(TEST_ID, "TestText", "TestText"),
VaultAddItemState.Custom.HiddenField(TEST_ID, "TestHidden", "TestHidden"),
VaultAddEditState.Custom.BooleanField(TEST_ID, "TestBoolean", false),
VaultAddEditState.Custom.TextField(TEST_ID, "TestText", "TestText"),
VaultAddEditState.Custom.HiddenField(TEST_ID, "TestHidden", "TestHidden"),
),
availableFolders = emptyList(),
availableOwners = emptyList(),
),
type = VaultAddItemState.ViewState.Content.ItemType.SecureNotes,
type = VaultAddEditState.ViewState.Content.ItemType.SecureNotes,
),
result,
)

View file

@ -13,7 +13,7 @@ import com.bitwarden.core.SecureNoteType
import com.bitwarden.core.SecureNoteView
import com.bitwarden.core.UriMatchType
import com.x8bit.bitwarden.ui.platform.base.util.asText
import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemState
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditState
import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType
import io.mockk.every
import io.mockk.mockkStatic
@ -37,8 +37,8 @@ class VaultAddItemStateExtensionsTest {
mockkStatic(Instant::class)
every { Instant.now() } returns Instant.MIN
val loginItemType = VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(
val loginItemType = VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(
name = "mockName-1",
folderName = "mockFolder-1".asText(),
favorite = false,
@ -46,7 +46,7 @@ class VaultAddItemStateExtensionsTest {
notes = "mockNotes-1",
ownership = "mockOwnership-1",
),
type = VaultAddItemState.ViewState.Content.ItemType.Login(
type = VaultAddEditState.ViewState.Content.ItemType.Login(
username = "mockUsername-1",
password = "mockPassword-1",
uri = "mockUri-1",
@ -103,18 +103,18 @@ class VaultAddItemStateExtensionsTest {
@Test
fun `toCipherView should transform Login ItemType to CipherView with original cipher`() {
val cipherView = DEFAULT_LOGIN_CIPHER_VIEW
val viewState = VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(
val viewState = VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(
originalCipher = cipherView,
name = "mockName-1",
folderName = "mockFolder-1".asText(),
favorite = true,
masterPasswordReprompt = false,
customFieldData = listOf(
VaultAddItemState.Custom.BooleanField("testId", "TestBoolean", false),
VaultAddItemState.Custom.TextField("testId", "TestText", "TestText"),
VaultAddItemState.Custom.HiddenField("testId", "TestHidden", "TestHidden"),
VaultAddItemState.Custom.LinkedField(
VaultAddEditState.Custom.BooleanField("testId", "TestBoolean", false),
VaultAddEditState.Custom.TextField("testId", "TestText", "TestText"),
VaultAddEditState.Custom.HiddenField("testId", "TestHidden", "TestHidden"),
VaultAddEditState.Custom.LinkedField(
"testId",
"TestLinked",
VaultLinkedFieldType.USERNAME,
@ -123,7 +123,7 @@ class VaultAddItemStateExtensionsTest {
notes = "mockNotes-1",
ownership = "mockOwnership-1",
),
type = VaultAddItemState.ViewState.Content.ItemType.Login(
type = VaultAddEditState.ViewState.Content.ItemType.Login(
username = "mockUsername-1",
password = "mockPassword-1",
uri = "mockUri-1",
@ -195,8 +195,8 @@ class VaultAddItemStateExtensionsTest {
fun `toCipherView should transform SecureNotes ItemType to CipherView`() {
mockkStatic(Instant::class)
every { Instant.now() } returns Instant.MIN
val viewState = VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(
val viewState = VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(
name = "mockName-1",
folderName = "mockFolder-1".asText(),
favorite = false,
@ -204,12 +204,12 @@ class VaultAddItemStateExtensionsTest {
notes = "mockNotes-1",
ownership = "mockOwnership-1",
customFieldData = listOf(
VaultAddItemState.Custom.BooleanField("testId", "TestBoolean", false),
VaultAddItemState.Custom.TextField("testId", "TestText", "TestText"),
VaultAddItemState.Custom.HiddenField("testId", "TestHidden", "TestHidden"),
VaultAddEditState.Custom.BooleanField("testId", "TestBoolean", false),
VaultAddEditState.Custom.TextField("testId", "TestText", "TestText"),
VaultAddEditState.Custom.HiddenField("testId", "TestHidden", "TestHidden"),
),
),
type = VaultAddItemState.ViewState.Content.ItemType.SecureNotes,
type = VaultAddEditState.ViewState.Content.ItemType.SecureNotes,
)
val result = viewState.toCipherView()
@ -267,8 +267,8 @@ class VaultAddItemStateExtensionsTest {
@Test
fun `toCipherView should transform SecureNotes ItemType to CipherView with original cipher`() {
val cipherView = DEFAULT_SECURE_NOTES_CIPHER_VIEW
val viewState = VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(
val viewState = VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(
originalCipher = cipherView,
name = "mockName-1",
folderName = "mockFolder-1".asText(),
@ -278,7 +278,7 @@ class VaultAddItemStateExtensionsTest {
ownership = "mockOwnership-1",
customFieldData = emptyList(),
),
type = VaultAddItemState.ViewState.Content.ItemType.SecureNotes,
type = VaultAddEditState.ViewState.Content.ItemType.SecureNotes,
)
val result = viewState.toCipherView()
@ -300,8 +300,8 @@ class VaultAddItemStateExtensionsTest {
fun `toCipherView should transform Identity ItemType to CipherView`() {
mockkStatic(Instant::class)
every { Instant.now() } returns Instant.MIN
val viewState = VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(
val viewState = VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(
name = "mockName-1",
folderName = "mockFolder-1".asText(),
favorite = false,
@ -309,8 +309,8 @@ class VaultAddItemStateExtensionsTest {
notes = "mockNotes-1",
ownership = "mockOwnership-1",
),
type = VaultAddItemState.ViewState.Content.ItemType.Identity(
selectedTitle = VaultAddItemState.ViewState.Content.ItemType.Identity.Title.MR,
type = VaultAddEditState.ViewState.Content.ItemType.Identity(
selectedTitle = VaultAddEditState.ViewState.Content.ItemType.Identity.Title.MR,
firstName = "mockFirstName",
lastName = "mockLastName",
middleName = "mockMiddleName",
@ -386,18 +386,18 @@ class VaultAddItemStateExtensionsTest {
@Test
fun `toCipherView should transform Identity ItemType to CipherView with original cipher`() {
val cipherView = DEFAULT_IDENTITY_CIPHER_VIEW
val viewState = VaultAddItemState.ViewState.Content(
common = VaultAddItemState.ViewState.Content.Common(
val viewState = VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(
originalCipher = cipherView,
name = "mockName-1",
folderName = "mockFolder-1".asText(),
favorite = true,
masterPasswordReprompt = false,
customFieldData = listOf(
VaultAddItemState.Custom.BooleanField("testId", "TestBoolean", false),
VaultAddItemState.Custom.TextField("testId", "TestText", "TestText"),
VaultAddItemState.Custom.HiddenField("testId", "TestHidden", "TestHidden"),
VaultAddItemState.Custom.LinkedField(
VaultAddEditState.Custom.BooleanField("testId", "TestBoolean", false),
VaultAddEditState.Custom.TextField("testId", "TestText", "TestText"),
VaultAddEditState.Custom.HiddenField("testId", "TestHidden", "TestHidden"),
VaultAddEditState.Custom.LinkedField(
"testId",
"TestLinked",
VaultLinkedFieldType.USERNAME,
@ -406,8 +406,8 @@ class VaultAddItemStateExtensionsTest {
notes = "mockNotes-1",
ownership = "mockOwnership-1",
),
type = VaultAddItemState.ViewState.Content.ItemType.Identity(
selectedTitle = VaultAddItemState.ViewState.Content.ItemType.Identity.Title.MR,
type = VaultAddEditState.ViewState.Content.ItemType.Identity(
selectedTitle = VaultAddEditState.ViewState.Content.ItemType.Identity.Title.MR,
firstName = "mockFirstName",
lastName = "mockLastName",
middleName = "mockMiddleName",