Updated on 2026-08-14

This commit is contained in:
Tangem 2023-08-03 22:59:39 +08:00
parent 06b13f2227
commit ff985dec4e
16 changed files with 246 additions and 159 deletions

View file

@ -14,6 +14,7 @@ import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameter
import com.tangem.core.ui.R
import com.tangem.core.ui.components.buttons.actions.ActionButton
import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.res.TangemTheme
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
@ -30,11 +31,7 @@ fun HorizontalActionChips(
verticalAlignment = Alignment.CenterVertically,
contentPadding = contentPadding,
) {
items(
items = buttons,
key = { it.text },
itemContent = { ActionButton(config = it) },
)
items(items = buttons, itemContent = { ActionButton(config = it) })
}
}
@ -61,22 +58,22 @@ private fun Preview_HorizontalActionChips_Dark(
private class ActionButtonConfigProvider : CollectionPreviewParameterProvider<ActionButtonConfig>(
collection = persistentListOf(
ActionButtonConfig(
text = "Buy",
text = TextReference.Str(value = "Buy"),
iconResId = R.drawable.ic_plus_24,
onClick = {},
),
ActionButtonConfig(
text = "Send",
text = TextReference.Str(value = "Send"),
iconResId = R.drawable.ic_arrow_up_24,
onClick = {},
),
ActionButtonConfig(
text = "Receive",
text = TextReference.Str(value = "Receive"),
iconResId = R.drawable.ic_arrow_down_24,
onClick = {},
),
ActionButtonConfig(
text = "Exchange",
text = TextReference.Str(value = "Exchange"),
iconResId = R.drawable.ic_exchange_vertical_24,
onClick = {},
),

View file

@ -1,6 +1,7 @@
package com.tangem.core.ui.components.buttons.actions
import androidx.annotation.DrawableRes
import com.tangem.core.ui.extensions.TextReference
/**
* Action button config
@ -13,7 +14,7 @@ import androidx.annotation.DrawableRes
[REDACTED_AUTHOR]
*/
data class ActionButtonConfig(
val text: String,
val text: TextReference,
@DrawableRes val iconResId: Int,
val onClick: () -> Unit,
val enabled: Boolean = true,

View file

@ -19,6 +19,8 @@ import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameter
import com.tangem.core.ui.R
import com.tangem.core.ui.components.SpacerW8
import com.tangem.core.ui.components.buttons.common.*
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.resolveReference
import com.tangem.core.ui.res.TangemTheme
/**
@ -103,7 +105,7 @@ private fun Button(
SpacerW8()
Text(
text = config.text,
text = config.text.resolveReference(),
color = if (config.enabled) TangemTheme.colors.text.primary1 else TangemTheme.colors.text.disabled,
overflow = TextOverflow.Ellipsis,
maxLines = 1,
@ -146,7 +148,17 @@ private fun Preview_ActionButton_Dark(@PreviewParameter(ActionStateProvider::cla
private class ActionStateProvider : CollectionPreviewParameterProvider<ActionButtonConfig>(
collection = listOf(
ActionButtonConfig(text = "Enabled", iconResId = R.drawable.ic_arrow_up_24, enabled = true, onClick = {}),
ActionButtonConfig(text = "Disabled", iconResId = R.drawable.ic_arrow_down_24, enabled = false, onClick = {}),
ActionButtonConfig(
text = TextReference.Str(value = "Enabled"),
iconResId = R.drawable.ic_arrow_up_24,
enabled = true,
onClick = {},
),
ActionButtonConfig(
text = TextReference.Str(value = "Disabled"),
iconResId = R.drawable.ic_arrow_down_24,
enabled = false,
onClick = {},
),
),
)

View file

@ -14,11 +14,15 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider
import com.tangem.core.ui.components.buttons.actions.ActionButton
import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig
import com.tangem.core.ui.extensions.resolveReference
import com.tangem.core.ui.res.TangemTheme
import com.tangem.core.ui.R
/**
* Placeholder for transaction's block without content
*
* @param state component state
* @param modifier modifier
*/
@Composable
fun EmptyTransactionBlock(state: EmptyTransactionsBlockState, modifier: Modifier = Modifier) {
Column(
@ -34,6 +38,7 @@ fun EmptyTransactionBlock(state: EmptyTransactionsBlockState, modifier: Modifier
painter = painterResource(id = state.iconRes),
contentDescription = null,
)
Text(
modifier = Modifier.padding(horizontal = TangemTheme.dimens.spacing32),
textAlign = TextAlign.Center,
@ -41,6 +46,7 @@ fun EmptyTransactionBlock(state: EmptyTransactionsBlockState, modifier: Modifier
style = TangemTheme.typography.body2,
color = TangemTheme.colors.text.secondary,
)
ActionButton(config = state.actionButtonConfig)
}
}
@ -67,26 +73,8 @@ private fun EmptyTransactionBlock_Dark(
private class EmptyTransactionBlockStateProvider : CollectionPreviewParameterProvider<EmptyTransactionsBlockState>(
collection = listOf(
EmptyTransactionsBlockState.Empty(
actionButtonConfig = ActionButtonConfig(
text = "Buy",
iconResId = R.drawable.ic_plus_24,
onClick = {},
),
),
EmptyTransactionsBlockState.FailedToLoad(
actionButtonConfig = ActionButtonConfig(
text = "Reload",
iconResId = R.drawable.ic_refresh_24,
onClick = {},
),
),
EmptyTransactionsBlockState.NotImplemented(
actionButtonConfig = ActionButtonConfig(
text = "Explore transaction history",
iconResId = R.drawable.ic_arrow_top_right_24,
onClick = {},
),
),
EmptyTransactionsBlockState.Empty(onClick = {}),
EmptyTransactionsBlockState.FailedToLoad(onClick = {}),
EmptyTransactionsBlockState.NotImplemented(onClick = {}),
),
)

View file

@ -1,37 +1,45 @@
package com.tangem.core.ui.components.transactions.empty
import androidx.annotation.DrawableRes
import com.tangem.core.ui.R
import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig
import com.tangem.core.ui.extensions.TextReference
sealed class EmptyTransactionsBlockState {
sealed class EmptyTransactionsBlockState(
val iconRes: Int,
val text: TextReference,
val actionButtonConfig: ActionButtonConfig,
) {
@get:DrawableRes
abstract val iconRes: Int
class FailedToLoad(onClick: () -> Unit) : EmptyTransactionsBlockState(
actionButtonConfig = ActionButtonConfig(
text = TextReference.Res(R.string.common_reload),
iconResId = R.drawable.ic_refresh_24,
onClick = onClick,
enabled = true,
),
iconRes = R.drawable.ic_alert_history_64,
text = TextReference.Res(R.string.transaction_history_error_failed_to_load),
)
abstract val text: TextReference
class Empty(onClick: (() -> Unit)?) : EmptyTransactionsBlockState(
actionButtonConfig = ActionButtonConfig(
text = TextReference.Res(R.string.common_buy),
iconResId = R.drawable.ic_plus_24,
onClick = onClick ?: {},
enabled = onClick != null,
),
iconRes = R.drawable.img_coin_64,
text = TextReference.Res(R.string.transaction_history_empty_transactions),
)
abstract val actionButtonConfig: ActionButtonConfig
data class FailedToLoad(
override val actionButtonConfig: ActionButtonConfig,
) : EmptyTransactionsBlockState() {
override val iconRes: Int = R.drawable.ic_alert_history_64
override val text: TextReference = TextReference.Res(R.string.transaction_history_error_failed_to_load)
}
data class Empty(
override val actionButtonConfig: ActionButtonConfig,
) : EmptyTransactionsBlockState() {
override val iconRes: Int = R.drawable.img_coin_64
override val text: TextReference = TextReference.Res(R.string.transaction_history_empty_transactions)
}
data class NotImplemented(
override val actionButtonConfig: ActionButtonConfig,
) : EmptyTransactionsBlockState() {
override val iconRes: Int = R.drawable.ic_compass_64
override val text: TextReference = TextReference.Res(R.string.transaction_history_not_supported_description)
}
class NotImplemented(onClick: () -> Unit) : EmptyTransactionsBlockState(
actionButtonConfig = ActionButtonConfig(
text = TextReference.Res(R.string.common_explore_transaction_history),
iconResId = R.drawable.ic_arrow_top_right_24,
onClick = onClick,
enabled = true,
),
iconRes = R.drawable.ic_compass_64,
text = TextReference.Res(R.string.transaction_history_not_supported_description),
)
}