From 4a8701f079e992a7fe9cae4cfd20a4d8cb6001ab Mon Sep 17 00:00:00 2001 From: chyngyz Date: Tue, 28 Jan 2025 12:33:02 +0600 Subject: [PATCH] Add token to watchlist from search page --- .../market/search/MarketSearchFragment.kt | 108 +++++++----------- 1 file changed, 41 insertions(+), 67 deletions(-) diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/search/MarketSearchFragment.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/search/MarketSearchFragment.kt index b8c34269c2..6cfeabdb08 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/search/MarketSearchFragment.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/search/MarketSearchFragment.kt @@ -3,36 +3,26 @@ package io.horizontalsystems.bankwallet.modules.market.search import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.background -import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.IntrinsicSize import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.Divider -import androidx.compose.material.Icon import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.saveable.rememberSaveable -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.focus.FocusRequester -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 @@ -51,8 +41,8 @@ import io.horizontalsystems.bankwallet.core.stats.stat import io.horizontalsystems.bankwallet.core.stats.statSection import io.horizontalsystems.bankwallet.modules.coin.CoinFragment import io.horizontalsystems.bankwallet.modules.market.search.MarketSearchModule.CoinItem -import io.horizontalsystems.bankwallet.modules.walletconnect.list.ui.DraggableCardSimple import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme +import io.horizontalsystems.bankwallet.ui.compose.components.ButtonSecondaryCircle import io.horizontalsystems.bankwallet.ui.compose.components.HeaderStick import io.horizontalsystems.bankwallet.ui.compose.components.HsImage import io.horizontalsystems.bankwallet.ui.compose.components.ListEmptyView @@ -61,10 +51,7 @@ import io.horizontalsystems.bankwallet.ui.compose.components.SectionItemBordered import io.horizontalsystems.bankwallet.ui.compose.components.body_leah import io.horizontalsystems.bankwallet.ui.compose.components.subhead2_grey import io.horizontalsystems.marketkit.models.Coin -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch import java.util.Optional -import kotlin.jvm.optionals.getOrNull class MarketSearchFragment : BaseComposeFragment() { @Composable @@ -151,9 +138,6 @@ fun MarketSearchResults( icon = R.drawable.ic_not_found ) } else { - val coroutineScope = rememberCoroutineScope() - var revealedCardId by remember(*inputs) { mutableStateOf(null) } - LazyColumn( state = rememberSaveable( *inputs, @@ -179,57 +163,19 @@ fun MarketSearchResults( .fillMaxWidth() .height(IntrinsicSize.Max) ) { - Box( - modifier = Modifier - .fillMaxHeight() - .background(if (item.favourited) ComposeAppTheme.colors.lucian else ComposeAppTheme.colors.jacob) - .align(Alignment.CenterEnd) - .width(100.dp) - .clickable { - onFavoriteClick( - item.favourited, - coin.uid - ) - - coroutineScope.launch { - delay(200) - revealedCardId = null - } - }, - contentAlignment = Alignment.Center - ) { - Icon( - painter = painterResource(id = if (item.favourited) R.drawable.ic_star_off_24 else R.drawable.ic_star_24), - tint = ComposeAppTheme.colors.claude, - contentDescription = stringResource(if (item.favourited) R.string.CoinPage_Unfavorite else R.string.CoinPage_Favorite), + Box(modifier = Modifier.background(ComposeAppTheme.colors.tyler)) { + MarketCoin( + coinUid = coin.uid, + coinCode = coin.code, + coinName = coin.name, + coinIconUrl = coin.imageUrl, + alternativeCoinIconUrl = coin.alternativeImageUrl, + coinIconPlaceholder = item.fullCoin.iconPlaceholder, + favourited = item.favourited, + onFavoriteClick = onFavoriteClick, + onClick = { onCoinClick(coin, section) }, ) } - val cardId = (section.title.getOrNull()?.let { stringResource(id = it) } ?: "") + coin.uid - DraggableCardSimple( - key = cardId, - isRevealed = revealedCardId == cardId, - cardOffset = 100f, - onReveal = { - if (revealedCardId != cardId) { - revealedCardId = cardId - } - }, - onConceal = { - revealedCardId = null - }, - content = { - Box(modifier = Modifier.background(ComposeAppTheme.colors.tyler)) { - MarketCoin( - coinCode = coin.code, - coinName = coin.name, - coinIconUrl = coin.imageUrl, - alternativeCoinIconUrl = coin.alternativeImageUrl, - coinIconPlaceholder = item.fullCoin.iconPlaceholder, - onClick = { onCoinClick(coin, section) } - ) - } - } - ) } } } @@ -249,11 +195,14 @@ fun MarketSearchResults( @Composable private fun MarketCoin( + coinUid: String, coinCode: String, coinName: String, coinIconUrl: String, alternativeCoinIconUrl: String?, coinIconPlaceholder: Int, + favourited: Boolean, + onFavoriteClick: (Boolean, String) -> Unit, onClick: () -> Unit, ) { @@ -261,6 +210,28 @@ private fun MarketCoin( borderTop = true, onClick = onClick ) { + if (favourited) { + ButtonSecondaryCircle( + modifier = Modifier.padding(end = 16.dp), + icon = R.drawable.ic_checkmark_20, + contentDescription = stringResource(R.string.CoinPage_Favorite), + tint = ComposeAppTheme.colors.dark, + background = ComposeAppTheme.colors.yellowD, + onClick = { + onFavoriteClick(true, coinUid) + } + ) + } else { + ButtonSecondaryCircle( + modifier = Modifier.padding(end = 16.dp), + icon = R.drawable.ic_plus_20, + contentDescription = stringResource(R.string.CoinPage_Favorite), + onClick = { + onFavoriteClick(false, coinUid) + } + ) + } + HsImage( url = coinIconUrl, alternativeUrl = alternativeCoinIconUrl, @@ -294,12 +265,15 @@ fun MarketCoinPreview() { val coin = Coin("ether", "Ethereum", "ETH") ComposeAppTheme { MarketCoin( + coin.uid, coin.code, coin.name, coin.imageUrl, null, R.drawable.coin_placeholder, - {}, + false, + { _, _ -> }, + {} ) } }