From a96272ee3b9e7fc39f86c5e8d1fb15f569b86d44 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 27 Nov 2024 14:43:47 +0400 Subject: [PATCH 1/3] Updated on 2026-08-14 --- .../ui/components/buttons/actions/Actions.kt | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/Actions.kt b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/Actions.kt index 77e06f0358..3fddfd6d06 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/Actions.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/Actions.kt @@ -23,6 +23,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider +import androidx.compose.ui.unit.dp import com.tangem.core.ui.R import com.tangem.core.ui.components.SpacerW8 import com.tangem.core.ui.extensions.TextReference @@ -78,6 +79,7 @@ fun ActionButton( ) } +@OptIn(ExperimentalFoundationApi::class) @Composable private fun Button( config: ActionButtonConfig, @@ -85,6 +87,7 @@ private fun Button( modifier: Modifier = Modifier, color: Color = TangemTheme.colors.button.secondary, ) { + val context = LocalContext.current val backgroundColor by animateColorAsState( targetValue = if (config.enabled) color else TangemTheme.colors.button.disabled, label = "Update background color", @@ -92,33 +95,9 @@ private fun Button( Box( modifier = modifier - .heightIn(min = TangemTheme.dimens.size36) + .heightIn(min = 36.dp) + .widthIn(min = 100.dp) .clip(shape) - .background(color = backgroundColor), - ) { - Content( - config = config, - modifier = Modifier.align(alignment = Alignment.Center), - ) - - if (config.isInProgress) { - Loading( - backgroundColor = backgroundColor, - modifier = Modifier - .matchParentSize() - .align(alignment = Alignment.Center), - ) - } - } -} - -@OptIn(ExperimentalFoundationApi::class) -@Composable -private fun Content(config: ActionButtonConfig, modifier: Modifier = Modifier) { - val context = LocalContext.current - - Row( - modifier = modifier .combinedClickable( enabled = config.enabled, onClick = config.onClick, @@ -131,7 +110,32 @@ private fun Content(config: ActionButtonConfig, modifier: Modifier = Modifier) { } }, ) - .padding(start = TangemTheme.dimens.spacing16, end = TangemTheme.dimens.spacing24) + .background(color = backgroundColor), + ) { + Content( + modifier = Modifier.align(Alignment.Center), + config = config, + ) + + if (config.isInProgress) { + Loading( + modifier = Modifier + .align(alignment = Alignment.Center) + .matchParentSize(), + backgroundColor = backgroundColor, + ) + } + } +} + +@Composable +private fun Content(config: ActionButtonConfig, modifier: Modifier = Modifier) { + Row( + modifier = modifier + .padding( + start = TangemTheme.dimens.spacing16, + end = TangemTheme.dimens.spacing24, + ) .padding(vertical = TangemTheme.dimens.spacing8), horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically, From 9c53805c51056d6ca48a290f9ffd7a877192c196 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 27 Nov 2024 19:00:11 +0400 Subject: [PATCH 2/3] Updated on 2026-08-14 --- .../ui/components/buttons/actions/Actions.kt | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/Actions.kt b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/Actions.kt index 3fddfd6d06..14d96a5225 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/Actions.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/Actions.kt @@ -140,33 +140,25 @@ private fun Content(config: ActionButtonConfig, modifier: Modifier = Modifier) { horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically, ) { - val iconTint by animateColorAsState( - targetValue = when { - !config.enabled -> TangemTheme.colors.icon.informative - config.dimContent -> TangemTheme.colors.icon.informative - else -> TangemTheme.colors.icon.primary1 - }, - label = "Update tint color", - ) - + val iconTint = when { + !config.enabled -> TangemTheme.colors.icon.informative + config.dimContent -> TangemTheme.colors.icon.informative + else -> TangemTheme.colors.icon.primary1 + } Icon( + modifier = Modifier.size(size = TangemTheme.dimens.size20), painter = painterResource(id = config.iconResId), contentDescription = null, - modifier = Modifier.size(size = TangemTheme.dimens.size20), tint = iconTint, ) SpacerW8() - val textColor by animateColorAsState( - targetValue = when { - !config.enabled -> TangemTheme.colors.text.disabled - config.dimContent -> TangemTheme.colors.text.tertiary - else -> TangemTheme.colors.text.primary1 - }, - label = "Update text color", - ) - + val textColor = when { + !config.enabled -> TangemTheme.colors.text.disabled + config.dimContent -> TangemTheme.colors.text.tertiary + else -> TangemTheme.colors.text.primary1 + } Text( text = config.text.resolveReference(), color = textColor, From 36c84f0483d6f4b4a9d6721466c8ee6120adebec Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 27 Nov 2024 17:14:29 +0400 Subject: [PATCH 3/3] Updated on 2026-08-14 --- .../organizetokens/OrganizeTokensScreen.kt | 6 +++--- .../organizetokens/OrganizeTokensViewModel.kt | 13 +++++-------- .../organizetokens/model/OrganizeTokensListState.kt | 10 +--------- .../organizetokens/utils/dnd/DragAndDropAdapter.kt | 4 ++-- 4 files changed, 11 insertions(+), 22 deletions(-) diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensScreen.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensScreen.kt index 15a4f2250e..1c79fc38cd 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensScreen.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensScreen.kt @@ -246,6 +246,7 @@ private fun TopBar( horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing8), ) { RoundedActionButton( + modifier = Modifier.weight(1f), config = ActionButtonConfig( text = TextReference.Res(id = R.string.organize_tokens_sort_by_balance), iconResId = R.drawable.ic_sort_24, @@ -253,10 +254,10 @@ private fun TopBar( onClick = config.onSortClick, dimContent = config.isSortedByBalance, ), - modifier = Modifier.weight(1f), color = TangemTheme.colors.background.primary, ) RoundedActionButton( + modifier = Modifier.weight(1f), config = ActionButtonConfig( text = TextReference.Res( id = if (config.isGrouped) { @@ -265,11 +266,10 @@ private fun TopBar( R.string.organize_tokens_group }, ), - enabled = config.isEnabled, iconResId = R.drawable.ic_group_24, + enabled = config.isEnabled, onClick = config.onGroupClick, ), - modifier = Modifier.weight(1f), color = TangemTheme.colors.background.primary, ) } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensViewModel.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensViewModel.kt index 93c0aab777..a27f15bdab 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensViewModel.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensViewModel.kt @@ -23,11 +23,9 @@ import com.tangem.feature.wallet.presentation.organizetokens.utils.dnd.DragAndDr import com.tangem.feature.wallet.presentation.router.InnerWalletRouter import com.tangem.feature.wallet.presentation.router.WalletRoute import com.tangem.utils.Provider -import com.tangem.utils.coroutines.CoroutineDispatcherProvider import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext import javax.inject.Inject @Suppress("LongParameterList") @@ -40,7 +38,6 @@ internal class OrganizeTokensViewModel @Inject constructor( private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, private val getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase, private val analyticsEventsHandler: AnalyticsEventHandler, - private val dispatchers: CoroutineDispatcherProvider, savedStateHandle: SavedStateHandle, ) : ViewModel(), DefaultLifecycleObserver, OrganizeTokensIntents { @@ -95,7 +92,7 @@ internal class OrganizeTokensViewModel @Inject constructor( analyticsEventsHandler.send(PortfolioOrganizeTokensAnalyticsEvent.ByBalance) - viewModelScope.launch(dispatchers.default) { + viewModelScope.launch { toggleTokenListSortingUseCase(list).fold( ifLeft = stateHolder::updateStateWithError, ifRight = { @@ -111,7 +108,7 @@ internal class OrganizeTokensViewModel @Inject constructor( analyticsEventsHandler.send(PortfolioOrganizeTokensAnalyticsEvent.Group) - viewModelScope.launch(dispatchers.default) { + viewModelScope.launch { toggleTokenListGroupingUseCase(list).fold( ifLeft = stateHolder::updateStateWithError, ifRight = { @@ -123,7 +120,7 @@ internal class OrganizeTokensViewModel @Inject constructor( } override fun onApplyClick() { - viewModelScope.launch(dispatchers.default) { + viewModelScope.launch { stateHolder.updateStateToDisplayProgress() val listState = uiState.value.itemsState @@ -147,8 +144,8 @@ internal class OrganizeTokensViewModel @Inject constructor( result.fold( ifLeft = stateHolder::updateStateWithError, ifRight = { + router.popBackStack() stateHolder.updateStateToHideProgress() - withContext(dispatchers.main) { router.popBackStack() } }, ) } @@ -161,7 +158,7 @@ internal class OrganizeTokensViewModel @Inject constructor( } private fun bootstrapTokenList() { - viewModelScope.launch(dispatchers.default) { + viewModelScope.launch { val tokenList = getTokenList() ?: return@launch stateHolder.updateStateWithTokenList(tokenList) diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/model/OrganizeTokensListState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/model/OrganizeTokensListState.kt index 2bc9fe9dd9..111a8b5211 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/model/OrganizeTokensListState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/model/OrganizeTokensListState.kt @@ -16,15 +16,7 @@ internal sealed class OrganizeTokensListState { override val items: PersistentList, ) : OrganizeTokensListState() - object Empty : OrganizeTokensListState() { + data object Empty : OrganizeTokensListState() { override val items: PersistentList = persistentListOf() } - - fun copySealed(items: PersistentList = this.items): OrganizeTokensListState { - return when (this) { - is GroupedByNetwork -> copy(items = items) - is Ungrouped -> copy(items = items) - is Empty -> Empty - } - } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/utils/dnd/DragAndDropAdapter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/utils/dnd/DragAndDropAdapter.kt index c567a63a5d..39d8295da6 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/utils/dnd/DragAndDropAdapter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/utils/dnd/DragAndDropAdapter.kt @@ -167,9 +167,9 @@ internal class DragAndDropAdapter( sealed class Type { - object Start : Type() + data object Start : Type() - object Dragged : Type() + data object Dragged : Type() data class End(val isItemsOrderChanged: Boolean) : Type() }