mirror of
https://github.com/bitwarden/android.git
synced 2026-06-06 22:42:58 -05:00
Add trailing icons for sends (#675)
This commit is contained in:
committed by
Álison Fernandes
parent
c7abbd17dc
commit
a1e55297e9
@@ -1,6 +1,10 @@
|
||||
package com.x8bit.bitwarden.ui.platform.components.model
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.Text
|
||||
|
||||
/**
|
||||
* Data class representing the resources required for an icon.
|
||||
@@ -12,3 +16,31 @@ data class IconResource(
|
||||
val iconPainter: Painter,
|
||||
val contentDescription: String,
|
||||
)
|
||||
|
||||
/**
|
||||
* Data class representing the resources required for an icon and is friendly to use in ViewModels.
|
||||
*
|
||||
* @property iconRes Resource for the icon.
|
||||
* @property contentDescription The icon's content description.
|
||||
*/
|
||||
data class IconRes(
|
||||
@DrawableRes
|
||||
val iconRes: Int,
|
||||
val contentDescription: Text,
|
||||
)
|
||||
|
||||
/**
|
||||
* A helper method to convert a list of [IconRes] to a list of [IconResource].
|
||||
*/
|
||||
@Composable
|
||||
fun List<IconRes>.toIconResources(): List<IconResource> = this.map { it.toIconResource() }
|
||||
|
||||
/**
|
||||
* A helper method to convert an [IconRes] to an [IconResource].
|
||||
*/
|
||||
@Composable
|
||||
fun IconRes.toIconResource(): IconResource =
|
||||
IconResource(
|
||||
iconPainter = painterResource(id = iconRes),
|
||||
contentDescription = contentDescription(),
|
||||
)
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.ui.platform.components.BitwardenListHeaderTextWithSupportLabel
|
||||
import com.x8bit.bitwarden.ui.platform.components.BitwardenListItem
|
||||
import com.x8bit.bitwarden.ui.platform.components.SelectionItemData
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.toIconResources
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
|
||||
/**
|
||||
@@ -42,6 +43,10 @@ fun VaultItemListingContent(
|
||||
label = it.title,
|
||||
supportingLabel = it.subtitle,
|
||||
onClick = { vaultItemClick(it.id) },
|
||||
trailingLabelIcons = it
|
||||
.extraIconList
|
||||
.toIconResources()
|
||||
.toPersistentList(),
|
||||
selectionDataList = it
|
||||
.overflowOptions
|
||||
.map { option ->
|
||||
|
||||
@@ -17,6 +17,7 @@ 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.platform.components.model.IconData
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.IconRes
|
||||
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.util.determineListingPredicate
|
||||
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.util.toItemListingType
|
||||
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.util.toViewState
|
||||
@@ -28,6 +29,7 @@ import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import java.time.Clock
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
@@ -38,6 +40,7 @@ import javax.inject.Inject
|
||||
@Suppress("MagicNumber", "TooManyFunctions")
|
||||
class VaultItemListingViewModel @Inject constructor(
|
||||
savedStateHandle: SavedStateHandle,
|
||||
private val clock: Clock,
|
||||
private val clipboardManager: BitwardenClipboardManager,
|
||||
private val vaultRepository: VaultRepository,
|
||||
private val environmentRepository: EnvironmentRepository,
|
||||
@@ -271,7 +274,10 @@ class VaultItemListingViewModel @Inject constructor(
|
||||
.filter { sendView ->
|
||||
sendView.determineListingPredicate(listingType)
|
||||
}
|
||||
.toViewState(baseWebSendUrl = state.baseWebSendUrl)
|
||||
.toViewState(
|
||||
baseWebSendUrl = state.baseWebSendUrl,
|
||||
clock = clock,
|
||||
)
|
||||
}
|
||||
},
|
||||
dialogState = currentState.dialogState.takeUnless { clearDialogState },
|
||||
@@ -356,6 +362,7 @@ data class VaultItemListingState(
|
||||
val title: String,
|
||||
val subtitle: String?,
|
||||
val iconData: IconData,
|
||||
val extraIconList: List<IconRes>,
|
||||
val overflowOptions: List<OverflowItem>,
|
||||
) {
|
||||
/**
|
||||
|
||||
@@ -10,10 +10,13 @@ import com.bitwarden.core.SendView
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.IconData
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.IconRes
|
||||
import com.x8bit.bitwarden.ui.tools.feature.send.model.SendStatusIcon
|
||||
import com.x8bit.bitwarden.ui.tools.feature.send.util.toSendUrl
|
||||
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.VaultItemListingState
|
||||
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.VaultItemListingsAction
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.util.toLoginIconData
|
||||
import java.time.Clock
|
||||
|
||||
/**
|
||||
* Determines a predicate to filter a list of [CipherView] based on the
|
||||
@@ -92,10 +95,14 @@ fun List<CipherView>.toViewState(
|
||||
*/
|
||||
fun List<SendView>.toViewState(
|
||||
baseWebSendUrl: String,
|
||||
clock: Clock,
|
||||
): VaultItemListingState.ViewState =
|
||||
if (isNotEmpty()) {
|
||||
VaultItemListingState.ViewState.Content(
|
||||
displayItemList = toDisplayItemList(baseWebSendUrl = baseWebSendUrl),
|
||||
displayItemList = toDisplayItemList(
|
||||
baseWebSendUrl = baseWebSendUrl,
|
||||
clock = clock,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
VaultItemListingState.ViewState.NoItems
|
||||
@@ -143,8 +150,14 @@ private fun List<CipherView>.toDisplayItemList(
|
||||
|
||||
private fun List<SendView>.toDisplayItemList(
|
||||
baseWebSendUrl: String,
|
||||
clock: Clock,
|
||||
): List<VaultItemListingState.DisplayItem> =
|
||||
this.map { it.toDisplayItem(baseWebSendUrl = baseWebSendUrl) }
|
||||
this.map {
|
||||
it.toDisplayItem(
|
||||
baseWebSendUrl = baseWebSendUrl,
|
||||
clock = clock,
|
||||
)
|
||||
}
|
||||
|
||||
private fun CipherView.toDisplayItem(
|
||||
baseIconUrl: String,
|
||||
@@ -158,6 +171,7 @@ private fun CipherView.toDisplayItem(
|
||||
baseIconUrl = baseIconUrl,
|
||||
isIconLoadingDisabled = isIconLoadingDisabled,
|
||||
),
|
||||
extraIconList = emptyList(),
|
||||
overflowOptions = emptyList(),
|
||||
)
|
||||
|
||||
@@ -181,6 +195,7 @@ private fun CipherView.toIconData(
|
||||
|
||||
private fun SendView.toDisplayItem(
|
||||
baseWebSendUrl: String,
|
||||
clock: Clock,
|
||||
): VaultItemListingState.DisplayItem =
|
||||
VaultItemListingState.DisplayItem(
|
||||
id = id.orEmpty(),
|
||||
@@ -192,6 +207,23 @@ private fun SendView.toDisplayItem(
|
||||
SendType.FILE -> R.drawable.ic_send_file
|
||||
},
|
||||
),
|
||||
extraIconList = listOfNotNull(
|
||||
SendStatusIcon.DISABLED
|
||||
.takeIf { disabled }
|
||||
?.let { IconRes(iconRes = it.iconRes, contentDescription = it.contentDescription) },
|
||||
SendStatusIcon.PASSWORD
|
||||
.takeIf { hasPassword }
|
||||
?.let { IconRes(iconRes = it.iconRes, contentDescription = it.contentDescription) },
|
||||
SendStatusIcon.MAX_ACCESS_COUNT_REACHED
|
||||
.takeIf { maxAccessCount?.let { maxCount -> accessCount >= maxCount } == true }
|
||||
?.let { IconRes(iconRes = it.iconRes, contentDescription = it.contentDescription) },
|
||||
SendStatusIcon.EXPIRED
|
||||
.takeIf { expirationDate?.isBefore(clock.instant()) == true }
|
||||
?.let { IconRes(iconRes = it.iconRes, contentDescription = it.contentDescription) },
|
||||
SendStatusIcon.PENDING_DELETE
|
||||
.takeIf { deletionDate.isBefore(clock.instant()) }
|
||||
?.let { IconRes(iconRes = it.iconRes, contentDescription = it.contentDescription) },
|
||||
),
|
||||
overflowOptions = listOfNotNull(
|
||||
VaultItemListingState.DisplayItem.OverflowItem(
|
||||
title = R.string.edit.asText(),
|
||||
|
||||
Reference in New Issue
Block a user