From 142ba20e3512d988607798e06309b69ba88539e6 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 28 Oct 2024 13:22:03 +0400 Subject: [PATCH] Updated on 2026-08-14 --- .../core/ui/decorations/RoundedDecorations.kt | 63 ++++++++++--------- .../DefaultSelectTokenComponent.kt | 46 ++++++++++++++ .../selecttoken/SelectTokenComponent.kt | 32 ++++++++++ .../di/SelectTokenComponentModule.kt | 18 ++++++ .../selecttoken/ui/SelectToken.kt | 45 +++++++++++++ .../tokenlist/DefaultTokenListComponent.kt | 5 +- .../tokenlist/TokenListComponent.kt | 15 +++-- .../presentation/tokenlist/ui/TokenList.kt | 11 ++-- .../tokenlist/utils/SearchTokensManager.kt | 6 +- .../multicurrency/MultiCurrencyContent.kt | 1 + .../multicurrency/MultiCurrencyContentItem.kt | 13 +--- 11 files changed, 203 insertions(+), 52 deletions(-) create mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/selecttoken/DefaultSelectTokenComponent.kt create mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/selecttoken/SelectTokenComponent.kt create mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/selecttoken/di/SelectTokenComponentModule.kt create mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/selecttoken/ui/SelectToken.kt diff --git a/core/ui/src/main/java/com/tangem/core/ui/decorations/RoundedDecorations.kt b/core/ui/src/main/java/com/tangem/core/ui/decorations/RoundedDecorations.kt index dabc6f97e2..02615d9faa 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/decorations/RoundedDecorations.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/decorations/RoundedDecorations.kt @@ -1,11 +1,13 @@ package com.tangem.core.ui.decorations +import androidx.compose.foundation.background import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.composed import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.Dp import com.tangem.core.ui.res.TangemTheme @@ -15,46 +17,49 @@ fun Modifier.roundedShapeItemDecoration( lastIndex: Int, addDefaultPadding: Boolean = true, radius: Dp = TangemTheme.dimens.radius16, + backgroundColor: Color? = null, ): Modifier = composed { val modifier = if (addDefaultPadding) this.padding(horizontal = TangemTheme.dimens.spacing16) else this + + val applyTopPadding: @Composable Modifier.() -> Modifier = { + if (addDefaultPadding) { + padding(top = TangemTheme.dimens.spacing12) + } else { + this + } + } + + val applyShape: Modifier.(shape: RoundedCornerShape?) -> Modifier = { shape -> + if (backgroundColor != null) { + if (shape != null) { + background(color = backgroundColor, shape = shape) + } else { + background(color = backgroundColor) + } + } else { + if (shape != null) { + clip(shape = shape) + } else { + this + } + } + } + val isSingleItem = currentIndex == 0 && lastIndex == 0 when { isSingleItem -> { modifier - .then( - if (addDefaultPadding) { - Modifier.padding(top = TangemTheme.dimens.spacing12) - } else { - Modifier - }, - ) - .clip(shape = RoundedCornerShape(radius)) + .applyTopPadding() + .applyShape(RoundedCornerShape(radius)) } currentIndex == 0 -> { modifier - .then( - if (addDefaultPadding) { - Modifier.padding(top = TangemTheme.dimens.spacing12) - } else { - Modifier - }, - ) - .clip( - shape = RoundedCornerShape( - topStart = radius, - topEnd = radius, - ), - ) + .applyTopPadding() + .applyShape(RoundedCornerShape(topStart = radius, topEnd = radius)) } currentIndex == lastIndex -> { - modifier - .clip( - shape = RoundedCornerShape( - bottomStart = radius, - bottomEnd = radius, - ), - ) + modifier.applyShape(RoundedCornerShape(bottomStart = radius, bottomEnd = radius)) } - else -> modifier + else -> modifier.applyShape(null) } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/selecttoken/DefaultSelectTokenComponent.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/selecttoken/DefaultSelectTokenComponent.kt new file mode 100644 index 0000000000..680be64c0b --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/selecttoken/DefaultSelectTokenComponent.kt @@ -0,0 +1,46 @@ +package com.tangem.feature.wallet.presentation.selecttoken + +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import com.tangem.core.decompose.context.AppComponentContext +import com.tangem.core.decompose.context.child +import com.tangem.feature.wallet.presentation.selecttoken.ui.SelectToken +import com.tangem.feature.wallet.presentation.tokenlist.TokenListComponent +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject + +internal class DefaultSelectTokenComponent @AssistedInject constructor( + @Assisted appComponentContext: AppComponentContext, + tokenListComponentFactory: TokenListComponent.Factory, + @Assisted private val params: SelectTokenComponent.Params, +) : AppComponentContext by appComponentContext, SelectTokenComponent { + + private val tokenListComponent: TokenListComponent = tokenListComponentFactory.create( + context = child(key = "token_list"), + params = TokenListComponent.Params( + hasSearchBar = params.hasSearchBar, + userWalletId = params.userWalletId, + onTokenClick = params.onTokenClick, + ), + ) + + @Composable + override fun Content(modifier: Modifier) { + SelectToken( + titleResId = params.titleResId, + onBackClick = router::pop, + tokenListComponent = tokenListComponent, + modifier = modifier, + ) + } + + @AssistedFactory + interface Factory : SelectTokenComponent.Factory { + + override fun create( + context: AppComponentContext, + params: SelectTokenComponent.Params, + ): DefaultSelectTokenComponent + } +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/selecttoken/SelectTokenComponent.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/selecttoken/SelectTokenComponent.kt new file mode 100644 index 0000000000..ff36917781 --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/selecttoken/SelectTokenComponent.kt @@ -0,0 +1,32 @@ +package com.tangem.feature.wallet.presentation.selecttoken + +import androidx.annotation.StringRes +import com.tangem.core.decompose.factory.ComponentFactory +import com.tangem.core.ui.decompose.ComposableContentComponent +import com.tangem.domain.tokens.model.CryptoCurrencyStatus +import com.tangem.domain.wallets.models.UserWalletId + +/** + * Select token component + * +[REDACTED_AUTHOR] + */ +interface SelectTokenComponent : ComposableContentComponent { + + interface Factory : ComponentFactory + + /** + * Params + * + * @property hasSearchBar flag that indicates if search bar should be shown + * @property userWalletId id of multi-currency wallet + * @property titleResId resource id of title + * @property onTokenClick callback for token click + */ + data class Params( + val hasSearchBar: Boolean, + val userWalletId: UserWalletId, + @StringRes val titleResId: Int, + val onTokenClick: (CryptoCurrencyStatus) -> Unit, + ) +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/selecttoken/di/SelectTokenComponentModule.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/selecttoken/di/SelectTokenComponentModule.kt new file mode 100644 index 0000000000..620bf54e1b --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/selecttoken/di/SelectTokenComponentModule.kt @@ -0,0 +1,18 @@ +package com.tangem.feature.wallet.presentation.selecttoken.di + +import com.tangem.feature.wallet.presentation.selecttoken.DefaultSelectTokenComponent +import com.tangem.feature.wallet.presentation.selecttoken.SelectTokenComponent +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +internal interface SelectTokenComponentModule { + + @Binds + @Singleton + fun bindSelectTokenComponentFactory(factory: DefaultSelectTokenComponent.Factory): SelectTokenComponent.Factory +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/selecttoken/ui/SelectToken.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/selecttoken/ui/SelectToken.kt new file mode 100644 index 0000000000..56c6872198 --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/selecttoken/ui/SelectToken.kt @@ -0,0 +1,45 @@ +package com.tangem.feature.wallet.presentation.selecttoken.ui + +import androidx.activity.compose.BackHandler +import androidx.annotation.StringRes +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.imePadding +import androidx.compose.foundation.layout.systemBarsPadding +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.tangem.core.ui.components.appbar.AppBarWithBackButton +import com.tangem.core.ui.res.TangemTheme +import com.tangem.feature.wallet.impl.R +import com.tangem.feature.wallet.presentation.tokenlist.TokenListComponent + +@Composable +internal fun SelectToken( + @StringRes titleResId: Int, + onBackClick: () -> Unit, + tokenListComponent: TokenListComponent, + modifier: Modifier = Modifier, +) { + BackHandler(onBack = onBackClick) + + Column( + modifier = modifier + .background(TangemTheme.colors.background.secondary) + .imePadding() + .systemBarsPadding(), + ) { + AppBarWithBackButton( + onBackClick = onBackClick, + text = stringResource(id = titleResId), + iconRes = R.drawable.ic_close_24, + ) + + tokenListComponent.Content( + contentPadding = PaddingValues(vertical = 8.dp, horizontal = 16.dp), + modifier = Modifier, + ) + } +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/tokenlist/DefaultTokenListComponent.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/tokenlist/DefaultTokenListComponent.kt index c74231c846..86dfa0a67f 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/tokenlist/DefaultTokenListComponent.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/tokenlist/DefaultTokenListComponent.kt @@ -1,5 +1,6 @@ package com.tangem.feature.wallet.presentation.tokenlist +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.runtime.Composable import androidx.compose.runtime.Stable import androidx.compose.runtime.getValue @@ -22,10 +23,10 @@ internal class DefaultTokenListComponent @AssistedInject constructor( private val model: TokenListModel = getOrCreateModel(params) @Composable - override fun Content(modifier: Modifier) { + override fun Content(contentPadding: PaddingValues, modifier: Modifier) { val state by model.state.collectAsStateWithLifecycle() - TokenList(state = state, modifier = modifier) + TokenList(state = state, contentPadding = contentPadding, modifier = modifier) } @AssistedFactory diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/tokenlist/TokenListComponent.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/tokenlist/TokenListComponent.kt index 3c271c0894..4bb85444e3 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/tokenlist/TokenListComponent.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/tokenlist/TokenListComponent.kt @@ -1,14 +1,19 @@ package com.tangem.feature.wallet.presentation.tokenlist +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.runtime.Composable import androidx.compose.runtime.Stable +import androidx.compose.ui.Modifier import com.tangem.core.decompose.factory.ComponentFactory -import com.tangem.core.ui.decompose.ComposableContentComponent import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.wallets.models.UserWalletId /** Token list component that present list of token for multi-currency wallet */ @Stable -internal interface TokenListComponent : ComposableContentComponent { +internal interface TokenListComponent { + + @Composable + fun Content(contentPadding: PaddingValues, modifier: Modifier) /** Component factory */ interface Factory : ComponentFactory @@ -16,9 +21,9 @@ internal interface TokenListComponent : ComposableContentComponent { /** * Params * - * @property hasSearchBar flag that indicates if search bar should be shown - * @property userWalletId id of multi-currency wallet - * @property onTokenClick callback for token click + * @property hasSearchBar flag that indicates if search bar should be shown + * @property userWalletId id of multi-currency wallet + * @property onTokenClick callback for token click */ data class Params( val hasSearchBar: Boolean, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/tokenlist/ui/TokenList.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/tokenlist/ui/TokenList.kt index e780c03e44..68a102e845 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/tokenlist/ui/TokenList.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/tokenlist/ui/TokenList.kt @@ -1,8 +1,8 @@ package com.tangem.feature.wallet.presentation.tokenlist.ui import androidx.compose.foundation.background +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.runtime.Composable @@ -26,8 +26,8 @@ import com.tangem.feature.wallet.presentation.wallet.ui.components.multicurrency [REDACTED_AUTHOR] */ @Composable -internal fun TokenList(state: TokenListUM, modifier: Modifier = Modifier) { - LazyColumn(modifier = modifier) { +internal fun TokenList(state: TokenListUM, contentPadding: PaddingValues, modifier: Modifier = Modifier) { + LazyColumn(modifier = modifier, contentPadding = contentPadding) { itemsIndexed( items = state.items, key = { _, item -> item.id }, @@ -42,6 +42,7 @@ internal fun TokenList(state: TokenListUM, modifier: Modifier = Modifier) { currentIndex = index, lastIndex = state.items.lastIndex, addDefaultPadding = false, + backgroundColor = TangemTheme.colors.background.primary, ), ) }, @@ -55,10 +56,10 @@ private fun Preview_TokenList(@PreviewParameter(PreviewTokenListUMProvider::clas TangemThemePreview { TokenList( state = state, + contentPadding = PaddingValues(all = 16.dp), modifier = Modifier .fillMaxWidth() - .background(color = TangemTheme.colors.background.secondary) - .padding(16.dp), + .background(color = TangemTheme.colors.background.secondary), ) } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/tokenlist/utils/SearchTokensManager.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/tokenlist/utils/SearchTokensManager.kt index 98258cca19..ff57e2818c 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/tokenlist/utils/SearchTokensManager.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/tokenlist/utils/SearchTokensManager.kt @@ -23,7 +23,11 @@ internal class SearchTokensManager @Inject constructor() { suspend fun update(value: String) { coroutineScope { - withDebounce(jobHolder) { _query.value = value } + if (value.isEmpty()) { + _query.value = value + } else { + withDebounce(jobHolder) { _query.value = value } + } } } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/MultiCurrencyContent.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/MultiCurrencyContent.kt index e0563a4400..14c3dc4b41 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/MultiCurrencyContent.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/MultiCurrencyContent.kt @@ -64,6 +64,7 @@ private fun LazyListScope.contentItems( modifier = modifier.roundedShapeItemDecoration( currentIndex = index, lastIndex = items.lastIndex, + backgroundColor = TangemTheme.colors.background.primary, ), ) }, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/MultiCurrencyContentItem.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/MultiCurrencyContentItem.kt index 0b8e4ea13b..7f26ab0399 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/MultiCurrencyContentItem.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/multicurrency/MultiCurrencyContentItem.kt @@ -1,6 +1,5 @@ package com.tangem.feature.wallet.presentation.wallet.ui.components.multicurrency -import androidx.compose.foundation.background import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier @@ -8,7 +7,6 @@ import androidx.compose.ui.unit.dp import com.tangem.core.ui.components.fields.SearchBar import com.tangem.core.ui.components.token.TokenItem import com.tangem.core.ui.extensions.resolveReference -import com.tangem.core.ui.res.TangemTheme import com.tangem.feature.wallet.presentation.common.component.NetworkTitleItem import com.tangem.feature.wallet.presentation.wallet.state.model.WalletTokensListState.TokensListItemState @@ -26,24 +24,19 @@ internal fun MultiCurrencyContentItem( isBalanceHidden: Boolean, modifier: Modifier = Modifier, ) { - val modifierWithBackground = modifier.background(color = TangemTheme.colors.background.primary) - when (state) { is TokensListItemState.NetworkGroupTitle -> { - NetworkTitleItem(networkName = state.name.resolveReference(), modifier = modifierWithBackground) + NetworkTitleItem(networkName = state.name.resolveReference(), modifier = modifier) } is TokensListItemState.Token -> { TokenItem( state = state.state, isBalanceHidden = isBalanceHidden, - modifier = modifierWithBackground, + modifier = modifier, ) } is TokensListItemState.SearchBar -> { - SearchBar( - state = state.searchBarUM, - modifier = modifierWithBackground.padding(all = 12.dp), - ) + SearchBar(state = state.searchBarUM, modifier = modifier.padding(all = 12.dp)) } } } \ No newline at end of file