From c831c3f659937e32178a843ba78e5c4d6e87196a Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 1 Feb 2023 12:51:21 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../EnrollBiometricsDialogConent.kt | 63 +--- .../ui/WalletSelectorBottomSheetFragment.kt | 14 +- .../ui/WalletSelectorScreenState.kt | 4 +- .../ui/WalletSelectorViewModel.kt | 41 ++- .../components/RemoveWalletDialogContent.kt | 24 ++ .../components/RenameWalletDialogContent.kt | 93 ++--- .../walletSelector/ui/model/DialogModel.kt | 14 + .../ui/model/RenameWalletDialog.kt | 10 - core/res/src/main/res/values-de/strings.xml | 1 + core/res/src/main/res/values-fr/strings.xml | 1 + core/res/src/main/res/values-it/strings.xml | 1 + core/res/src/main/res/values-ru/strings.xml | 1 + core/res/src/main/res/values/strings.xml | 1 + .../com/tangem/core/ui/components/Dialogs.kt | 338 +++++++++++++++--- 14 files changed, 421 insertions(+), 185 deletions(-) create mode 100644 app/src/main/java/com/tangem/tap/features/walletSelector/ui/components/RemoveWalletDialogContent.kt create mode 100644 app/src/main/java/com/tangem/tap/features/walletSelector/ui/model/DialogModel.kt delete mode 100644 app/src/main/java/com/tangem/tap/features/walletSelector/ui/model/RenameWalletDialog.kt diff --git a/app/src/main/java/com/tangem/tap/features/saveWallet/ui/components/EnrollBiometricsDialogConent.kt b/app/src/main/java/com/tangem/tap/features/saveWallet/ui/components/EnrollBiometricsDialogConent.kt index 0e7b6f987c..c401e1e40b 100644 --- a/app/src/main/java/com/tangem/tap/features/saveWallet/ui/components/EnrollBiometricsDialogConent.kt +++ b/app/src/main/java/com/tangem/tap/features/saveWallet/ui/components/EnrollBiometricsDialogConent.kt @@ -1,66 +1,31 @@ package com.tangem.tap.features.saveWallet.ui.components import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.window.Dialog import com.tangem.core.ui.R -import com.tangem.core.ui.components.SpacerH16 -import com.tangem.core.ui.components.SpacerH24 -import com.tangem.core.ui.components.SpacerW8 -import com.tangem.core.ui.components.TextButton +import com.tangem.core.ui.components.BasicDialog +import com.tangem.core.ui.components.DialogButton import com.tangem.core.ui.res.TangemTheme import com.tangem.tap.features.saveWallet.ui.models.EnrollBiometricsDialog @Composable fun EnrollBiometricsDialogContent(dialog: EnrollBiometricsDialog) { - Dialog(onDismissRequest = dialog.onCancel) { - Column( - modifier = Modifier - .background( - shape = TangemTheme.shapes.roundedCornersLarge, - color = TangemTheme.colors.background.plain, - ) - .padding(all = TangemTheme.dimens.spacing24), - ) { - Text( - modifier = Modifier.fillMaxWidth(), - text = stringResource(R.string.save_user_wallet_agreement_enroll_biometrics_title), - style = TangemTheme.typography.h3, - color = TangemTheme.colors.text.primary1, - ) - SpacerH16() - Text( - modifier = Modifier.fillMaxWidth(), - text = stringResource(R.string.save_user_wallet_agreement_enroll_biometrics_description), - style = TangemTheme.typography.body2, - color = TangemTheme.colors.text.primary1, - ) - SpacerH24() - Row( - modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.End, - ) { - TextButton( - text = stringResource(R.string.common_cancel), - onClick = dialog.onCancel, - ) - SpacerW8() - TextButton( - text = stringResource(R.string.common_enable), - onClick = dialog.onEnroll, - ) - } - } - } + BasicDialog( + title = stringResource(R.string.save_user_wallet_agreement_enroll_biometrics_title), + message = stringResource(R.string.save_user_wallet_agreement_enroll_biometrics_description), + confirmButton = DialogButton( + title = stringResource(R.string.common_enable), + onClick = dialog.onEnroll, + ), + dismissButton = DialogButton( + onClick = dialog.onCancel, + ), + onDismissDialog = dialog.onCancel, + ) } // region Preview diff --git a/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorBottomSheetFragment.kt b/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorBottomSheetFragment.kt index 4e0edeb703..30eb4cb1fb 100644 --- a/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorBottomSheetFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorBottomSheetFragment.kt @@ -25,9 +25,10 @@ import com.tangem.core.ui.fragments.ComposeBottomSheetFragment import com.tangem.core.ui.res.TangemTheme import com.tangem.tap.common.analytics.events.MyWallets import com.tangem.tap.features.details.ui.cardsettings.resolveReference +import com.tangem.tap.features.walletSelector.ui.components.RemoveWalletDialogContent import com.tangem.tap.features.walletSelector.ui.components.RenameWalletDialogContent import com.tangem.tap.features.walletSelector.ui.components.WalletSelectorScreenContent -import com.tangem.tap.features.walletSelector.ui.model.RenameWalletDialog +import com.tangem.tap.features.walletSelector.ui.model.DialogModel internal class WalletSelectorBottomSheetFragment : ComposeBottomSheetFragment() { private val viewModel by viewModels() @@ -48,7 +49,7 @@ internal class WalletSelectorBottomSheetFragment : ComposeBottomSheetFragment RemoveWalletDialogContent(dialog) + is DialogModel.RenameWalletDialog -> RenameWalletDialogContent(dialog) + } } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorScreenState.kt b/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorScreenState.kt index 1831d16240..b2da2e5b5f 100644 --- a/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorScreenState.kt +++ b/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorScreenState.kt @@ -3,8 +3,8 @@ package com.tangem.tap.features.walletSelector.ui import androidx.compose.runtime.Immutable import com.tangem.domain.common.util.UserWalletId import com.tangem.tap.features.details.ui.cardsettings.TextReference +import com.tangem.tap.features.walletSelector.ui.model.DialogModel import com.tangem.tap.features.walletSelector.ui.model.MultiCurrencyUserWalletItem -import com.tangem.tap.features.walletSelector.ui.model.RenameWalletDialog import com.tangem.tap.features.walletSelector.ui.model.SingleCurrencyUserWalletItem @Immutable @@ -14,7 +14,7 @@ internal data class WalletSelectorScreenState( val selectedUserWalletId: UserWalletId? = null, val isLocked: Boolean = false, val editingUserWalletsIds: List = listOf(), - val renameWalletDialog: RenameWalletDialog? = null, + val dialog: DialogModel? = null, val showAddCardProgress: Boolean = false, val showUnlockProgress: Boolean = false, val error: TextReference? = null, diff --git a/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorViewModel.kt b/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorViewModel.kt index edb923f5ba..21313550f3 100644 --- a/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorViewModel.kt @@ -8,7 +8,7 @@ import com.tangem.tap.common.analytics.events.MyWallets import com.tangem.tap.common.extensions.dispatchOnMain import com.tangem.tap.features.walletSelector.redux.WalletSelectorAction import com.tangem.tap.features.walletSelector.redux.WalletSelectorState -import com.tangem.tap.features.walletSelector.ui.model.RenameWalletDialog +import com.tangem.tap.features.walletSelector.ui.model.DialogModel import com.tangem.tap.store import com.tangem.tap.userWalletsListManager import com.tangem.tap.walletStoresManager @@ -67,28 +67,28 @@ internal class WalletSelectorViewModel : ViewModel(), StoreSubscriber + onConfirm = { newName -> store.dispatch(WalletSelectorAction.RenameWallet(editedUserWalletId, newName)) stateInternal.update { prevState -> prevState.copy( - renameWalletDialog = null, + dialog = null, editingUserWalletsIds = emptyList(), ) } }, - onCancel = { + onDismiss = { stateInternal.update { prevState -> prevState.copy( - renameWalletDialog = null, + dialog = null, ) } }, @@ -96,7 +96,7 @@ internal class WalletSelectorViewModel : ViewModel(), StoreSubscriber prevState.copy( - renameWalletDialog = dialog, + dialog = dialog, ) } } @@ -105,7 +105,30 @@ internal class WalletSelectorViewModel : ViewModel(), StoreSubscriber + prevState.copy( + dialog = null, + editingUserWalletsIds = emptyList(), + ) + } + }, + onDismiss = { + stateInternal.update { prevState -> + prevState.copy( + dialog = null, + ) + } + }, + ) + + stateInternal.update { prevState -> + prevState.copy( + dialog = dialog, + ) + } } } diff --git a/app/src/main/java/com/tangem/tap/features/walletSelector/ui/components/RemoveWalletDialogContent.kt b/app/src/main/java/com/tangem/tap/features/walletSelector/ui/components/RemoveWalletDialogContent.kt new file mode 100644 index 0000000000..cedbb48278 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/walletSelector/ui/components/RemoveWalletDialogContent.kt @@ -0,0 +1,24 @@ +package com.tangem.tap.features.walletSelector.ui.components + +import androidx.compose.runtime.Composable +import androidx.compose.ui.res.stringResource +import com.tangem.core.ui.components.BasicDialog +import com.tangem.core.ui.components.DialogButton +import com.tangem.tap.features.walletSelector.ui.model.DialogModel +import com.tangem.wallet.R + +@Composable +internal fun RemoveWalletDialogContent(dialog: DialogModel.RemoveWalletDialog) { + BasicDialog( + message = stringResource(id = R.string.user_wallet_list_delete_prompt), + confirmButton = DialogButton( + title = stringResource(id = R.string.common_delete), + warning = true, + onClick = dialog.onConfirm, + ), + dismissButton = DialogButton( + onClick = dialog.onDismiss, + ), + onDismissDialog = dialog.onDismiss, + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/walletSelector/ui/components/RenameWalletDialogContent.kt b/app/src/main/java/com/tangem/tap/features/walletSelector/ui/components/RenameWalletDialogContent.kt index 7822c91288..97d465df54 100644 --- a/app/src/main/java/com/tangem/tap/features/walletSelector/ui/components/RenameWalletDialogContent.kt +++ b/app/src/main/java/com/tangem/tap/features/walletSelector/ui/components/RenameWalletDialogContent.kt @@ -1,12 +1,6 @@ package com.tangem.tap.features.walletSelector.ui.components -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -16,65 +10,39 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.window.Dialog -import com.tangem.core.ui.components.OutlineTextField -import com.tangem.core.ui.components.SpacerH16 -import com.tangem.core.ui.components.SpacerH24 -import com.tangem.core.ui.components.SpacerW8 -import com.tangem.core.ui.components.TextButton +import com.tangem.core.ui.components.AdditionalTextInputDialogParams +import com.tangem.core.ui.components.DialogButton +import com.tangem.core.ui.components.TextInputDialog import com.tangem.core.ui.res.TangemTheme -import com.tangem.tap.features.walletSelector.ui.model.RenameWalletDialog +import com.tangem.tap.features.walletSelector.ui.model.DialogModel import com.tangem.wallet.R @Composable -internal fun RenameWalletDialogContent(dialog: RenameWalletDialog) { - Dialog(onDismissRequest = dialog.onCancel) { - Column( - modifier = Modifier - .background( - shape = TangemTheme.shapes.roundedCornersLarge, - color = TangemTheme.colors.background.plain, - ) - .padding(all = TangemTheme.dimens.spacing24), - ) { - var value by remember { - mutableStateOf(TextFieldValue(text = dialog.currentName)) - } - - Text( - modifier = Modifier.fillMaxWidth(), - text = stringResource(R.string.user_wallet_list_rename_popup_title), - style = TangemTheme.typography.h3, - color = TangemTheme.colors.text.primary1, - ) - SpacerH16() - OutlineTextField( - value = value, - label = stringResource(R.string.user_wallet_list_rename_popup_placeholder), - onValueChange = { newValue -> - value = newValue - }, - ) - SpacerH24() - Row( - modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.End, - ) { - TextButton( - text = stringResource(id = R.string.common_cancel), - onClick = dialog.onCancel, - ) - SpacerW8() - TextButton( - text = stringResource(id = R.string.common_save), - enabled = value.text.isNotEmpty() && value.text != dialog.currentName, - onClick = { - dialog.onApply(value.text) - }, - ) - } - } +internal fun RenameWalletDialogContent(dialog: DialogModel.RenameWalletDialog) { + var value by remember { + mutableStateOf(TextFieldValue(text = dialog.currentName)) } + + TextInputDialog( + fieldValue = value, + confirmButton = DialogButton( + title = stringResource(id = R.string.common_save), + enabled = value.text.isNotEmpty() && value.text != dialog.currentName, + onClick = { dialog.onConfirm(value.text) }, + ), + onDismissDialog = dialog.onDismiss, + onValueChange = { newValue -> + value = newValue + }, + title = stringResource(R.string.user_wallet_list_rename_popup_title), + dismissButton = DialogButton( + title = stringResource(id = R.string.common_cancel), + onClick = dialog.onDismiss, + ), + textFieldParams = AdditionalTextInputDialogParams( + label = stringResource(R.string.user_wallet_list_rename_popup_placeholder), + ), + ) } // region Preview @@ -83,10 +51,9 @@ private fun RenameWalletDialogContentSample( modifier: Modifier = Modifier, ) { Column( - modifier = modifier - .background(TangemTheme.colors.background.primary), + modifier = modifier, ) { - RenameWalletDialogContent(dialog = RenameWalletDialog("", {}, {})) + RenameWalletDialogContent(dialog = DialogModel.RenameWalletDialog("", {}, {})) } } diff --git a/app/src/main/java/com/tangem/tap/features/walletSelector/ui/model/DialogModel.kt b/app/src/main/java/com/tangem/tap/features/walletSelector/ui/model/DialogModel.kt new file mode 100644 index 0000000000..1dcfb1a2a5 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/walletSelector/ui/model/DialogModel.kt @@ -0,0 +1,14 @@ +package com.tangem.tap.features.walletSelector.ui.model + +internal sealed interface DialogModel { + data class RenameWalletDialog( + val currentName: String, + val onConfirm: (newName: String) -> Unit, + val onDismiss: () -> Unit, + ) : DialogModel + + data class RemoveWalletDialog( + val onConfirm: () -> Unit, + val onDismiss: () -> Unit, + ) : DialogModel +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/walletSelector/ui/model/RenameWalletDialog.kt b/app/src/main/java/com/tangem/tap/features/walletSelector/ui/model/RenameWalletDialog.kt deleted file mode 100644 index e3969634ce..0000000000 --- a/app/src/main/java/com/tangem/tap/features/walletSelector/ui/model/RenameWalletDialog.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.tangem.tap.features.walletSelector.ui.model - -import androidx.compose.runtime.Immutable - -@Immutable -internal data class RenameWalletDialog( - val currentName: String, - val onApply: (newName: String) -> Unit, - val onCancel: () -> Unit, -) \ No newline at end of file diff --git a/core/res/src/main/res/values-de/strings.xml b/core/res/src/main/res/values-de/strings.xml index d2c19be882..2949fd6eec 100644 --- a/core/res/src/main/res/values-de/strings.xml +++ b/core/res/src/main/res/values-de/strings.xml @@ -371,6 +371,7 @@ Tangem Twin This action is irreversible. You will not have access to the old wallet. Add new wallet + Are you sure you want to delete this wallet? %d selected This wallet has already been saved, you can add another one Multi-currency diff --git a/core/res/src/main/res/values-fr/strings.xml b/core/res/src/main/res/values-fr/strings.xml index 179d53accf..927fa8f9b9 100644 --- a/core/res/src/main/res/values-fr/strings.xml +++ b/core/res/src/main/res/values-fr/strings.xml @@ -371,6 +371,7 @@ Tangem Twin This action is irreversible. You will not have access to the old wallet. Add new wallet + Are you sure you want to delete this wallet? %d selected This wallet has already been saved, you can add another one Multi-currency diff --git a/core/res/src/main/res/values-it/strings.xml b/core/res/src/main/res/values-it/strings.xml index 13d8eec203..44aa7b8d83 100644 --- a/core/res/src/main/res/values-it/strings.xml +++ b/core/res/src/main/res/values-it/strings.xml @@ -371,6 +371,7 @@ Tangem Twin This action is irreversible. You will not have access to the old wallet. Add new wallet + Are you sure you want to delete this wallet? %d selected This wallet has already been saved, you can add another one Multi-currency diff --git a/core/res/src/main/res/values-ru/strings.xml b/core/res/src/main/res/values-ru/strings.xml index 72e70b3ce4..ffc2e011c1 100644 --- a/core/res/src/main/res/values-ru/strings.xml +++ b/core/res/src/main/res/values-ru/strings.xml @@ -371,6 +371,7 @@ Tangem Twin Это действие необратимо. У вас не будет доступа к старому кошельку. Добавить новый кошелек + Вы уверены, что хотите удалить этот кошелек? %d выбрано Этот кошелек уже был сохранен, вы можете добавить другой Мультивалютные diff --git a/core/res/src/main/res/values/strings.xml b/core/res/src/main/res/values/strings.xml index 884c983651..b410d6bc44 100644 --- a/core/res/src/main/res/values/strings.xml +++ b/core/res/src/main/res/values/strings.xml @@ -371,6 +371,7 @@ Tangem Twin This action is irreversible. You will not have access to the old wallet. Add new wallet + Are you sure you want to delete this wallet? %d selected This wallet has already been saved, you can add another one Multi-currency diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/Dialogs.kt b/core/ui/src/main/java/com/tangem/core/ui/components/Dialogs.kt index aa01105bc9..993ae27a45 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/Dialogs.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/Dialogs.kt @@ -1,15 +1,49 @@ package com.tangem.core.ui.components +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding -import androidx.compose.material.AlertDialog import androidx.compose.material.Text import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.window.Dialog import com.tangem.core.ui.R import com.tangem.core.ui.res.TangemTheme +/** + * Dialog button params + * + * @param title Button text. If not provided default values will be used + * @param warning If true then button text will be in theme warning color + * @param enabled If false button will be disabled + * @param onClick Button click callback + */ +data class DialogButton( + val title: String? = null, + val warning: Boolean = false, + val enabled: Boolean = true, + val onClick: () -> Unit, +) + +/** + * Additional params for dialog text field + */ +data class AdditionalTextInputDialogParams( + val label: String? = null, + val placeholder: String? = null, + val caption: String? = null, + val enabled: Boolean = true, + val isError: Boolean = false, +) + /** * Simple alert dialog with a message and 'OK' button * @@ -30,63 +64,204 @@ fun BasicDialog( title: String? = null, dismissButton: DialogButton? = null, ) { - AlertDialog( - text = { - Text( - text = message, - style = TangemTheme.typography.body2, - color = TangemTheme.colors.text.secondary, - ) - }, - title = if (title != null) { - { - Text( - text = title, - style = TangemTheme.typography.h2, - color = TangemTheme.colors.text.primary1, - ) - } - } else { - null - }, - onDismissRequest = onDismissDialog, - confirmButton = { - TextButton( - modifier = Modifier.padding(bottom = TangemTheme.dimens.spacing12), - text = confirmButton.title ?: stringResource(id = R.string.common_ok), - onClick = confirmButton.onClick, - ) - }, - dismissButton = { - if (dismissButton != null) { - TextButton( - modifier = Modifier.padding(bottom = TangemTheme.dimens.spacing12), - text = dismissButton.title ?: stringResource(id = R.string.common_cancel), - onClick = dismissButton.onClick, - ) - } - }, - shape = TangemTheme.shapes.roundedCornersLarge, - modifier = Modifier.padding(TangemTheme.dimens.spacing24), + TangemDialog( + type = DialogType.Message(message), + confirmButton = confirmButton, + onDismissDialog = onDismissDialog, + title = title, + dismissButton = dismissButton, ) } -data class DialogButton( - val title: String? = null, - val onClick: () -> Unit, -) - @Composable fun SimpleOkDialog(message: String, onDismissDialog: () -> Unit) { - BasicDialog( - message = message, + TangemDialog( + type = DialogType.Message(message), confirmButton = DialogButton(onClick = onDismissDialog), onDismissDialog = onDismissDialog, + title = null, + dismissButton = null, ) } -// region Preview +/** + * Dialog with text field + * + * @param fieldValue Text field value + * @param onValueChange Text field value callback + * @param title title to show (no title if null) + * @param confirmButton title and action for confirm button + * @param dismissButton title and action for dismiss button (no dismiss button if null) + * @param onDismissDialog action to perform when dialog is closed + * @param textFieldParams Additional params for dialog text field + * + * @see Figma component + */ +@Composable +fun TextInputDialog( + fieldValue: TextFieldValue, + confirmButton: DialogButton, + onDismissDialog: () -> Unit, + onValueChange: (TextFieldValue) -> Unit, + title: String? = null, + dismissButton: DialogButton? = null, + textFieldParams: AdditionalTextInputDialogParams, +) { + TangemDialog( + type = DialogType.TextInput( + value = fieldValue, + onValueChange = onValueChange, + params = textFieldParams, + ), + confirmButton = confirmButton, + onDismissDialog = onDismissDialog, + title = title, + dismissButton = dismissButton, + ) +} +// region Defaults +@Composable +private fun TangemDialog( + type: DialogType, + confirmButton: DialogButton, + onDismissDialog: () -> Unit, + title: String? = null, + dismissButton: DialogButton? = null, +) { + Dialog(onDismissRequest = onDismissDialog) { + Column( + modifier = Modifier + .background( + shape = TangemTheme.shapes.roundedCornersLarge, + color = TangemTheme.colors.background.plain, + ) + .padding(all = TangemTheme.dimens.spacing24), + ) { + if (title != null) { + Text( + modifier = Modifier.fillMaxWidth(), + text = title, + style = when (type) { + is DialogType.Message -> TangemTheme.typography.h2 + is DialogType.TextInput -> TangemTheme.typography.h3 + }, + color = TangemTheme.colors.text.primary1, + ) + SpacerH16() + } + DialogContent(type = type) + SpacerH24() + DialogButtons(confirmButton = confirmButton, dismissButton = dismissButton) + } + } +} + +@Composable +private fun DialogContent( + modifier: Modifier = Modifier, + type: DialogType, +) { + Column( + modifier = modifier, + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally, + ) { + when (type) { + is DialogType.Message -> { + Text( + modifier = Modifier.fillMaxWidth(), + text = type.message, + style = TangemTheme.typography.body2, + color = TangemTheme.colors.text.secondary, + ) + } + is DialogType.TextInput -> { + OutlineTextField( + modifier = Modifier.fillMaxWidth(), + value = type.value, + label = type.params.label, + placeholder = type.params.placeholder, + caption = type.params.caption, + enabled = type.params.enabled, + isError = type.params.isError, + onValueChange = { newValue -> + type.onValueChange(newValue) + }, + ) + } + } + } +} + +@Composable +private fun DialogButtons( + modifier: Modifier = Modifier, + confirmButton: DialogButton, + dismissButton: DialogButton?, +) { + Row( + modifier = modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.spacedBy( + space = TangemTheme.dimens.spacing4, + alignment = Alignment.End, + ), + ) { + if (dismissButton != null) { + DialogButton( + text = dismissButton.title ?: stringResource(id = R.string.common_cancel), + warning = dismissButton.warning, + enabled = dismissButton.enabled, + onClick = dismissButton.onClick, + ) + } + DialogButton( + text = confirmButton.title ?: stringResource(id = R.string.common_ok), + warning = confirmButton.warning, + enabled = confirmButton.enabled, + onClick = confirmButton.onClick, + ) + } +} + +@Composable +private fun DialogButton( + modifier: Modifier = Modifier, + text: String, + warning: Boolean, + enabled: Boolean, + onClick: () -> Unit, +) { + Box(modifier = modifier) { + if (warning) { + WarningTextButton( + text = text, + enabled = enabled, + onClick = onClick, + ) + } else { + TextButton( + text = text, + enabled = enabled, + onClick = onClick, + ) + } + } +} + +private sealed interface DialogType { + data class Message(val message: String) : DialogType + + data class TextInput( + val value: TextFieldValue, + val onValueChange: (TextFieldValue) -> Unit, + val params: AdditionalTextInputDialogParams = AdditionalTextInputDialogParams(), + ) : DialogType +} +// endregion Defaults + +// region Preview @Composable private fun SimpleOkDialogPreview() { SimpleOkDialog( @@ -139,4 +314,73 @@ private fun Preview_BasicDialog_InDarkTheme() { } } +@Composable +private fun WarningBasicDialogSample( + modifier: Modifier = Modifier, +) { + Column( + modifier = modifier, + ) { + BasicDialog( + message = "All protected passwords will be deleted from the secure storage, you must enter the wallet " + + "password to work with the app", + title = "Attention", + confirmButton = DialogButton(warning = true) {}, + dismissButton = DialogButton {}, + onDismissDialog = {}, + ) + } +} + +@Preview(showBackground = true, widthDp = 360) +@Composable +private fun WarningBasicDialogPreview_Light() { + TangemTheme { + WarningBasicDialogSample() + } +} + +@Preview(showBackground = true, widthDp = 360) +@Composable +private fun WarningBasicDialogPreview_Dark() { + TangemTheme(isDark = true) { + WarningBasicDialogSample() + } +} + +@Composable +private fun TextInputDialogSample( + modifier: Modifier = Modifier, +) { + Column( + modifier = modifier, + ) { + TextInputDialog( + fieldValue = TextFieldValue(text = ""), + title = "Rename Wallet", + confirmButton = DialogButton {}, + onDismissDialog = {}, + onValueChange = {}, + textFieldParams = AdditionalTextInputDialogParams( + label = "Wallet name", + ), + ) + } +} + +@Preview(showBackground = true, widthDp = 360) +@Composable +private fun TextInputDialogPreview_Light() { + TangemTheme { + TextInputDialogSample() + } +} + +@Preview(showBackground = true, widthDp = 360) +@Composable +private fun TextInputDialogPreview_Dark() { + TangemTheme(isDark = true) { + TextInputDialogSample() + } +} // endregion Preview \ No newline at end of file