mirror of
https://github.com/bitwarden/android.git
synced 2026-06-06 06:17:21 -05:00
BIT-1301 Adding icons to collection items (#840)
This commit is contained in:
committed by
Álison Fernandes
parent
82ef39e15d
commit
2d652c8a2e
@@ -19,6 +19,7 @@ import com.x8bit.bitwarden.ui.platform.feature.search.SearchTypeData
|
||||
import com.x8bit.bitwarden.ui.platform.util.toFormattedPattern
|
||||
import com.x8bit.bitwarden.ui.tools.feature.send.util.toLabelIcons
|
||||
import com.x8bit.bitwarden.ui.tools.feature.send.util.toOverflowActions
|
||||
import com.x8bit.bitwarden.ui.vault.feature.util.toLabelIcons
|
||||
import com.x8bit.bitwarden.ui.vault.feature.util.toOverflowActions
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.util.toLoginIconData
|
||||
import java.time.Clock
|
||||
@@ -171,7 +172,7 @@ private fun CipherView.toDisplayItem(
|
||||
baseIconUrl = baseIconUrl,
|
||||
isIconLoadingDisabled = isIconLoadingDisabled,
|
||||
),
|
||||
extraIconList = emptyList(),
|
||||
extraIconList = toLabelIcons(),
|
||||
overflowOptions = toOverflowActions(),
|
||||
totpCode = login?.totp,
|
||||
)
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.x8bit.bitwarden.ui.platform.util.toFormattedPattern
|
||||
import com.x8bit.bitwarden.ui.tools.feature.send.util.toLabelIcons
|
||||
import com.x8bit.bitwarden.ui.tools.feature.send.util.toOverflowActions
|
||||
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.VaultItemListingState
|
||||
import com.x8bit.bitwarden.ui.vault.feature.util.toLabelIcons
|
||||
import com.x8bit.bitwarden.ui.vault.feature.util.toOverflowActions
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.util.toLoginIconData
|
||||
import java.time.Clock
|
||||
@@ -210,7 +211,7 @@ private fun CipherView.toDisplayItem(
|
||||
baseIconUrl = baseIconUrl,
|
||||
isIconLoadingDisabled = isIconLoadingDisabled,
|
||||
),
|
||||
extraIconList = emptyList(),
|
||||
extraIconList = toLabelIcons(),
|
||||
overflowOptions = toOverflowActions(),
|
||||
)
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.x8bit.bitwarden.ui.vault.feature.util
|
||||
|
||||
import com.bitwarden.core.CipherType
|
||||
import com.bitwarden.core.CipherView
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.IconRes
|
||||
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.model.ListingItemOverflowAction
|
||||
import com.x8bit.bitwarden.ui.vault.model.VaultTrailingIcon
|
||||
|
||||
/**
|
||||
* Creates the list of overflow actions to be displayed for a [CipherView].
|
||||
@@ -36,3 +38,18 @@ fun CipherView.toOverflowActions(): List<ListingItemOverflowAction.VaultAction>
|
||||
)
|
||||
}
|
||||
.orEmpty()
|
||||
|
||||
/**
|
||||
* Checks if the list is empty and if not returns an icon in a list.
|
||||
*/
|
||||
fun CipherView.toLabelIcons(): List<IconRes> {
|
||||
return listOfNotNull(
|
||||
VaultTrailingIcon.COLLECTION.takeIf {
|
||||
this.collectionIds.isNotEmpty() || this.organizationId?.isNotEmpty() == true
|
||||
},
|
||||
VaultTrailingIcon.ATTACHMENT.takeIf { this.attachments?.isNotEmpty() == true },
|
||||
)
|
||||
.map {
|
||||
IconRes(iconRes = it.iconRes, contentDescription = it.contentDescription)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@ import androidx.compose.ui.unit.dp
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.ui.platform.components.BitwardenGroupItem
|
||||
import com.x8bit.bitwarden.ui.platform.components.BitwardenListHeaderTextWithSupportLabel
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.toIconResources
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.handlers.VaultHandlers
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
|
||||
/**
|
||||
* Content view for the [VaultScreen].
|
||||
@@ -76,6 +78,10 @@ fun VaultContent(
|
||||
items(state.favoriteItems) { favoriteItem ->
|
||||
VaultEntryListItem(
|
||||
startIcon = favoriteItem.startIcon,
|
||||
trailingLabelIcons = favoriteItem
|
||||
.extraIconList
|
||||
.toIconResources()
|
||||
.toPersistentList(),
|
||||
label = favoriteItem.name(),
|
||||
supportingLabel = favoriteItem.supportingLabel?.invoke(),
|
||||
onClick = { vaultHandlers.vaultItemClick(favoriteItem) },
|
||||
@@ -231,6 +237,10 @@ fun VaultContent(
|
||||
items(state.noFolderItems) { noFolderItem ->
|
||||
VaultEntryListItem(
|
||||
startIcon = noFolderItem.startIcon,
|
||||
trailingLabelIcons = noFolderItem
|
||||
.extraIconList
|
||||
.toIconResources()
|
||||
.toPersistentList(),
|
||||
label = noFolderItem.name(),
|
||||
supportingLabel = noFolderItem.supportingLabel?.invoke(),
|
||||
onClick = { vaultHandlers.vaultItemClick(noFolderItem) },
|
||||
|
||||
@@ -7,8 +7,11 @@ 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.components.model.IconData
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.IconResource
|
||||
import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
|
||||
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.model.ListingItemOverflowAction
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
/**
|
||||
@@ -30,6 +33,7 @@ fun VaultEntryListItem(
|
||||
overflowOptions: List<ListingItemOverflowAction.VaultAction>,
|
||||
onOverflowOptionClick: (ListingItemOverflowAction.VaultAction) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
trailingLabelIcons: ImmutableList<IconResource> = persistentListOf(),
|
||||
supportingLabel: String? = null,
|
||||
) {
|
||||
BitwardenListItem(
|
||||
@@ -37,6 +41,7 @@ fun VaultEntryListItem(
|
||||
label = label,
|
||||
supportingLabel = supportingLabel,
|
||||
startIcon = startIcon,
|
||||
trailingLabelIcons = trailingLabelIcons,
|
||||
onClick = onClick,
|
||||
selectionDataList = overflowOptions
|
||||
.map { option ->
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.x8bit.bitwarden.ui.platform.base.util.concat
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.hexToColor
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.IconData
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.IconRes
|
||||
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.model.ListingItemOverflowAction
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.model.VaultFilterData
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.model.VaultFilterType
|
||||
@@ -655,8 +656,16 @@ data class VaultState(
|
||||
*/
|
||||
abstract val name: Text
|
||||
|
||||
/**
|
||||
* The icon at the start of the item.
|
||||
*/
|
||||
abstract val startIcon: IconData
|
||||
|
||||
/**
|
||||
* The icons shown after the item name.
|
||||
*/
|
||||
abstract val extraIconList: List<IconRes>
|
||||
|
||||
/**
|
||||
* An optional supporting label for the vault item that provides additional information.
|
||||
* This property is open to be overridden by subclasses that can provide their own
|
||||
@@ -679,6 +688,7 @@ data class VaultState(
|
||||
override val id: String,
|
||||
override val name: Text,
|
||||
override val startIcon: IconData = IconData.Local(R.drawable.ic_login_item),
|
||||
override val extraIconList: List<IconRes> = emptyList(),
|
||||
override val overflowOptions: List<ListingItemOverflowAction.VaultAction>,
|
||||
val username: Text?,
|
||||
) : VaultItem() {
|
||||
@@ -696,6 +706,7 @@ data class VaultState(
|
||||
override val id: String,
|
||||
override val name: Text,
|
||||
override val startIcon: IconData = IconData.Local(R.drawable.ic_card_item),
|
||||
override val extraIconList: List<IconRes> = emptyList(),
|
||||
override val overflowOptions: List<ListingItemOverflowAction.VaultAction>,
|
||||
val brand: Text? = null,
|
||||
val lastFourDigits: Text? = null,
|
||||
@@ -723,6 +734,7 @@ data class VaultState(
|
||||
override val id: String,
|
||||
override val name: Text,
|
||||
override val startIcon: IconData = IconData.Local(R.drawable.ic_identity_item),
|
||||
override val extraIconList: List<IconRes> = emptyList(),
|
||||
override val overflowOptions: List<ListingItemOverflowAction.VaultAction>,
|
||||
val firstName: Text?,
|
||||
) : VaultItem() {
|
||||
@@ -738,6 +750,7 @@ data class VaultState(
|
||||
override val id: String,
|
||||
override val name: Text,
|
||||
override val startIcon: IconData = IconData.Local(R.drawable.ic_secure_note_item),
|
||||
override val extraIconList: List<IconRes> = emptyList(),
|
||||
override val overflowOptions: List<ListingItemOverflowAction.VaultAction>,
|
||||
) : VaultItem() {
|
||||
override val supportingLabel: Text? get() = null
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.VaultData
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.IconData
|
||||
import com.x8bit.bitwarden.ui.vault.feature.util.toLabelIcons
|
||||
import com.x8bit.bitwarden.ui.vault.feature.util.toOverflowActions
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.VaultState
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.model.VaultFilterType
|
||||
@@ -158,12 +159,14 @@ private fun CipherView.toVaultItemOrNull(
|
||||
baseIconUrl = baseIconUrl,
|
||||
),
|
||||
overflowOptions = toOverflowActions(),
|
||||
extraIconList = toLabelIcons(),
|
||||
)
|
||||
|
||||
CipherType.SECURE_NOTE -> VaultState.ViewState.VaultItem.SecureNote(
|
||||
id = id,
|
||||
name = name.asText(),
|
||||
overflowOptions = toOverflowActions(),
|
||||
extraIconList = toLabelIcons(),
|
||||
)
|
||||
|
||||
CipherType.CARD -> VaultState.ViewState.VaultItem.Card(
|
||||
@@ -174,6 +177,7 @@ private fun CipherView.toVaultItemOrNull(
|
||||
?.takeLast(4)
|
||||
?.asText(),
|
||||
overflowOptions = toOverflowActions(),
|
||||
extraIconList = toLabelIcons(),
|
||||
)
|
||||
|
||||
CipherType.IDENTITY -> VaultState.ViewState.VaultItem.Identity(
|
||||
@@ -181,6 +185,7 @@ private fun CipherView.toVaultItemOrNull(
|
||||
name = name.asText(),
|
||||
firstName = identity?.firstName?.asText(),
|
||||
overflowOptions = toOverflowActions(),
|
||||
extraIconList = toLabelIcons(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.x8bit.bitwarden.ui.vault.model
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.Text
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
|
||||
/**
|
||||
* Represents the icons displayed after the cipher name.
|
||||
*/
|
||||
enum class VaultTrailingIcon(
|
||||
@DrawableRes val iconRes: Int,
|
||||
val contentDescription: Text,
|
||||
) {
|
||||
COLLECTION(
|
||||
iconRes = R.drawable.ic_collection,
|
||||
contentDescription = R.string.collections.asText(),
|
||||
),
|
||||
ATTACHMENT(
|
||||
iconRes = R.drawable.ic_attachment,
|
||||
contentDescription = R.string.attachments.asText(),
|
||||
),
|
||||
}
|
||||
Reference in New Issue
Block a user