Updated on 2026-08-14
This commit is contained in:
parent
d4c932d3c3
commit
5db8900311
40 changed files with 198 additions and 88 deletions
|
|
@ -6,6 +6,7 @@ import com.tangem.common.ui.R
|
|||
import com.tangem.core.ui.components.account.AccountCharIcon
|
||||
import com.tangem.core.ui.components.account.AccountIconSize
|
||||
import com.tangem.core.ui.components.account.AccountResIcon
|
||||
import com.tangem.core.ui.components.account.PaymentAccountIcon
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
import com.tangem.core.ui.extensions.resolveReference
|
||||
import com.tangem.domain.models.account.CryptoPortfolioIcon
|
||||
|
|
@ -16,7 +17,7 @@ import com.tangem.domain.models.account.CryptoPortfolioIcon.Color
|
|||
* - a single character (derived from the [name]) using [AccountCharIcon], or
|
||||
* - a predefined vector resource (from [icon]) using [AccountResIcon].
|
||||
*
|
||||
* The background color is taken from [CryptoPortfolioIconUM.color],
|
||||
* The background color is taken from [AccountIconUM.CryptoPortfolio.color],
|
||||
* and the icon size, text style, and container shape are adapted based on the given [size].
|
||||
*
|
||||
* @param name A [TextReference] used to resolve and display the first letter
|
||||
|
|
@ -31,29 +32,43 @@ import com.tangem.domain.models.account.CryptoPortfolioIcon.Color
|
|||
@Composable
|
||||
fun AccountIcon(
|
||||
name: TextReference,
|
||||
icon: CryptoPortfolioIconUM,
|
||||
icon: AccountIconUM.CryptoPortfolio,
|
||||
size: AccountIconSize,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val letter = name.resolveReference().firstOrNull()
|
||||
val iconColor = icon.color.getUiColor()
|
||||
when {
|
||||
icon.value == CryptoPortfolioIcon.Icon.Letter && letter == null -> {
|
||||
AccountResIcon(
|
||||
resId = R.drawable.ic_tangem_24,
|
||||
color = icon.color.getUiColor(),
|
||||
color = iconColor,
|
||||
size = size,
|
||||
modifier = modifier,
|
||||
)
|
||||
}
|
||||
icon.value == CryptoPortfolioIcon.Icon.Letter -> AccountCharIcon(
|
||||
char = letter ?: 'N',
|
||||
color = icon.color.getUiColor(),
|
||||
color = iconColor,
|
||||
size = size,
|
||||
modifier = modifier,
|
||||
)
|
||||
else -> AccountResIcon(
|
||||
resId = icon.value.getResId(),
|
||||
color = icon.color.getUiColor(),
|
||||
color = iconColor,
|
||||
size = size,
|
||||
modifier = modifier,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun AccountIcon(name: TextReference, icon: AccountIconUM, size: AccountIconSize, modifier: Modifier = Modifier) {
|
||||
when (icon) {
|
||||
is AccountIconUM.Payment -> PaymentAccountIcon(size = size, modifier = modifier)
|
||||
is AccountIconUM.CryptoPortfolio -> AccountIcon(
|
||||
name = name,
|
||||
icon = icon,
|
||||
size = size,
|
||||
modifier = modifier,
|
||||
)
|
||||
|
|
@ -62,7 +77,7 @@ fun AccountIcon(
|
|||
|
||||
object AccountIconPreviewData {
|
||||
|
||||
fun randomAccountIcon(letter: Boolean = false) = CryptoPortfolioIconUM(
|
||||
fun randomAccountIcon(letter: Boolean = false) = AccountIconUM.CryptoPortfolio(
|
||||
value = if (letter) CryptoPortfolioIcon.Icon.Letter else CryptoPortfolioIcon.Icon.entries.random(),
|
||||
color = Color.entries.random(),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package com.tangem.common.ui.account
|
||||
|
||||
import com.tangem.domain.models.account.CryptoPortfolioIcon.Color
|
||||
import com.tangem.domain.models.account.CryptoPortfolioIcon.Icon
|
||||
|
||||
sealed class AccountIconUM {
|
||||
data class CryptoPortfolio(val value: Icon, val color: Color) : AccountIconUM()
|
||||
|
||||
data object Payment : AccountIconUM()
|
||||
}
|
||||
|
|
@ -27,7 +27,7 @@ import com.tangem.core.ui.res.TangemTheme
|
|||
@Composable
|
||||
fun AccountLabel(
|
||||
name: TextReference,
|
||||
icon: CryptoPortfolioIconUM,
|
||||
icon: AccountIconUM,
|
||||
iconSize: AccountIconSize,
|
||||
modifier: Modifier = Modifier,
|
||||
nameStyle: TextStyle = TangemTheme.typography.subtitle2,
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class AccountPortfolioItemUMConverter(
|
|||
private fun getImageState(account: Account.CryptoPortfolio) = when (account) {
|
||||
is Account.CryptoPortfolio -> UserWalletItemUM.ImageState.Account(
|
||||
name = account.accountName.toUM().value,
|
||||
icon = account.icon.toUM(),
|
||||
icon = CryptoPortfolioIconConverter.convert(account.icon),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ import com.tangem.core.ui.res.TangemThemePreview
|
|||
fun AccountRow(
|
||||
title: TextReference,
|
||||
subtitle: TextReference,
|
||||
icon: CryptoPortfolioIconUM,
|
||||
icon: AccountIconUM.CryptoPortfolio,
|
||||
modifier: Modifier = Modifier,
|
||||
isReverse: Boolean = false,
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package com.tangem.common.ui.account
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
|
|
@ -9,11 +11,16 @@ import androidx.compose.ui.Modifier
|
|||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.tangem.core.ui.components.account.AccountIconSize
|
||||
import com.tangem.core.ui.extensions.resolveReference
|
||||
import com.tangem.core.ui.extensions.stringReference
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.core.ui.res.TangemThemePreview
|
||||
import com.tangem.core.ui.test.SendScreenTestTags
|
||||
import com.tangem.domain.models.account.CryptoPortfolioIcon
|
||||
import com.tangem.utils.StringsSigns
|
||||
|
||||
/**
|
||||
* A composable function that displays an account label (icon + name) with an optional prefix.
|
||||
|
|
@ -61,4 +68,28 @@ fun AccountTitle(
|
|||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
private fun PreviewAccountTitle() {
|
||||
TangemThemePreview {
|
||||
Column {
|
||||
AccountTitle(
|
||||
accountTitleUM = AccountTitleUM.Account(
|
||||
prefixText = stringReference(StringsSigns.DOT),
|
||||
name = stringReference("Main Wallet"),
|
||||
icon = AccountIconUM.CryptoPortfolio(
|
||||
value = CryptoPortfolioIcon.Icon.Bookmark,
|
||||
color = CryptoPortfolioIcon.Color.Pattypan,
|
||||
),
|
||||
),
|
||||
modifier = Modifier.padding(4.dp),
|
||||
)
|
||||
AccountTitle(
|
||||
accountTitleUM = AccountTitleUM.Account.payment(prefixText = stringReference(StringsSigns.DOT)),
|
||||
modifier = Modifier.padding(4.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
package com.tangem.common.ui.account
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import com.tangem.common.ui.R
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
|
||||
/**
|
||||
* A sealed interface representing the title of an account, which can be either a simple text
|
||||
|
|
@ -19,6 +21,16 @@ sealed interface AccountTitleUM {
|
|||
data class Account(
|
||||
val prefixText: TextReference,
|
||||
val name: TextReference,
|
||||
val icon: CryptoPortfolioIconUM,
|
||||
) : AccountTitleUM
|
||||
val icon: AccountIconUM,
|
||||
) : AccountTitleUM {
|
||||
companion object {
|
||||
fun payment(prefixText: TextReference = TextReference.EMPTY): Account {
|
||||
return Account(
|
||||
prefixText = prefixText,
|
||||
name = resourceReference(R.string.tangempay_payment_account),
|
||||
icon = AccountIconUM.Payment,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.tangem.common.ui.account
|
||||
|
||||
import com.tangem.domain.models.account.CryptoPortfolioIcon
|
||||
import com.tangem.utils.converter.TwoWayConverter
|
||||
|
||||
object CryptoPortfolioIconConverter : TwoWayConverter<CryptoPortfolioIcon, AccountIconUM.CryptoPortfolio> {
|
||||
override fun convert(value: CryptoPortfolioIcon): AccountIconUM.CryptoPortfolio {
|
||||
return AccountIconUM.CryptoPortfolio(value = value.value, color = value.color)
|
||||
}
|
||||
|
||||
override fun convertBack(value: AccountIconUM.CryptoPortfolio): CryptoPortfolioIcon {
|
||||
return CryptoPortfolioIcon.ofCustomAccount(value = value.value, color = value.color)
|
||||
}
|
||||
}
|
||||
|
|
@ -47,7 +47,4 @@ fun CryptoPortfolioIcon.Icon.getResId(): Int {
|
|||
CryptoPortfolioIcon.Icon.Package -> R.drawable.ic_package_24
|
||||
CryptoPortfolioIcon.Icon.Gift -> R.drawable.ic_gift_24
|
||||
}
|
||||
}
|
||||
|
||||
fun CryptoPortfolioIcon.toUM() = CryptoPortfolioIconUM(domainModel = this)
|
||||
fun CryptoPortfolioIconUM.toDomain() = CryptoPortfolioIcon.ofCustomAccount(value = this.value, color = this.color)
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package com.tangem.common.ui.account
|
||||
|
||||
import com.tangem.domain.models.account.CryptoPortfolioIcon
|
||||
import com.tangem.domain.models.account.CryptoPortfolioIcon.Color
|
||||
import com.tangem.domain.models.account.CryptoPortfolioIcon.Icon
|
||||
|
||||
data class CryptoPortfolioIconUM(
|
||||
val value: Icon,
|
||||
val color: Color,
|
||||
) {
|
||||
constructor(domainModel: CryptoPortfolioIcon) : this(
|
||||
value = domainModel.value,
|
||||
color = domainModel.color,
|
||||
)
|
||||
}
|
||||
|
|
@ -82,7 +82,7 @@ fun PortfolioSelectRow(
|
|||
|
||||
@Immutable
|
||||
data class PortfolioSelectUM(
|
||||
val icon: CryptoPortfolioIconUM?,
|
||||
val icon: AccountIconUM.CryptoPortfolio?,
|
||||
val name: TextReference,
|
||||
val isAccountMode: Boolean,
|
||||
val isMultiChoice: Boolean,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.common.ui.amountScreen.converters
|
||||
|
||||
import com.tangem.common.ui.account.AccountTitleUM
|
||||
import com.tangem.common.ui.account.CryptoPortfolioIconConverter
|
||||
import com.tangem.common.ui.account.toUM
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
import com.tangem.domain.models.account.Account
|
||||
|
|
@ -15,7 +16,7 @@ class AmountAccountConverter(
|
|||
return if (value != null && isAccountsMode) {
|
||||
AccountTitleUM.Account(
|
||||
name = value.accountName.toUM().value,
|
||||
icon = value.icon.toUM(),
|
||||
icon = CryptoPortfolioIconConverter.convert(value.icon),
|
||||
prefixText = prefixText,
|
||||
)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import androidx.compose.foundation.text.KeyboardOptions
|
|||
import com.tangem.common.ui.R
|
||||
import com.tangem.common.ui.account.AccountNameUM
|
||||
import com.tangem.common.ui.account.AccountTitleUM
|
||||
import com.tangem.common.ui.account.toUM
|
||||
import com.tangem.common.ui.account.CryptoPortfolioIconConverter
|
||||
import com.tangem.common.ui.amountScreen.models.AmountFieldModel
|
||||
import com.tangem.common.ui.amountScreen.models.AmountState
|
||||
import com.tangem.core.ui.components.currency.icon.CurrencyIconState
|
||||
|
|
@ -88,7 +88,7 @@ object AmountStatePreviewData {
|
|||
val amountStateV2Accounts = amountState.copy(
|
||||
accountTitleUM = AccountTitleUM.Account(
|
||||
name = AccountNameUM.DefaultMain.value,
|
||||
icon = CryptoPortfolioIcon.ofDefaultCustomAccount().toUM(),
|
||||
icon = CryptoPortfolioIconConverter.convert(CryptoPortfolioIcon.ofDefaultCustomAccount()),
|
||||
prefixText = resourceReference(R.string.common_from),
|
||||
),
|
||||
availableBalanceCrypto = stringReference("2 130,81231238 USDT"),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.tangem.common.ui.userwallet.state
|
||||
|
||||
import com.tangem.common.ui.account.CryptoPortfolioIconUM
|
||||
import com.tangem.common.ui.account.AccountIconUM
|
||||
import com.tangem.core.ui.components.artwork.ArtworkUM
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
import javax.annotation.concurrent.Immutable
|
||||
|
|
@ -64,7 +64,7 @@ data class UserWalletItemUM(
|
|||
|
||||
data class Account(
|
||||
val name: TextReference,
|
||||
val icon: CryptoPortfolioIconUM,
|
||||
val icon: AccountIconUM.CryptoPortfolio,
|
||||
) : ImageState()
|
||||
|
||||
data class Image(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue