mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 15:15:34 +03:00
Convert UI list to persistent list (#588)
This commit is contained in:
parent
5e2e23edec
commit
93c628ae38
6 changed files with 44 additions and 8 deletions
|
@ -31,6 +31,8 @@ import androidx.compose.ui.unit.dp
|
|||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.IconResource
|
||||
import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
|
||||
import kotlinx.collections.immutable.PersistentList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
|
||||
/**
|
||||
* A Composable function that displays a row item.
|
||||
|
@ -51,7 +53,7 @@ fun BitwardenListItem(
|
|||
label: String,
|
||||
startIcon: Painter,
|
||||
onClick: () -> Unit,
|
||||
selectionDataList: List<SelectionItemData>,
|
||||
selectionDataList: PersistentList<SelectionItemData>,
|
||||
modifier: Modifier = Modifier,
|
||||
supportingLabel: String? = null,
|
||||
trailingLabelIcons: List<IconResource> = emptyList(),
|
||||
|
@ -158,7 +160,7 @@ private fun BitwardenListItem_preview() {
|
|||
supportingLabel = "Jan 3, 2024, 10:35 AM",
|
||||
startIcon = painterResource(id = R.drawable.ic_send_text),
|
||||
onClick = {},
|
||||
selectionDataList = emptyList(),
|
||||
selectionDataList = persistentListOf(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package com.x8bit.bitwarden.ui.platform.util
|
||||
|
||||
import kotlinx.collections.immutable.PersistentList
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
|
||||
/**
|
||||
* Creates an immutable [PersistentList] of the given [elements] excluding the null ones.
|
||||
*/
|
||||
fun <T : Any> persistentListOfNotNull(vararg elements: T?): PersistentList<T> =
|
||||
elements.filterNotNull().toPersistentList()
|
|
@ -12,6 +12,7 @@ import com.x8bit.bitwarden.ui.platform.components.SelectionItemData
|
|||
import com.x8bit.bitwarden.ui.platform.components.model.IconResource
|
||||
import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
|
||||
import com.x8bit.bitwarden.ui.tools.feature.send.model.SendStatusIcon
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
|
||||
/**
|
||||
* A Composable function that displays a row send item.
|
||||
|
@ -50,7 +51,7 @@ fun SendListItem(
|
|||
)
|
||||
},
|
||||
onClick = onClick,
|
||||
selectionDataList = listOf(
|
||||
selectionDataList = persistentListOf(
|
||||
SelectionItemData(
|
||||
text = stringResource(id = R.string.edit),
|
||||
onClick = onEditClick,
|
||||
|
|
|
@ -31,8 +31,8 @@ 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.platform.components.OverflowMenuItemData
|
||||
import com.x8bit.bitwarden.ui.platform.util.persistentListOfNotNull
|
||||
import com.x8bit.bitwarden.ui.tools.feature.send.addsend.handlers.AddSendHandlers
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
|
||||
/**
|
||||
* Displays new send UX.
|
||||
|
@ -92,7 +92,7 @@ fun AddSendScreen(
|
|||
)
|
||||
if (!state.isAddMode) {
|
||||
BitwardenOverflowActionItem(
|
||||
menuItemDataList = listOfNotNull(
|
||||
menuItemDataList = persistentListOfNotNull(
|
||||
OverflowMenuItemData(
|
||||
text = stringResource(id = R.string.remove_password),
|
||||
onClick = remember(viewModel) {
|
||||
|
@ -122,8 +122,7 @@ fun AddSendScreen(
|
|||
{ viewModel.trySendAction(AddSendAction.DeleteClick) }
|
||||
},
|
||||
),
|
||||
)
|
||||
.toPersistentList(),
|
||||
),
|
||||
)
|
||||
}
|
||||
},
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.x8bit.bitwarden.R
|
|||
import com.x8bit.bitwarden.ui.platform.components.BitwardenListItem
|
||||
import com.x8bit.bitwarden.ui.platform.components.SelectionItemData
|
||||
import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
|
||||
/**
|
||||
* A Composable function that displays a row item for different types of vault entries.
|
||||
|
@ -36,7 +37,7 @@ fun VaultEntryListItem(
|
|||
supportingLabel = supportingLabel,
|
||||
startIcon = startIcon,
|
||||
onClick = onClick,
|
||||
selectionDataList = listOf(
|
||||
selectionDataList = persistentListOf(
|
||||
SelectionItemData(
|
||||
text = "Not yet implemented",
|
||||
onClick = {
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package com.x8bit.bitwarden.ui.platform.util
|
||||
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class PersistentListExtensionsTest {
|
||||
|
||||
@Test
|
||||
fun `PersistentListOfNotNull should filter out null values`() {
|
||||
val expected = persistentListOf("Hello", "World")
|
||||
|
||||
val result = persistentListOfNotNull(
|
||||
"Hello",
|
||||
null,
|
||||
"World",
|
||||
null,
|
||||
null,
|
||||
)
|
||||
|
||||
assertEquals(expected, result)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue