Updated on 2026-08-14
This commit is contained in:
parent
36b4671a05
commit
eab83c7675
18 changed files with 113 additions and 98 deletions
|
|
@ -9,9 +9,9 @@ import com.tangem.core.ui.extensions.TextReference
|
|||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.feature.wallet.presentation.common.state.TokenItemState
|
||||
import com.tangem.feature.wallet.presentation.common.state.TokenItemState.TokenOptionsState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.DraggableItem
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.OrganizeTokensListState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.OrganizeTokensState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.DraggableItem
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensListState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensState
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.*
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.components.*
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTokensListState.TokensListItemState
|
||||
|
|
@ -206,12 +206,13 @@ internal object WalletPreviewData {
|
|||
|
||||
val groupedOrganizeTokensState by lazy {
|
||||
OrganizeTokensState(
|
||||
onBackClick = {},
|
||||
itemsState = OrganizeTokensListState.GroupedByNetwork(
|
||||
items = draggableItems,
|
||||
),
|
||||
header = OrganizeTokensState.HeaderConfig(
|
||||
onSortByBalanceClick = {},
|
||||
onGroupByNetworkClick = {},
|
||||
onSortClick = {},
|
||||
onGroupClick = {},
|
||||
),
|
||||
dndConfig = OrganizeTokensState.DragAndDropConfig(
|
||||
onItemDragged = { _, _ -> },
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tangem.feature.wallet.presentation.organizetokens
|
||||
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.DraggableItem
|
||||
import org.burnoutcrew.reorderable.ItemPosition
|
||||
|
||||
internal interface OrganizeTokensIntents {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,9 @@ import com.tangem.feature.wallet.impl.R
|
|||
import com.tangem.feature.wallet.presentation.common.WalletPreviewData
|
||||
import com.tangem.feature.wallet.presentation.common.component.DraggableNetworkGroupItem
|
||||
import com.tangem.feature.wallet.presentation.common.component.DraggableTokenItem
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.DraggableItem
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensListState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensState
|
||||
import org.burnoutcrew.reorderable.*
|
||||
|
||||
@Composable
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import com.tangem.common.Provider
|
|||
import com.tangem.domain.tokens.error.TokenListError
|
||||
import com.tangem.domain.tokens.error.TokenListSortingError
|
||||
import com.tangem.domain.tokens.model.TokenList
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensListState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.utils.common.updateSorting
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.utils.converter.InProgressStateConverter
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.utils.converter.TokenListToStateConverter
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.lifecycle.viewModelScope
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.feature.wallet.presentation.common.WalletPreviewData
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.DraggableItem
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensListState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.utils.common.*
|
||||
import com.tangem.feature.wallet.presentation.router.InnerWalletRouter
|
||||
import com.tangem.feature.wallet.presentation.router.WalletRoute
|
||||
|
|
|
|||
|
|
@ -1,60 +1,8 @@
|
|||
package com.tangem.feature.wallet.presentation.organizetokens
|
||||
package com.tangem.feature.wallet.presentation.organizetokens.model
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import com.tangem.feature.wallet.presentation.common.state.TokenItemState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.DraggableItem.RoundingMode
|
||||
import kotlinx.collections.immutable.PersistentList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import org.burnoutcrew.reorderable.ItemPosition
|
||||
|
||||
@Immutable
|
||||
internal data class OrganizeTokensState(
|
||||
val onBackClick: () -> Unit,
|
||||
val itemsState: OrganizeTokensListState,
|
||||
val header: HeaderConfig,
|
||||
val actions: ActionsConfig,
|
||||
val dndConfig: DragAndDropConfig,
|
||||
) {
|
||||
|
||||
data class HeaderConfig(
|
||||
val isEnabled: Boolean = false,
|
||||
val isSortedByBalance: Boolean = false,
|
||||
val isGrouped: Boolean = false,
|
||||
val onSortClick: () -> Unit,
|
||||
val onGroupClick: () -> Unit,
|
||||
)
|
||||
|
||||
data class ActionsConfig(
|
||||
val canApply: Boolean = false,
|
||||
val showApplyProgress: Boolean = false,
|
||||
val onApplyClick: () -> Unit,
|
||||
val onCancelClick: () -> Unit,
|
||||
)
|
||||
|
||||
data class DragAndDropConfig(
|
||||
val onItemDragged: (ItemPosition, ItemPosition) -> Unit,
|
||||
val canDragItemOver: (ItemPosition, ItemPosition) -> Boolean,
|
||||
val onItemDragEnd: () -> Unit,
|
||||
val onDragStart: (DraggableItem) -> Unit,
|
||||
)
|
||||
}
|
||||
|
||||
@Immutable
|
||||
internal sealed class OrganizeTokensListState {
|
||||
abstract val items: PersistentList<DraggableItem>
|
||||
|
||||
data class GroupedByNetwork(
|
||||
override val items: PersistentList<DraggableItem>,
|
||||
) : OrganizeTokensListState()
|
||||
|
||||
data class Ungrouped(
|
||||
override val items: PersistentList<DraggableItem.Token>,
|
||||
) : OrganizeTokensListState()
|
||||
|
||||
object Empty : OrganizeTokensListState() {
|
||||
override val items: PersistentList<DraggableItem> = persistentListOf()
|
||||
}
|
||||
}
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.DraggableItem.RoundingMode
|
||||
|
||||
/**
|
||||
* Helper class for the DND list items
|
||||
|
|
@ -152,4 +100,30 @@ internal sealed class DraggableItem {
|
|||
* */
|
||||
data class All(override val showGap: Boolean = false) : RoundingMode()
|
||||
}
|
||||
|
||||
/**
|
||||
* Update item [RoundingMode]
|
||||
*
|
||||
* @param mode new [RoundingMode]
|
||||
*
|
||||
* @return updated [DraggableItem]
|
||||
* */
|
||||
fun updateRoundingMode(mode: RoundingMode): DraggableItem = when (this) {
|
||||
is GroupPlaceholder -> this
|
||||
is GroupHeader -> this.copy(roundingMode = mode)
|
||||
is Token -> this.copy(roundingMode = mode)
|
||||
}
|
||||
|
||||
/**
|
||||
* Update item shadow visibility
|
||||
*
|
||||
* @param show if true then item should be elevated
|
||||
*
|
||||
* @return updated [DraggableItem]
|
||||
* */
|
||||
fun updateShadowVisibility(show: Boolean): DraggableItem = when (this) {
|
||||
is GroupPlaceholder -> this
|
||||
is GroupHeader -> this.copy(showShadow = show)
|
||||
is Token -> this.copy(showShadow = show)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.tangem.feature.wallet.presentation.organizetokens.model
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import kotlinx.collections.immutable.PersistentList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
|
||||
@Immutable
|
||||
internal sealed class OrganizeTokensListState {
|
||||
abstract val items: PersistentList<DraggableItem>
|
||||
|
||||
data class GroupedByNetwork(
|
||||
override val items: PersistentList<DraggableItem>,
|
||||
) : OrganizeTokensListState()
|
||||
|
||||
data class Ungrouped(
|
||||
override val items: PersistentList<DraggableItem.Token>,
|
||||
) : OrganizeTokensListState()
|
||||
|
||||
object Empty : OrganizeTokensListState() {
|
||||
override val items: PersistentList<DraggableItem> = persistentListOf()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package com.tangem.feature.wallet.presentation.organizetokens.model
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import org.burnoutcrew.reorderable.ItemPosition
|
||||
|
||||
@Immutable
|
||||
internal data class OrganizeTokensState(
|
||||
val onBackClick: () -> Unit,
|
||||
val itemsState: OrganizeTokensListState,
|
||||
val header: HeaderConfig,
|
||||
val actions: ActionsConfig,
|
||||
val dndConfig: DragAndDropConfig,
|
||||
) {
|
||||
|
||||
data class HeaderConfig(
|
||||
val isEnabled: Boolean = false,
|
||||
val isSortedByBalance: Boolean = false,
|
||||
val isGrouped: Boolean = false,
|
||||
val onSortClick: () -> Unit,
|
||||
val onGroupClick: () -> Unit,
|
||||
)
|
||||
|
||||
data class ActionsConfig(
|
||||
val canApply: Boolean = false,
|
||||
val showApplyProgress: Boolean = false,
|
||||
val onApplyClick: () -> Unit,
|
||||
val onCancelClick: () -> Unit,
|
||||
)
|
||||
|
||||
data class DragAndDropConfig(
|
||||
val onItemDragged: (ItemPosition, ItemPosition) -> Unit,
|
||||
val canDragItemOver: (ItemPosition, ItemPosition) -> Boolean,
|
||||
val onItemDragEnd: () -> Unit,
|
||||
val onDragStart: (DraggableItem) -> Unit,
|
||||
)
|
||||
}
|
||||
|
|
@ -1,33 +1,6 @@
|
|||
package com.tangem.feature.wallet.presentation.organizetokens.utils.common
|
||||
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.DraggableItem
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.DraggableItem.RoundingMode
|
||||
|
||||
/**
|
||||
* Update item [RoundingMode]
|
||||
*
|
||||
* @param mode new [RoundingMode]
|
||||
*
|
||||
* @return updated [DraggableItem]
|
||||
* */
|
||||
internal fun DraggableItem.updateRoundingMode(mode: RoundingMode): DraggableItem = when (this) {
|
||||
is DraggableItem.GroupPlaceholder -> this
|
||||
is DraggableItem.GroupHeader -> this.copy(roundingMode = mode)
|
||||
is DraggableItem.Token -> this.copy(roundingMode = mode)
|
||||
}
|
||||
|
||||
/**
|
||||
* Update item shadow visibility
|
||||
*
|
||||
* @param show if true then item should be elevated
|
||||
*
|
||||
* @return updated [DraggableItem]
|
||||
* */
|
||||
internal fun DraggableItem.updateShadowVisibility(show: Boolean): DraggableItem = when (this) {
|
||||
is DraggableItem.GroupPlaceholder -> this
|
||||
is DraggableItem.GroupHeader -> this.copy(showShadow = show)
|
||||
is DraggableItem.Token -> this.copy(showShadow = show)
|
||||
}
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.DraggableItem
|
||||
|
||||
internal fun getGroupPlaceholder(index: Int): DraggableItem.GroupPlaceholder {
|
||||
return DraggableItem.GroupPlaceholder(id = "placeholder_${index.inc()}")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.tangem.feature.wallet.presentation.organizetokens.utils.common
|
||||
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.DraggableItem
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.DraggableItem
|
||||
import kotlinx.collections.immutable.PersistentList
|
||||
import org.burnoutcrew.reorderable.ItemPosition
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.tangem.feature.wallet.presentation.organizetokens.utils.common
|
||||
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.DraggableItem
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.OrganizeTokensListState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.DraggableItem
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensListState
|
||||
import kotlinx.collections.immutable.PersistentList
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.tangem.feature.wallet.presentation.organizetokens.utils.converter
|
||||
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.OrganizeTokensState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensState
|
||||
import com.tangem.utils.converter.TwoWayConverter
|
||||
|
||||
internal class InProgressStateConverter : TwoWayConverter<OrganizeTokensState, OrganizeTokensState> {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ package com.tangem.feature.wallet.presentation.organizetokens.utils.converter
|
|||
|
||||
import com.tangem.common.Provider
|
||||
import com.tangem.domain.tokens.model.TokenList
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.OrganizeTokensListState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.OrganizeTokensState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensListState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.utils.converter.items.TokenListToListStateConverter
|
||||
import com.tangem.utils.converter.Converter
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package com.tangem.feature.wallet.presentation.organizetokens.utils.converter.er
|
|||
|
||||
import com.tangem.common.Provider
|
||||
import com.tangem.domain.tokens.error.TokenListError
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.OrganizeTokensState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.utils.converter.InProgressStateConverter
|
||||
import com.tangem.utils.converter.Converter
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package com.tangem.feature.wallet.presentation.organizetokens.utils.converter.er
|
|||
|
||||
import com.tangem.common.Provider
|
||||
import com.tangem.domain.tokens.error.TokenListSortingError
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.OrganizeTokensState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.utils.converter.InProgressStateConverter
|
||||
import com.tangem.utils.converter.Converter
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import com.tangem.domain.tokens.model.CryptoCurrency
|
|||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
import com.tangem.feature.wallet.impl.R
|
||||
import com.tangem.feature.wallet.presentation.common.state.TokenItemState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.DraggableItem
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.DraggableItem
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.utils.common.getGroupHeaderId
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.utils.common.getTokenItemId
|
||||
import com.tangem.utils.converter.Converter
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.tangem.feature.wallet.presentation.organizetokens.utils.converter.items
|
||||
|
||||
import com.tangem.domain.tokens.model.NetworkGroup
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.DraggableItem
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.DraggableItem
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.utils.common.getGroupHeaderId
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.utils.common.getGroupPlaceholder
|
||||
import com.tangem.utils.converter.Converter
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.tangem.feature.wallet.presentation.organizetokens.utils.converter.items
|
||||
|
||||
import com.tangem.domain.tokens.model.TokenList
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.OrganizeTokensListState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensListState
|
||||
import com.tangem.feature.wallet.presentation.organizetokens.utils.common.uniteItems
|
||||
import com.tangem.utils.converter.Converter
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue