diff --git a/core/ui/src/main/java/com/tangem/core/ui/ds/topbar/TangemTopBar.kt b/core/ui/src/main/java/com/tangem/core/ui/ds/topbar/TangemTopBar.kt index c9dca9b4fc..383047dd49 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/ds/topbar/TangemTopBar.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/ds/topbar/TangemTopBar.kt @@ -26,6 +26,8 @@ import com.tangem.core.ui.R import com.tangem.core.ui.extensions.* import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreviewRedesign +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.persistentListOf /** * A top bar composable that displays a title and optional start and end icons. @@ -34,8 +36,8 @@ import com.tangem.core.ui.res.TangemThemePreviewRedesign * @param title The title text to be displayed in the center of the top bar. * @param modifier Modifier to be applied to the top bar. * @param subtitle Optional subtitle text to be displayed below the title. - * @param startActionUM Optional action data for the start action icon. - * @param endActionUM Optional action data for the end action icon. + * @param startAction Optional action data for the start action icon. + * @param endActions List of end action icons to display on the right side. * @param titleIconRes Optional drawable resource ID for the icon to be displayed next to the title. * [REDACTED_AUTHOR] @@ -45,8 +47,8 @@ fun TangemTopBar( modifier: Modifier = Modifier, title: TextReference? = null, subtitle: TextReference? = null, - startActionUM: TangemTopBarActionUM? = null, - endActionUM: TangemTopBarActionUM? = null, + startAction: TangemTopBarActionUM? = null, + endActions: ImmutableList = persistentListOf(), @DrawableRes titleIconRes: Int? = null, ) { TangemTopBar( @@ -54,13 +56,19 @@ fun TangemTopBar( subtitle = subtitle, titleIconRes = titleIconRes, modifier = modifier, - startContent = if (startActionUM != null) { - { TangemTopBarActionContent(startActionUM) } + startContent = if (startAction != null) { + { TangemTopBarActionContent(startAction) } } else { null }, - endContent = if (endActionUM != null) { - { TangemTopBarActionContent(endActionUM) } + endContent = if (endActions.isNotEmpty()) { + { + Row(horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens2.x1)) { + endActions.forEach { action -> + TangemTopBarActionContent(action) + } + } + } } else { null }, @@ -215,7 +223,17 @@ private fun TangemTopBar_Preview(@PreviewParameter(PreviewProvider::class) param titleIconRes = params.titleIconRes, modifier = Modifier.background(TangemTheme.colors2.surface.level1), startContent = params.startActionUM?.let { { TangemTopBarActionContent(it) } }, - endContent = params.endActionUM?.let { { TangemTopBarActionContent(it) } }, + endContent = if (params.endActions.isNotEmpty()) { + { + Row(horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens2.x1)) { + params.endActions.forEach { action -> + TangemTopBarActionContent(action) + } + } + } + } else { + null + }, ) } } @@ -225,7 +243,7 @@ private class TangemTopBarPreviewData( val subtitle: TextReference? = null, val titleIconRes: Int? = null, val startActionUM: TangemTopBarActionUM? = null, - val endActionUM: TangemTopBarActionUM? = null, + val endActions: ImmutableList = persistentListOf(), ) private class PreviewProvider : PreviewParameterProvider { @@ -238,11 +256,11 @@ private class PreviewProvider : PreviewParameterProvider) + + /** Open QR scanner screen */ + fun openQrScanner() } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateController.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateController.kt index b1ddbd67b7..89bff8d53b 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateController.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateController.kt @@ -130,7 +130,7 @@ internal class WalletStateController @Inject constructor( private fun getInitialState(): WalletScreenState { return WalletScreenState( - topBarConfig = WalletTopBarConfig(onDetailsClick = {}), + topBarConfig = WalletTopBarConfig(), selectedWalletIndex = NOT_INITIALIZED_WALLET_INDEX, wallets = persistentListOf(), wallets2 = persistentListOf(), diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletTopBarConfig.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletTopBarConfig.kt index 0bf162e9c7..717a80fe24 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletTopBarConfig.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletTopBarConfig.kt @@ -1,8 +1,16 @@ package com.tangem.feature.wallet.presentation.wallet.state.model +import androidx.compose.runtime.Immutable +import com.tangem.core.ui.ds.topbar.TangemTopBarActionUM +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.persistentListOf + /** * Wallet screen top bar config * - * @property onDetailsClick lambda be invoked when details button is clicked + * @property endActions list of top bar end action buttons (e.g. QR scan, More) */ -internal data class WalletTopBarConfig(val onDetailsClick: () -> Unit) \ No newline at end of file +@Immutable +internal data class WalletTopBarConfig( + val endActions: ImmutableList = persistentListOf(), +) \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/InitializeWalletsTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/InitializeWalletsTransformer.kt index eb010c9a39..a79d895999 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/InitializeWalletsTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/InitializeWalletsTransformer.kt @@ -1,7 +1,9 @@ package com.tangem.feature.wallet.presentation.wallet.state.transformers +import com.tangem.core.ui.R as CoreUiR import com.tangem.common.ui.userwallet.converter.WalletIconUMConverter import com.tangem.core.ui.ds.button.TangemButtonUM +import com.tangem.core.ui.ds.topbar.TangemTopBarActionUM import com.tangem.domain.card.common.util.cardTypesResolver import com.tangem.domain.models.wallet.UserWallet import com.tangem.domain.models.wallet.isLocked @@ -25,6 +27,7 @@ internal class InitializeWalletsTransformer( private val clickIntents: WalletClickIntents, private val walletImageResolver: WalletImageResolver, private val getWalletIconUseCase: GetWalletIconUseCase, + private val isMainScreenQrScanningEnabled: Boolean = false, ) : WalletScreenStateTransformer { private val walletLoadingStateFactory by lazy { @@ -60,7 +63,20 @@ internal class InitializeWalletsTransformer( private fun createTopBarConfig(): WalletTopBarConfig { return WalletTopBarConfig( - onDetailsClick = clickIntents::onDetailsClick, + endActions = listOfNotNull( + if (isMainScreenQrScanningEnabled) { + TangemTopBarActionUM( + iconRes = CoreUiR.drawable.ic_qrcode_scaner_24, + onClick = clickIntents::onScanQrClick, + ) + } else { + null + }, + TangemTopBarActionUM( + iconRes = CoreUiR.drawable.ic_more_default_24, + onClick = clickIntents::onDetailsClick, + ), + ).toPersistentList(), ) } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletTopBar.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletTopBar.kt index 7782f92342..e2eb07e356 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletTopBar.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletTopBar.kt @@ -25,6 +25,7 @@ import com.tangem.feature.wallet.impl.R import com.tangem.feature.wallet.presentation.common.WalletPreviewDataLegacy import com.tangem.feature.wallet.presentation.wallet.state.model.WalletTopBarConfig import dev.chrisbanes.haze.HazeProgressive +import kotlinx.collections.immutable.persistentListOf private const val VISIBILITY_THRESHOLD = 0.5f @@ -54,16 +55,11 @@ internal fun WalletTopBar( TangemTopBar( title = wrappedBalance, - startActionUM = TangemTopBarActionUM( + startAction = TangemTopBarActionUM( iconRes = R.drawable.ic_tangem_24, isActionable = false, ), - endActionUM = TangemTopBarActionUM( - iconRes = R.drawable.ic_more_default_24, - isActionable = true, - onClick = topBarConfig.onDetailsClick, - ghostModeProgress = behavior.state.collapsedFraction, - ), + endActions = topBarConfig.endActions, modifier = Modifier .statusBarsPadding() .testTag(MainScreenTestTags.TOP_BAR), @@ -85,8 +81,15 @@ internal fun WalletTopBar(config: WalletTopBarConfig) { Icon(painter = painterResource(id = R.drawable.img_tangem_logo_90_24), contentDescription = null) }, actions = { - IconButton(onClick = config.onDetailsClick, modifier = Modifier.testTag(MainScreenTestTags.MORE_BUTTON)) { - Icon(painter = painterResource(id = R.drawable.ic_more_vertical_24), contentDescription = null) + config.endActions.forEach { action -> + if (action.onClick != null) { + IconButton(onClick = action.onClick!!) { + Icon( + painter = painterResource(id = action.iconRes), + contentDescription = null, + ) + } + } } }, colors = TopAppBarDefaults.topAppBarColors( @@ -115,7 +118,31 @@ private fun Preview_WalletTopBar() { private fun WalletTopBar_Preview() { TangemThemePreviewRedesign { WalletTopBar( - topBarConfig = WalletTopBarConfig(onDetailsClick = {}), + topBarConfig = WalletTopBarConfig(), + walletBalance = stringReference("$ 8923,05"), + behavior = rememberTangemExitUntilCollapsedScrollBehavior(), + ) + } +} + +@Composable +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +private fun WalletTopBar_WithQrButton_Preview() { + TangemThemePreviewRedesign { + WalletTopBar( + topBarConfig = WalletTopBarConfig( + endActions = persistentListOf( + TangemTopBarActionUM( + iconRes = com.tangem.core.ui.R.drawable.ic_qrcode_scaner_24, + onClick = {}, + ), + TangemTopBarActionUM( + iconRes = R.drawable.ic_more_default_24, + onClick = {}, + ), + ), + ), walletBalance = stringReference("$ 8923,05"), behavior = rememberTangemExitUntilCollapsedScrollBehavior(), )