mirror of
https://github.com/bitwarden/android.git
synced 2026-06-08 08:06:32 -05:00
Add helper method for getting sendView icons (#678)
This commit is contained in:
committed by
Álison Fernandes
parent
cb306a8377
commit
2c749186e1
@@ -1,10 +1,12 @@
|
||||
package com.x8bit.bitwarden.ui.platform.components.model
|
||||
|
||||
import android.os.Parcelable
|
||||
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
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
/**
|
||||
* Data class representing the resources required for an icon.
|
||||
@@ -23,11 +25,12 @@ data class IconResource(
|
||||
* @property iconRes Resource for the icon.
|
||||
* @property contentDescription The icon's content description.
|
||||
*/
|
||||
@Parcelize
|
||||
data class IconRes(
|
||||
@DrawableRes
|
||||
val iconRes: Int,
|
||||
val contentDescription: Text,
|
||||
)
|
||||
) : Parcelable
|
||||
|
||||
/**
|
||||
* A helper method to convert a list of [IconRes] to a list of [IconResource].
|
||||
|
||||
@@ -15,10 +15,10 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenListItem
|
||||
import com.x8bit.bitwarden.ui.platform.components.BitwardenTwoButtonDialog
|
||||
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.IconRes
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.IconResource
|
||||
import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
|
||||
import com.x8bit.bitwarden.ui.platform.util.persistentListOfNotNull
|
||||
import com.x8bit.bitwarden.ui.tools.feature.send.model.SendStatusIcon
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ fun SendListItem(
|
||||
label: String,
|
||||
supportingLabel: String,
|
||||
startIcon: IconData,
|
||||
trailingLabelIcons: List<SendStatusIcon>,
|
||||
trailingLabelIcons: List<IconRes>,
|
||||
onClick: () -> Unit,
|
||||
onEditClick: () -> Unit,
|
||||
onCopyClick: () -> Unit,
|
||||
|
||||
@@ -18,7 +18,7 @@ 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.tools.feature.send.model.SendStatusIcon
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.IconRes
|
||||
import com.x8bit.bitwarden.ui.tools.feature.send.util.toViewState
|
||||
import com.x8bit.bitwarden.ui.vault.feature.item.VaultItemScreen
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
@@ -350,7 +350,7 @@ data class SendState(
|
||||
val name: String,
|
||||
val deletionDate: String,
|
||||
val type: Type,
|
||||
val iconList: List<SendStatusIcon>,
|
||||
val iconList: List<IconRes>,
|
||||
val shareUrl: String,
|
||||
val hasPassword: Boolean,
|
||||
) : Parcelable {
|
||||
|
||||
@@ -5,8 +5,6 @@ import com.bitwarden.core.SendView
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.SendData
|
||||
import com.x8bit.bitwarden.ui.platform.util.toFormattedPattern
|
||||
import com.x8bit.bitwarden.ui.tools.feature.send.SendState
|
||||
import com.x8bit.bitwarden.ui.tools.feature.send.model.SendStatusIcon
|
||||
import java.time.Instant
|
||||
|
||||
private const val DELETION_DATE_PATTERN: String = "MMM d, uuuu, hh:mm a"
|
||||
|
||||
@@ -38,21 +36,7 @@ private fun List<SendView>.toSendContent(
|
||||
SendType.TEXT -> SendState.ViewState.Content.SendItem.Type.TEXT
|
||||
SendType.FILE -> SendState.ViewState.Content.SendItem.Type.FILE
|
||||
},
|
||||
iconList = listOfNotNull(
|
||||
SendStatusIcon.DISABLED.takeIf { sendView.disabled },
|
||||
SendStatusIcon.PASSWORD.takeIf { sendView.hasPassword },
|
||||
SendStatusIcon.MAX_ACCESS_COUNT_REACHED.takeIf {
|
||||
sendView.maxAccessCount?.let { maxCount ->
|
||||
sendView.accessCount >= maxCount
|
||||
} == true
|
||||
},
|
||||
SendStatusIcon.EXPIRED.takeIf {
|
||||
sendView.expirationDate?.isBefore(Instant.now()) == true
|
||||
},
|
||||
SendStatusIcon.PENDING_DELETE.takeIf {
|
||||
sendView.deletionDate.isBefore(Instant.now())
|
||||
},
|
||||
),
|
||||
iconList = sendView.toLabelIcons(),
|
||||
shareUrl = sendView.toSendUrl(baseWebSendUrl),
|
||||
hasPassword = sendView.hasPassword,
|
||||
)
|
||||
|
||||
@@ -1,6 +1,24 @@
|
||||
package com.x8bit.bitwarden.ui.tools.feature.send.util
|
||||
|
||||
import com.bitwarden.core.SendView
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.IconRes
|
||||
import com.x8bit.bitwarden.ui.tools.feature.send.model.SendStatusIcon
|
||||
import java.time.Clock
|
||||
|
||||
/**
|
||||
* Creates the list of trailing label icons to be displayed for a [SendView].
|
||||
*/
|
||||
fun SendView.toLabelIcons(clock: Clock = Clock.systemDefaultZone()): List<IconRes> =
|
||||
listOfNotNull(
|
||||
SendStatusIcon.DISABLED.takeIf { disabled },
|
||||
SendStatusIcon.PASSWORD.takeIf { hasPassword },
|
||||
SendStatusIcon.MAX_ACCESS_COUNT_REACHED.takeIf {
|
||||
maxAccessCount?.let { maxCount -> accessCount >= maxCount } == true
|
||||
},
|
||||
SendStatusIcon.EXPIRED.takeIf { expirationDate?.isBefore(clock.instant()) == true },
|
||||
SendStatusIcon.PENDING_DELETE.takeIf { deletionDate.isBefore(clock.instant()) },
|
||||
)
|
||||
.map { IconRes(iconRes = it.iconRes, contentDescription = it.contentDescription) }
|
||||
|
||||
/**
|
||||
* Creates a sharable url from a [SendView].
|
||||
|
||||
@@ -10,8 +10,7 @@ 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.toLabelIcons
|
||||
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
|
||||
@@ -207,23 +206,7 @@ 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) },
|
||||
),
|
||||
extraIconList = toLabelIcons(clock = clock),
|
||||
overflowOptions = listOfNotNull(
|
||||
VaultItemListingState.DisplayItem.OverflowItem(
|
||||
title = R.string.edit.asText(),
|
||||
|
||||
Reference in New Issue
Block a user