Skip to content

Commit

Permalink
Add redirection callback to voucher dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
sabercodic committed Oct 17, 2023
1 parent 391268b commit bc46977
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 @@ -100,7 +100,7 @@ fun RedeemVoucherDialog(
uiState: VoucherDialogUiState,
onVoucherInputChange: (String) -> Unit = {},
onRedeem: (voucherCode: String) -> Unit,
onDismiss: () -> Unit
onDismiss: (isTimeAdded: Boolean) -> Unit
) {
AlertDialog(
title = {
Expand Down Expand Up @@ -146,7 +146,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 @@ -192,7 +194,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 bc46977

Please sign in to comment.