Updated on 2026-08-14
This commit is contained in:
parent
702041224f
commit
c831c3f659
14 changed files with 421 additions and 185 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<WalletSelectorScreenState>() {
|
||||
private val viewModel by viewModels<WalletSelectorViewModel>()
|
||||
|
|
@ -48,7 +49,7 @@ internal class WalletSelectorBottomSheetFragment : ComposeBottomSheetFragment<Wa
|
|||
override fun ScreenContent(state: WalletSelectorScreenState, modifier: Modifier) {
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val errorMessage by rememberUpdatedState(newValue = state.error?.resolveReference())
|
||||
val renameWalletDialog by rememberUpdatedState(newValue = state.renameWalletDialog)
|
||||
val dialog by rememberUpdatedState(newValue = state.dialog)
|
||||
|
||||
Box(modifier = modifier.nestedScroll(rememberNestedScrollInteropConnection())) {
|
||||
WalletSelectorScreenContent(
|
||||
|
|
@ -71,7 +72,7 @@ internal class WalletSelectorBottomSheetFragment : ComposeBottomSheetFragment<Wa
|
|||
)
|
||||
}
|
||||
|
||||
RenameWalletDialog(dialog = renameWalletDialog)
|
||||
Dialog(dialog = dialog)
|
||||
|
||||
LaunchedEffect(key1 = errorMessage) {
|
||||
errorMessage?.let {
|
||||
|
|
@ -83,8 +84,11 @@ internal class WalletSelectorBottomSheetFragment : ComposeBottomSheetFragment<Wa
|
|||
|
||||
@Suppress("TopLevelComposableFunctions")
|
||||
@Composable
|
||||
private fun RenameWalletDialog(dialog: RenameWalletDialog?) {
|
||||
private fun Dialog(dialog: DialogModel?) {
|
||||
if (dialog == null) return
|
||||
RenameWalletDialogContent(dialog)
|
||||
when (dialog) {
|
||||
is DialogModel.RemoveWalletDialog -> RemoveWalletDialogContent(dialog)
|
||||
is DialogModel.RenameWalletDialog -> RenameWalletDialogContent(dialog)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<UserWalletId> = listOf(),
|
||||
val renameWalletDialog: RenameWalletDialog? = null,
|
||||
val dialog: DialogModel? = null,
|
||||
val showAddCardProgress: Boolean = false,
|
||||
val showUnlockProgress: Boolean = false,
|
||||
val error: TextReference? = null,
|
||||
|
|
|
|||
|
|
@ -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<WalletSele
|
|||
}
|
||||
|
||||
fun renameWallet() = with(state.value) {
|
||||
if (editingUserWalletsIds.isNotEmpty() && renameWalletDialog == null) {
|
||||
if (editingUserWalletsIds.isNotEmpty() && dialog == null) {
|
||||
val editedUserWalletId = editingUserWalletsIds.first()
|
||||
val editedUserWallet = (multiCurrencyWallets + singleCurrencyWallets)
|
||||
.find { it.id == editedUserWalletId }
|
||||
|
||||
if (editedUserWallet != null) {
|
||||
Analytics.send(MyWallets.Button.EditWalletTapped())
|
||||
val dialog = RenameWalletDialog(
|
||||
val dialog = DialogModel.RenameWalletDialog(
|
||||
currentName = editedUserWallet.name,
|
||||
onApply = { newName ->
|
||||
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<WalletSele
|
|||
|
||||
stateInternal.update { prevState ->
|
||||
prevState.copy(
|
||||
renameWalletDialog = dialog,
|
||||
dialog = dialog,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -105,7 +105,30 @@ internal class WalletSelectorViewModel : ViewModel(), StoreSubscriber<WalletSele
|
|||
|
||||
fun deleteWallets() = with(state.value) {
|
||||
if (editingUserWalletsIds.isNotEmpty()) {
|
||||
store.dispatch(WalletSelectorAction.RemoveWallets(userWalletsIds = editingUserWalletsIds))
|
||||
val dialog = DialogModel.RemoveWalletDialog(
|
||||
onConfirm = {
|
||||
store.dispatch(WalletSelectorAction.RemoveWallets(editingUserWalletsIds))
|
||||
stateInternal.update { prevState ->
|
||||
prevState.copy(
|
||||
dialog = null,
|
||||
editingUserWalletsIds = emptyList(),
|
||||
)
|
||||
}
|
||||
},
|
||||
onDismiss = {
|
||||
stateInternal.update { prevState ->
|
||||
prevState.copy(
|
||||
dialog = null,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
stateInternal.update { prevState ->
|
||||
prevState.copy(
|
||||
dialog = dialog,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
|
@ -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("", {}, {}))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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,
|
||||
)
|
||||
|
|
@ -371,6 +371,7 @@
|
|||
<string name="twins_recreate_toolbar">Tangem Twin</string>
|
||||
<string name="twins_recreate_warning">This action is irreversible. You will not have access to the old wallet.</string>
|
||||
<string name="user_wallet_list_add_button">Add new wallet</string>
|
||||
<string name="user_wallet_list_delete_prompt">Are you sure you want to delete this wallet?</string>
|
||||
<string name="user_wallet_list_editing_count">%d selected</string>
|
||||
<string name="user_wallet_list_error_wallet_already_saved">This wallet has already been saved, you can add another one</string>
|
||||
<string name="user_wallet_list_multi_header">Multi-currency</string>
|
||||
|
|
|
|||
|
|
@ -371,6 +371,7 @@
|
|||
<string name="twins_recreate_toolbar">Tangem Twin</string>
|
||||
<string name="twins_recreate_warning">This action is irreversible. You will not have access to the old wallet.</string>
|
||||
<string name="user_wallet_list_add_button">Add new wallet</string>
|
||||
<string name="user_wallet_list_delete_prompt">Are you sure you want to delete this wallet?</string>
|
||||
<string name="user_wallet_list_editing_count">%d selected</string>
|
||||
<string name="user_wallet_list_error_wallet_already_saved">This wallet has already been saved, you can add another one</string>
|
||||
<string name="user_wallet_list_multi_header">Multi-currency</string>
|
||||
|
|
|
|||
|
|
@ -371,6 +371,7 @@
|
|||
<string name="twins_recreate_toolbar">Tangem Twin</string>
|
||||
<string name="twins_recreate_warning">This action is irreversible. You will not have access to the old wallet.</string>
|
||||
<string name="user_wallet_list_add_button">Add new wallet</string>
|
||||
<string name="user_wallet_list_delete_prompt">Are you sure you want to delete this wallet?</string>
|
||||
<string name="user_wallet_list_editing_count">%d selected</string>
|
||||
<string name="user_wallet_list_error_wallet_already_saved">This wallet has already been saved, you can add another one</string>
|
||||
<string name="user_wallet_list_multi_header">Multi-currency</string>
|
||||
|
|
|
|||
|
|
@ -371,6 +371,7 @@
|
|||
<string name="twins_recreate_toolbar">Tangem Twin</string>
|
||||
<string name="twins_recreate_warning">Это действие необратимо. У вас не будет доступа к старому кошельку.</string>
|
||||
<string name="user_wallet_list_add_button">Добавить новый кошелек</string>
|
||||
<string name="user_wallet_list_delete_prompt">Вы уверены, что хотите удалить этот кошелек?</string>
|
||||
<string name="user_wallet_list_editing_count">%d выбрано</string>
|
||||
<string name="user_wallet_list_error_wallet_already_saved">Этот кошелек уже был сохранен, вы можете добавить другой</string>
|
||||
<string name="user_wallet_list_multi_header">Мультивалютные</string>
|
||||
|
|
|
|||
|
|
@ -371,6 +371,7 @@
|
|||
<string name="twins_recreate_toolbar">Tangem Twin</string>
|
||||
<string name="twins_recreate_warning">This action is irreversible. You will not have access to the old wallet.</string>
|
||||
<string name="user_wallet_list_add_button">Add new wallet</string>
|
||||
<string name="user_wallet_list_delete_prompt">Are you sure you want to delete this wallet?</string>
|
||||
<string name="user_wallet_list_editing_count">%d selected</string>
|
||||
<string name="user_wallet_list_error_wallet_already_saved">This wallet has already been saved, you can add another one</string>
|
||||
<string name="user_wallet_list_multi_header">Multi-currency</string>
|
||||
|
|
|
|||
|
|
@ -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 <a href = "https://www.figma.com/file/14ISV23YB1yVW1uNVwqrKv/Android?node-id=268%3A273&t=9uHKoudX78ySqium-4"
|
||||
* >Figma component</a>
|
||||
*/
|
||||
@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
|
||||
Loading…
Add table
Add a link
Reference in a new issue