Updated on 2026-08-14
This commit is contained in:
parent
776ee6d136
commit
cffc4e4686
4 changed files with 66 additions and 45 deletions
|
|
@ -5,18 +5,21 @@ import com.tangem.domain.common.util.cardTypesResolver
|
|||
import com.tangem.domain.common.util.getCardsCount
|
||||
import com.tangem.domain.demo.DemoConfig
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import com.tangem.domain.wallets.repository.WalletsRepository
|
||||
import com.tangem.feature.wallet.impl.R
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Wallet image resolver
|
||||
*
|
||||
* @property walletsRepository wallets repository
|
||||
*
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
internal object WalletImageResolver {
|
||||
|
||||
private const val WALLET_WITHOUT_BACKUP_COUNT = 1
|
||||
private const val WALLET_WITH_ONE_BACKUP_COUNT = 2
|
||||
private const val WALLET_WITH_TWO_BACKUPS_COUNT = 3
|
||||
internal class WalletImageResolver @Inject constructor(
|
||||
private val walletsRepository: WalletsRepository,
|
||||
) {
|
||||
|
||||
/** Get a specified wallet [userWallet] image */
|
||||
@Suppress("CyclomaticComplexMethod")
|
||||
|
|
@ -36,6 +39,7 @@ internal object WalletImageResolver {
|
|||
|
||||
return when {
|
||||
cardTypesResolver.isDevKit() -> R.drawable.ill_dev_120_106
|
||||
userWallet.isRing() -> userWallet.resolveWalletWithRing()
|
||||
cobrandImage != null -> userWallet.resolveWallet2Cobrand(image = cobrandImage)
|
||||
cardTypesResolver.isWallet2() -> userWallet.resolveWallet2()
|
||||
cardTypesResolver.isShibaWallet() -> userWallet.resolveShibaWallet()
|
||||
|
|
@ -48,6 +52,18 @@ internal object WalletImageResolver {
|
|||
}
|
||||
}
|
||||
|
||||
private fun UserWallet.isRing(): Boolean {
|
||||
return scanResponse.cardTypesResolver.isRing() ||
|
||||
runBlocking { walletsRepository.isWalletWithRing(userWalletId = this@isRing.walletId) }
|
||||
}
|
||||
|
||||
private fun UserWallet.resolveWalletWithRing(): Int? {
|
||||
return resolveWallet2(
|
||||
oneBackupResId = R.drawable.ill_card_with_ring_120_106,
|
||||
twoBackupResId = R.drawable.ill_card2_with_ring_120_106,
|
||||
)
|
||||
}
|
||||
|
||||
private fun UserWallet.resolveWallet2Cobrand(image: Wallet2CobrandImage): Int? {
|
||||
return resolveWallet2(oneBackupResId = image.cards2ResId, twoBackupResId = image.cards3ResId)
|
||||
}
|
||||
|
|
@ -90,4 +106,10 @@ internal object WalletImageResolver {
|
|||
|
||||
return if (count != null) resolve(count) else null
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val WALLET_WITHOUT_BACKUP_COUNT = 1
|
||||
const val WALLET_WITH_ONE_BACKUP_COUNT = 2
|
||||
const val WALLET_WITH_TWO_BACKUPS_COUNT = 3
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,11 @@
|
|||
package com.tangem.feature.wallet.presentation.wallet.ui.components.common
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.animation.AnimatedContent
|
||||
import androidx.compose.animation.*
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.togetherWith
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.LocalIndication
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
|
|
@ -26,9 +25,11 @@ import androidx.compose.ui.draw.clip
|
|||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.layout.onSizeChanged
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
|
|
@ -54,7 +55,7 @@ import com.tangem.feature.wallet.impl.R
|
|||
import com.tangem.feature.wallet.presentation.common.WalletPreviewData
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletCardState
|
||||
|
||||
// private const val HALF_OF_ITEM_WIDTH = 0.5
|
||||
private const val HALF_OF_ITEM_WIDTH = 0.5
|
||||
|
||||
/**
|
||||
* Wallet card
|
||||
|
|
@ -116,33 +117,31 @@ internal fun WalletCard(state: WalletCardState, isBalanceHidden: Boolean, modifi
|
|||
bottom.linkTo(anchor = parent.bottom, margin = contentVerticalMargin)
|
||||
|
||||
if (additionalText != null) {
|
||||
width = Dimension.wrapContent
|
||||
// TODO: [REDACTED_JIRA]
|
||||
// width = if (state.imageResId != null) {
|
||||
// end.linkTo(imageRef.start)
|
||||
// Dimension.fillToConstraints
|
||||
// } else {
|
||||
// Dimension.wrapContent
|
||||
// }
|
||||
width = if (state.imageResId != null) {
|
||||
end.linkTo(imageRef.start)
|
||||
Dimension.fillToConstraints
|
||||
} else {
|
||||
Dimension.wrapContent
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
// TODO: [REDACTED_JIRA]
|
||||
// If balance has a large width then image must be hidden
|
||||
// val hasSpaceForImage by remember(key1 = balanceWidth, key2 = itemSize.width) {
|
||||
// mutableStateOf(value = balanceWidth < itemSize.width * HALF_OF_ITEM_WIDTH)
|
||||
// }
|
||||
// if (hasSpaceForImage) {
|
||||
// Image(
|
||||
// id = state.imageResId,
|
||||
// modifier = Modifier.constrainAs(imageRef) {
|
||||
// end.linkTo(parent.end)
|
||||
// bottom.linkTo(parent.bottom)
|
||||
// height = Dimension.fillToConstraints
|
||||
// },
|
||||
// )
|
||||
// }
|
||||
val hasSpaceForImage by remember(key1 = balanceWidth, key2 = itemSize.width) {
|
||||
mutableStateOf(value = balanceWidth < itemSize.width * HALF_OF_ITEM_WIDTH)
|
||||
}
|
||||
|
||||
if (hasSpaceForImage) {
|
||||
Image(
|
||||
id = state.imageResId,
|
||||
modifier = Modifier.constrainAs(imageRef) {
|
||||
end.linkTo(parent.end)
|
||||
bottom.linkTo(parent.bottom)
|
||||
height = Dimension.fillToConstraints
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -371,19 +370,19 @@ private fun LockedContent(modifier: Modifier = Modifier) {
|
|||
)
|
||||
}
|
||||
|
||||
// @Composable
|
||||
// private fun Image(@DrawableRes id: Int?, modifier: Modifier = Modifier) {
|
||||
// AnimatedVisibility(visible = id != null, modifier = modifier) {
|
||||
// val imageRes = id ?: return@AnimatedVisibility
|
||||
//
|
||||
// Image(
|
||||
// painter = painterResource(id = imageRes),
|
||||
// contentDescription = null,
|
||||
// modifier = Modifier.width(width = TangemTheme.dimens.size120),
|
||||
// contentScale = ContentScale.FillWidth,
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
@Composable
|
||||
private fun Image(@DrawableRes id: Int?, modifier: Modifier = Modifier) {
|
||||
AnimatedVisibility(visible = id != null, modifier = modifier) {
|
||||
val imageRes = id ?: return@AnimatedVisibility
|
||||
|
||||
Image(
|
||||
painter = painterResource(id = imageRes),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.width(width = TangemTheme.dimens.size120),
|
||||
contentScale = ContentScale.FillWidth,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// region Preview
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 160 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 126 KiB |
Loading…
Add table
Add a link
Reference in a new issue