Skip to content

Commit

Permalink
Merge branch 'redirect-to-connect-screen-on-redeem-voucher-success-dr…
Browse files Browse the repository at this point in the history
…oid-342'
  • Loading branch information
Pururun committed Oct 19, 2023
2 parents ed5722d + e5f86d1 commit 58b09e8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fun RedeemVoucherDialog(
uiState: VoucherDialogUiState,
onVoucherInputChange: (String) -> Unit = {},
onRedeem: (voucherCode: String) -> Unit,
onDismiss: () -> Unit
onDismiss: (isTimeAdded: Boolean) -> Unit
) {
AlertDialog(
title = {
Expand Down Expand Up @@ -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)
}
)
}
},
Expand Down Expand Up @@ -173,7 +175,9 @@ fun RedeemVoucherDialog(
},
containerColor = MaterialTheme.colorScheme.background,
titleContentColor = MaterialTheme.colorScheme.onBackground,
onDismissRequest = onDismiss
onDismissRequest = {
onDismiss(uiState.voucherViewModelState is VoucherDialogState.Success)
}
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<VoucherDialogViewModel>()
private lateinit var voucherDialog: Dialog
Expand All @@ -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)
}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 58b09e8

Please sign in to comment.