From e5f86d1252c8259fc6586e07c5fa37baf20309c0 Mon Sep 17 00:00:00 2001 From: saber safavi Date: Thu, 12 Oct 2023 14:41:03 +0200 Subject: [PATCH] Add redirection callback to voucher dialog --- .../mullvadvpn/compose/dialog/RedeemVoucherDialog.kt | 10 +++++++--- .../compose/screen/RedeemVoucherDialogScreen.kt | 2 +- .../mullvadvpn/ui/fragment/OutOfTimeFragment.kt | 3 ++- .../ui/fragment/RedeemVoucherDialogFragment.kt | 7 +++++-- .../mullvad/mullvadvpn/ui/fragment/WelcomeFragment.kt | 3 ++- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/RedeemVoucherDialog.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/RedeemVoucherDialog.kt index 0848b895945d..a7a7273555d9 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/RedeemVoucherDialog.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/RedeemVoucherDialog.kt @@ -99,7 +99,7 @@ fun RedeemVoucherDialog( uiState: VoucherDialogUiState, onVoucherInputChange: (String) -> Unit = {}, onRedeem: (voucherCode: String) -> Unit, - onDismiss: () -> Unit + onDismiss: (isTimeAdded: Boolean) -> Unit ) { AlertDialog( title = { @@ -127,7 +127,9 @@ fun RedeemVoucherDialog( R.string.changes_dialog_dismiss_button else R.string.cancel ), - onClick = onDismiss + onClick = { + onDismiss(uiState.voucherViewModelState is VoucherDialogState.Success) + } ) } }, @@ -173,7 +175,9 @@ fun RedeemVoucherDialog( }, containerColor = MaterialTheme.colorScheme.background, titleContentColor = MaterialTheme.colorScheme.onBackground, - onDismissRequest = onDismiss + onDismissRequest = { + onDismiss(uiState.voucherViewModelState is VoucherDialogState.Success) + } ) } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/RedeemVoucherDialogScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/RedeemVoucherDialogScreen.kt index 1344db5b2091..1db18b01a31b 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/RedeemVoucherDialogScreen.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/RedeemVoucherDialogScreen.kt @@ -26,7 +26,7 @@ internal fun RedeemVoucherDialogScreen( uiState: VoucherDialogUiState, onVoucherInputChange: (String) -> Unit = {}, onRedeem: (voucherCode: String) -> Unit, - onDismiss: () -> Unit + onDismiss: (isTimeAdded: Boolean) -> Unit ) { RedeemVoucherDialog(uiState, onVoucherInputChange, onRedeem, onDismiss) } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/OutOfTimeFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/OutOfTimeFragment.kt index 700ffba14576..53df05c5f3fe 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/OutOfTimeFragment.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/OutOfTimeFragment.kt @@ -46,7 +46,8 @@ class OutOfTimeFragment : BaseFragment() { private fun openRedeemVoucherFragment() { val transaction = parentFragmentManager.beginTransaction() transaction.addToBackStack(null) - RedeemVoucherDialogFragment().show(transaction, null) + RedeemVoucherDialogFragment { wasSuccessful -> if (wasSuccessful) advanceToConnectScreen() } + .show(transaction, null) } private fun advanceToConnectScreen() { diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/RedeemVoucherDialogFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/RedeemVoucherDialogFragment.kt index 61f24e45fcf3..2730fde5479d 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/RedeemVoucherDialogFragment.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/RedeemVoucherDialogFragment.kt @@ -14,7 +14,7 @@ import net.mullvad.mullvadvpn.lib.theme.AppTheme import net.mullvad.mullvadvpn.viewmodel.VoucherDialogViewModel import org.koin.androidx.viewmodel.ext.android.viewModel -class RedeemVoucherDialogFragment : DialogFragment() { +class RedeemVoucherDialogFragment(val onDialogDismiss: (Boolean) -> Unit = {}) : DialogFragment() { private val vm by viewModel() private lateinit var voucherDialog: Dialog @@ -31,7 +31,10 @@ class RedeemVoucherDialogFragment : DialogFragment() { uiState = vm.uiState.collectAsState().value, onVoucherInputChange = { vm.onVoucherInputChange(it) }, onRedeem = { vm.onRedeem(it) }, - onDismiss = { onDismiss(voucherDialog) } + onDismiss = { + onDismiss(voucherDialog) + onDialogDismiss(it) + } ) } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/WelcomeFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/WelcomeFragment.kt index 403c50ccec12..d04c5de53afd 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/WelcomeFragment.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/fragment/WelcomeFragment.kt @@ -45,7 +45,8 @@ class WelcomeFragment : BaseFragment() { private fun openRedeemVoucherFragment() { val transaction = parentFragmentManager.beginTransaction() transaction.addToBackStack(null) - RedeemVoucherDialogFragment().show(transaction, null) + RedeemVoucherDialogFragment { wasSuccessful -> if (wasSuccessful) advanceToConnectScreen() } + .show(transaction, null) } private fun advanceToConnectScreen() {