BIT-2269: Make all lists in Composables immutable (#1319)

This commit is contained in:
Caleb Derosier 2024-04-30 13:47:26 -06:00 committed by Álison Fernandes
parent 13d31c6ce8
commit b0cae8e553
7 changed files with 22 additions and 13 deletions

View file

@ -41,6 +41,8 @@ import com.x8bit.bitwarden.ui.platform.components.content.BitwardenLoadingConten
import com.x8bit.bitwarden.ui.platform.components.scaffold.BitwardenScaffold
import com.x8bit.bitwarden.ui.platform.components.util.rememberVectorPainter
import com.x8bit.bitwarden.ui.platform.feature.settings.folders.model.FolderDisplayItem
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
/**
* Displays the folders screen.
@ -106,7 +108,7 @@ fun FoldersScreen(
when (val viewState = state.value.viewState) {
is FoldersState.ViewState.Content -> {
FoldersContent(
foldersList = viewState.folderList,
foldersList = viewState.folderList.toImmutableList(),
onItemClick = remember(viewModel) {
{ viewModel.trySendAction(FoldersAction.FolderClick(it)) }
},
@ -138,7 +140,7 @@ fun FoldersScreen(
@Composable
private fun FoldersContent(
foldersList: List<FolderDisplayItem>,
foldersList: ImmutableList<FolderDisplayItem>,
onItemClick: (folderId: String) -> Unit,
modifier: Modifier = Modifier,
) {

View file

@ -80,6 +80,7 @@ import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorState.MainType.Pa
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorState.MainType.Username.UsernameType.ForwardedEmailAlias.ServiceType
import com.x8bit.bitwarden.ui.tools.feature.generator.GeneratorState.MainType.Username.UsernameType.ForwardedEmailAlias.ServiceTypeOption
import com.x8bit.bitwarden.ui.tools.feature.generator.model.GeneratorMode
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
@ -339,7 +340,7 @@ private fun ScrollContent(
Spacer(modifier = Modifier.height(8.dp))
MainStateOptionsItem(
selectedType = state.selectedType,
possibleMainStates = state.typeOptions,
possibleMainStates = state.typeOptions.toImmutableList(),
onMainStateOptionClicked = onMainStateOptionClicked,
)
}
@ -421,7 +422,7 @@ private fun GeneratedStringItem(
@Composable
private fun MainStateOptionsItem(
selectedType: GeneratorState.MainType,
possibleMainStates: List<GeneratorState.MainTypeOption>,
possibleMainStates: ImmutableList<GeneratorState.MainTypeOption>,
onMainStateOptionClicked: (GeneratorState.MainTypeOption) -> Unit,
) {
val optionsWithStrings = possibleMainStates.associateWith { stringResource(id = it.labelRes) }

View file

@ -20,6 +20,7 @@ import com.x8bit.bitwarden.ui.platform.components.model.IconData
import com.x8bit.bitwarden.ui.platform.components.text.BitwardenPolicyWarningText
import com.x8bit.bitwarden.ui.platform.components.util.rememberVectorPainter
import com.x8bit.bitwarden.ui.tools.feature.send.handlers.SendHandlers
import kotlinx.collections.immutable.toImmutableList
/**
* Content view for the [SendScreen].
@ -96,7 +97,7 @@ fun SendContent(
startIcon = IconData.Local(it.type.iconRes),
label = it.name,
supportingLabel = it.deletionDate,
trailingLabelIcons = it.iconList,
trailingLabelIcons = it.iconList.toImmutableList(),
showMoreOptions = !policyDisablesSend,
onClick = { sendHandlers.onSendClick(it) },
onCopyClick = { sendHandlers.onCopySendClick(it) },

View file

@ -19,6 +19,8 @@ import com.x8bit.bitwarden.ui.platform.components.model.IconResource
import com.x8bit.bitwarden.ui.platform.components.util.rememberVectorPainter
import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
import com.x8bit.bitwarden.ui.platform.util.persistentListOfNotNull
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toPersistentList
/**
@ -44,7 +46,7 @@ fun SendListItem(
label: String,
supportingLabel: String,
startIcon: IconData,
trailingLabelIcons: List<IconRes>,
trailingLabelIcons: ImmutableList<IconRes>,
showMoreOptions: Boolean,
onClick: () -> Unit,
onEditClick: () -> Unit,
@ -123,7 +125,7 @@ private fun SendListItem_preview() {
label = "Sample Label",
supportingLabel = "Jan 3, 2024, 10:35 AM",
startIcon = IconData.Local(R.drawable.ic_send_text),
trailingLabelIcons = emptyList(),
trailingLabelIcons = persistentListOf(),
showMoreOptions = true,
onClick = {},
onCopyClick = {},

View file

@ -20,6 +20,7 @@ import com.x8bit.bitwarden.ui.platform.components.model.toIconResources
import com.x8bit.bitwarden.ui.platform.components.util.rememberVectorPainter
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.model.ListingItemOverflowAction
import com.x8bit.bitwarden.ui.vault.feature.vault.handlers.VaultHandlers
import kotlinx.collections.immutable.toImmutableList
import kotlinx.collections.immutable.toPersistentList
/**
@ -88,7 +89,7 @@ fun VaultContent(
label = favoriteItem.name(),
supportingLabel = favoriteItem.supportingLabel?.invoke(),
onClick = { vaultHandlers.vaultItemClick(favoriteItem) },
overflowOptions = favoriteItem.overflowOptions,
overflowOptions = favoriteItem.overflowOptions.toImmutableList(),
onOverflowOptionClick = { action ->
if (favoriteItem.shouldShowMasterPasswordReprompt &&
action.requiresPasswordReprompt
@ -266,7 +267,7 @@ fun VaultContent(
label = noFolderItem.name(),
supportingLabel = noFolderItem.supportingLabel?.invoke(),
onClick = { vaultHandlers.vaultItemClick(noFolderItem) },
overflowOptions = noFolderItem.overflowOptions,
overflowOptions = noFolderItem.overflowOptions.toImmutableList(),
onOverflowOptionClick = { action ->
if (noFolderItem.shouldShowMasterPasswordReprompt &&
action.requiresPasswordReprompt

View file

@ -33,7 +33,7 @@ fun VaultEntryListItem(
startIconTestTag: String,
label: String,
onClick: () -> Unit,
overflowOptions: List<ListingItemOverflowAction.VaultAction>,
overflowOptions: ImmutableList<ListingItemOverflowAction.VaultAction>,
onOverflowOptionClick: (ListingItemOverflowAction.VaultAction) -> Unit,
modifier: Modifier = Modifier,
trailingLabelIcons: ImmutableList<IconResource> = persistentListOf(),
@ -68,7 +68,7 @@ private fun VaultEntryListItem_preview() {
label = "Example Login",
supportingLabel = "Username",
onClick = {},
overflowOptions = emptyList(),
overflowOptions = persistentListOf(),
onOverflowOptionClick = {},
modifier = Modifier,
)

View file

@ -33,7 +33,9 @@ import com.x8bit.bitwarden.ui.platform.components.header.BitwardenListHeaderText
import com.x8bit.bitwarden.ui.platform.components.scaffold.BitwardenScaffold
import com.x8bit.bitwarden.ui.platform.components.util.rememberVectorPainter
import com.x8bit.bitwarden.ui.vault.feature.verificationcode.handlers.VerificationCodeHandlers
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
/**
* Displays the verification codes to the user.
@ -114,7 +116,7 @@ fun VerificationCodeScreen(
when (val viewState = state.viewState) {
is VerificationCodeState.ViewState.Content -> {
VerificationCodeContent(
items = viewState.verificationCodeDisplayItems,
items = viewState.verificationCodeDisplayItems.toImmutableList(),
onCopyClick = verificationCodeHandler.copyClick,
itemClick = verificationCodeHandler.itemClick,
modifier = modifier,
@ -151,7 +153,7 @@ private fun VerificationCodeDialogs(
@Composable
private fun VerificationCodeContent(
items: List<VerificationCodeDisplayItem>,
items: ImmutableList<VerificationCodeDisplayItem>,
itemClick: (id: String) -> Unit,
onCopyClick: (text: String) -> Unit,
modifier: Modifier = Modifier,