Updated on 2026-08-14

This commit is contained in:
Tangem 2022-08-03 14:12:22 +03:00
parent f77fa1fe70
commit 4646e3b5c6
3 changed files with 110 additions and 38 deletions

View file

@ -19,22 +19,7 @@ import com.tangem.wallet.R
private const val QCX = "QCX"
private const val VOYR = "VOYRME"
fun loadCurrencyIcon(
currencyImageView: CurrencyIconView,
currencyTextView: TextView,
token: Token?,
blockchain: Blockchain,
) {
CurrencyIconLoader(
currencyImageView = currencyImageView.imageView,
currencyTextView = currencyTextView,
token = token,
blockchain = blockchain
)
.load()
}
private class CurrencyIconLoader(
class CurrencyIconRequest(
private val currencyImageView: ImageFilterView,
private val currencyTextView: TextView,
private val token: Token?,

View file

@ -3,27 +3,69 @@ package com.tangem.tap.features.wallet.ui.images
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.TextView
import androidx.annotation.DrawableRes
import androidx.constraintlayout.utils.widget.ImageFilterView
import com.google.android.material.card.MaterialCardView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isVisible
import com.tangem.blockchain.common.DerivationStyle
import com.tangem.tangem_sdk_new.extensions.dpToPx
import com.tangem.tap.common.extensions.getRoundIconRes
import com.tangem.tap.features.wallet.models.Currency
import com.tangem.wallet.databinding.ViewCurrencyIconBinding
import kotlin.math.roundToInt
class CurrencyIconView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
) : MaterialCardView(context, attrs, defStyleAttr) {
) : ConstraintLayout(context, attrs, defStyleAttr) {
private val binding = ViewCurrencyIconBinding.inflate(
LayoutInflater.from(context),
this
this,
)
val imageView: ImageFilterView
get() = binding.iv
private val currencyImageView: ImageFilterView
get() = binding.ivCurrency
private val currencyTextView: TextView
get() = binding.tvTokenLetter
private var isBlockchainIconVisible: Boolean
get() = binding.ivBlockchain.isVisible
set(value) = binding.ivBlockchain::isVisible.set(value)
private var isBadgeVisible: Boolean
get() = binding.badge.isVisible
set(value) = binding.badge::isVisible.set(value)
@DrawableRes
private var blockchainIconRes: Int? = null
set(value) {
if (value != null && value != field && isBlockchainIconVisible) {
binding.ivBlockchain.setImageResource(value)
field = value
}
}
init {
elevation = 0f
cardElevation = 0f
radius = dpToPx(6f)
minWidth = dpToPx(48f).roundToInt()
minHeight = dpToPx(48f).roundToInt()
}
fun load(
currency: Currency,
derivationStyle: DerivationStyle?,
) {
isBlockchainIconVisible = currency.isToken()
isBadgeVisible = currency.isCustomCurrency(derivationStyle)
blockchainIconRes = currency.blockchain.getRoundIconRes()
CurrencyIconRequest(
currencyImageView = currencyImageView,
currencyTextView = currencyTextView,
token = (currency as? Currency.Token)?.token,
blockchain = currency.blockchain,
).load()
}
}