From 0e4c0349de82239c6c1e3455f9bda5111d31ffe0 Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 23 Sep 2022 10:24:28 +0400 Subject: [PATCH 1/3] Updated on 2026-08-14 --- .../wallet/ui/images/CurrencyIconRequest.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/images/CurrencyIconRequest.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/images/CurrencyIconRequest.kt index cd7959319e..f6d1124e89 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/images/CurrencyIconRequest.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/images/CurrencyIconRequest.kt @@ -52,9 +52,6 @@ class CurrencyIconRequest( private fun loadTokenIcon() { loadTokenIconBase( - onStart = { - currencyImageView.setColorFilter(it.getColor()) - }, onSuccess = { currencyImageView.colorFilter = null } @@ -94,17 +91,25 @@ class CurrencyIconRequest( data = getTokenIcon(token, blockchain), placeholderRes = R.drawable.shape_circle, onStart = { - currencyTextView.text = token.symbol.take(1) - currencyTextView.setTextColor(token.getTextColor()) + showPlaceholder(token) onStart(token) }, onSuccess = { currencyTextView.text = null onSuccess(token) }, - onError = { onError(token) }, + onError = { + showPlaceholder(token) + onError(token) + }, ) } + + private fun showPlaceholder(token: Token) { + currencyTextView.text = token.symbol.take(1) + currencyTextView.setTextColor(token.getTextColor()) + currencyImageView.setColorFilter(token.getColor()) + } } private inline fun ImageView.loadIcon( From 5ad45b5e22ef6e66530392da0b46e22440c09104 Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 15 Sep 2022 01:00:26 +0400 Subject: [PATCH 2/3] Updated on 2026-08-14 --- .../com/tangem/tap/common/extensions/Token.kt | 20 +++++---- .../wallet/ui/images/CurrencyIconRequest.kt | 38 +++++++++------- .../wallet/ui/images/CurrencyIconView.kt | 43 ++++++++----------- .../main/res/layout/view_currency_icon.xml | 7 +-- 4 files changed, 58 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/common/extensions/Token.kt b/app/src/main/java/com/tangem/tap/common/extensions/Token.kt index 10897bc069..59c918d736 100644 --- a/app/src/main/java/com/tangem/tap/common/extensions/Token.kt +++ b/app/src/main/java/com/tangem/tap/common/extensions/Token.kt @@ -5,19 +5,23 @@ import androidx.annotation.ColorInt import androidx.core.graphics.luminance import androidx.core.graphics.toColorInt import com.tangem.blockchain.common.Token -import com.tangem.wallet.R @ColorInt -fun Token.getColor(): Int { - return try { - ("#" + this.contractAddress.subSequence(2..7).toString()) - .toColorInt() +fun Token.getColor(isTestnet: Boolean = false): Int { + val defaultColor = "#C7C7CC".toColorInt() // equivalent to R.color.lightGray4 + + return if (isTestnet) + defaultColor + else try { + ("#" + this.contractAddress.subSequence(2..7).toString()).toColorInt() } catch (exception: Exception) { - R.color.lightGray4 + defaultColor } } @ColorInt -fun Token.getTextColor(): Int { - return if (this.getColor().luminance > 0.5) Color.BLACK else Color.WHITE +fun Token.getTextColor(isTestnet: Boolean = false): Int = when { + isTestnet -> Color.WHITE + this.getColor().luminance > 0.5 -> Color.BLACK + else -> Color.WHITE } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/images/CurrencyIconRequest.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/images/CurrencyIconRequest.kt index f6d1124e89..62f015909c 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/images/CurrencyIconRequest.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/images/CurrencyIconRequest.kt @@ -21,7 +21,7 @@ private const val VOYR = "VOYRME" class CurrencyIconRequest( private val currencyImageView: ImageFilterView, - private val currencyTextView: TextView, + private val currencyTextView: TextView?, private val token: Token?, private val blockchain: Blockchain, ) { @@ -38,7 +38,7 @@ class CurrencyIconRequest( loadBlockchainIconBase( onStart = { currencyImageView.colorFilter = null - } + }, ) } @@ -46,15 +46,22 @@ class CurrencyIconRequest( loadBlockchainIconBase( onStart = { currencyImageView.saturation = 0f - } + }, ) } private fun loadTokenIcon() { loadTokenIconBase( + onStart = { + currencyImageView.setColorFilter(it.getColor()) + }, onSuccess = { currencyImageView.colorFilter = null - } + }, + onError = { + currencyImageView.setColorFilter(it.getColor()) + currencyTextView?.setTextColor(it.getTextColor()) + }, ) } @@ -62,7 +69,12 @@ class CurrencyIconRequest( loadTokenIconBase( onStart = { currencyImageView.saturation = 0f - } + }, + onError = { + currencyImageView.saturation = 0f + currencyImageView.setColorFilter(it.getColor(true)) + currencyTextView?.setTextColor(it.getTextColor(true)) + }, ) } @@ -91,25 +103,21 @@ class CurrencyIconRequest( data = getTokenIcon(token, blockchain), placeholderRes = R.drawable.shape_circle, onStart = { - showPlaceholder(token) + currencyTextView?.text = token.name.take(1) + currencyTextView?.setTextColor(token.getTextColor()) onStart(token) }, onSuccess = { - currencyTextView.text = null + currencyTextView?.text = null onSuccess(token) }, onError = { - showPlaceholder(token) + // for some reason the onStart doesn't call if an error occurs + currencyTextView?.text = token.name.take(1) onError(token) }, ) } - - private fun showPlaceholder(token: Token) { - currencyTextView.text = token.symbol.take(1) - currencyTextView.setTextColor(token.getTextColor()) - currencyImageView.setColorFilter(token.getColor()) - } } private inline fun ImageView.loadIcon( @@ -127,7 +135,7 @@ private inline fun ImageView.loadIcon( .listener( onStart = { onStart() }, onSuccess = { _, _ -> onSuccess() }, - onError = { _, _ -> onError() } + onError = { _, _ -> onError() }, ) .target(imageView = this) .build() diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/images/CurrencyIconView.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/images/CurrencyIconView.kt index ec9ff38519..96d03cdd22 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/images/CurrencyIconView.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/images/CurrencyIconView.kt @@ -4,13 +4,11 @@ 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 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 @@ -24,29 +22,16 @@ class CurrencyIconView @JvmOverloads constructor( LayoutInflater.from(context), this, ) - 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 - } - } + private var isBlockchainBadgeVisible: Boolean + get() = binding.ivBlockchainBadge.isVisible + set(value) = binding.ivBlockchainBadge::isVisible.set(value) + private var isCustomCurrencyBadgeVisible: Boolean + get() = binding.customBadge.isVisible + set(value) = binding.customBadge::isVisible.set(value) init { minWidth = dpToPx(48f).roundToInt() @@ -57,9 +42,7 @@ class CurrencyIconView @JvmOverloads constructor( currency: Currency, derivationStyle: DerivationStyle?, ) { - isBlockchainIconVisible = currency.isToken() - isBadgeVisible = currency.isCustomCurrency(derivationStyle) - blockchainIconRes = currency.blockchain.getRoundIconRes() + isCustomCurrencyBadgeVisible = currency.isCustomCurrency(derivationStyle) CurrencyIconRequest( currencyImageView = currencyImageView, @@ -67,5 +50,17 @@ class CurrencyIconView @JvmOverloads constructor( token = (currency as? Currency.Token)?.token, blockchain = currency.blockchain, ).load() + + if (currency.isToken()) { + // load a blockchain icon into the blockchain badge + isBlockchainBadgeVisible = true + + CurrencyIconRequest( + currencyImageView = binding.ivBlockchainBadge, + currencyTextView = null, + token = null, + blockchain = currency.blockchain, + ).load() + } } } \ No newline at end of file diff --git a/app/src/main/res/layout/view_currency_icon.xml b/app/src/main/res/layout/view_currency_icon.xml index 801ac76c97..aa1330c398 100644 --- a/app/src/main/res/layout/view_currency_icon.xml +++ b/app/src/main/res/layout/view_currency_icon.xml @@ -35,12 +35,13 @@ android:textColor="@android:color/white" android:textSize="25sp" android:textStyle="bold" + android:translationY="-1dp" tools:text="J" /> - Date: Thu, 15 Sep 2022 15:44:08 +0400 Subject: [PATCH 3/3] Updated on 2026-08-14 --- .../wallet/ui/WalletDetailsFragment.kt | 1 + .../wallet/ui/adapters/WalletAdapter.kt | 1 + .../wallet/ui/images/CurrencyIconView.kt | 50 ++++++++++--------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt index ab07dd33d5..db9173e486 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletDetailsFragment.kt @@ -41,6 +41,7 @@ import com.tangem.tap.features.wallet.redux.WalletState import com.tangem.tap.features.wallet.redux.WalletState.Companion.UNKNOWN_AMOUNT_SIGN import com.tangem.tap.features.wallet.ui.adapters.PendingTransactionsAdapter import com.tangem.tap.features.wallet.ui.adapters.WalletDetailWarningMessagesAdapter +import com.tangem.tap.features.wallet.ui.images.load import com.tangem.tap.features.wallet.ui.test.TestWalletDetails import com.tangem.tap.store import com.tangem.wallet.R diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/WalletAdapter.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/WalletAdapter.kt index 4be9104bb1..af061d48f1 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/WalletAdapter.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/adapters/WalletAdapter.kt @@ -15,6 +15,7 @@ import com.tangem.tap.common.extensions.show import com.tangem.tap.features.wallet.redux.WalletAction import com.tangem.tap.features.wallet.redux.WalletData import com.tangem.tap.features.wallet.ui.BalanceStatus +import com.tangem.tap.features.wallet.ui.images.load import com.tangem.tap.store import com.tangem.wallet.R import com.tangem.wallet.databinding.ItemCurrencyWalletBinding diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/images/CurrencyIconView.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/images/CurrencyIconView.kt index 96d03cdd22..4f5fd38bf9 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/ui/images/CurrencyIconView.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/images/CurrencyIconView.kt @@ -22,14 +22,16 @@ class CurrencyIconView @JvmOverloads constructor( LayoutInflater.from(context), this, ) - private val currencyImageView: ImageFilterView + val currencyImageView: ImageFilterView get() = binding.ivCurrency - private val currencyTextView: TextView + val currencyTextView: TextView get() = binding.tvTokenLetter - private var isBlockchainBadgeVisible: Boolean + val blockchainBadge: ImageFilterView + get() = binding.ivBlockchainBadge + var isBlockchainBadgeVisible: Boolean get() = binding.ivBlockchainBadge.isVisible set(value) = binding.ivBlockchainBadge::isVisible.set(value) - private var isCustomCurrencyBadgeVisible: Boolean + var isCustomCurrencyBadgeVisible: Boolean get() = binding.customBadge.isVisible set(value) = binding.customBadge::isVisible.set(value) @@ -37,30 +39,30 @@ class CurrencyIconView @JvmOverloads constructor( minWidth = dpToPx(48f).roundToInt() minHeight = dpToPx(48f).roundToInt() } +} - fun load( - currency: Currency, - derivationStyle: DerivationStyle?, - ) { - isCustomCurrencyBadgeVisible = currency.isCustomCurrency(derivationStyle) +fun CurrencyIconView.load( + currency: Currency, + derivationStyle: DerivationStyle?, +) { + isCustomCurrencyBadgeVisible = currency.isCustomCurrency(derivationStyle) + + CurrencyIconRequest( + currencyImageView = currencyImageView, + currencyTextView = currencyTextView, + token = (currency as? Currency.Token)?.token, + blockchain = currency.blockchain, + ).load() + + if (currency.isToken()) { + // load a blockchain icon into the blockchain badge + isBlockchainBadgeVisible = true CurrencyIconRequest( - currencyImageView = currencyImageView, - currencyTextView = currencyTextView, - token = (currency as? Currency.Token)?.token, + currencyImageView = blockchainBadge, + currencyTextView = null, + token = null, blockchain = currency.blockchain, ).load() - - if (currency.isToken()) { - // load a blockchain icon into the blockchain badge - isBlockchainBadgeVisible = true - - CurrencyIconRequest( - currencyImageView = binding.ivBlockchainBadge, - currencyTextView = null, - token = null, - blockchain = currency.blockchain, - ).load() - } } } \ No newline at end of file