Updated on 2026-08-14
This commit is contained in:
commit
292b6e93e5
5 changed files with 53 additions and 68 deletions
|
|
@ -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,38 +110,55 @@ 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,
|
||||
) {
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -16,15 +16,7 @@ internal sealed class OrganizeTokensListState {
|
|||
override val items: PersistentList<DraggableItem>,
|
||||
) : OrganizeTokensListState()
|
||||
|
||||
object Empty : OrganizeTokensListState() {
|
||||
data object Empty : OrganizeTokensListState() {
|
||||
override val items: PersistentList<DraggableItem> = persistentListOf()
|
||||
}
|
||||
|
||||
fun copySealed(items: PersistentList<DraggableItem> = this.items): OrganizeTokensListState {
|
||||
return when (this) {
|
||||
is GroupedByNetwork -> copy(items = items)
|
||||
is Ungrouped -> copy(items = items)
|
||||
is Empty -> Empty
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue