Skip to content

Commit

Permalink
Do not show a toast after dismissing the dns dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Mar 22, 2024
1 parent 7163899 commit 6d10536
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fun DnsDialog(
viewModel::onDnsInputChange,
onSaveDnsClick = viewModel::onSaveDnsClick,
onRemoveDnsClick = viewModel::onRemoveDnsClick,
onDismiss = { resultNavigator.navigateBack(false) }
onDismiss = { resultNavigator.navigateBack(result = false) }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_WIREGUARD_CUSTOM_PORT_TEXT_
import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_WIREGUARD_PORT_ITEM_X_TEST_TAG
import net.mullvad.mullvadvpn.compose.transitions.SlideInFromRightTransition
import net.mullvad.mullvadvpn.compose.util.LaunchedEffectCollect
import net.mullvad.mullvadvpn.compose.util.OnNavResultValue
import net.mullvad.mullvadvpn.constant.WIREGUARD_PRESET_PORTS
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.lib.theme.Dimens
Expand Down Expand Up @@ -138,12 +139,11 @@ fun VpnSettings(
val vm = koinViewModel<VpnSettingsViewModel>()
val state by vm.uiState.collectAsStateWithLifecycle()

dnsDialogResult.onNavResult {
when (it) {
NavResult.Canceled -> {
vm.onDnsDialogDismissed()
}
is NavResult.Value -> {}
dnsDialogResult.OnNavResultValue { result ->
if (result) {
vm.showApplySettingChangesWarningToast()
} else {
vm.onDnsDialogDismissed()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisallowComposableCalls
import com.ramcosta.composedestinations.result.NavResult
import com.ramcosta.composedestinations.result.ResultRecipient
import net.mullvad.mullvadvpn.compose.destinations.DirectionDestination
import com.ramcosta.composedestinations.spec.DestinationSpec

@Composable
fun <D : DirectionDestination, V> ResultRecipient<D, V>.OnNavResultValue(
fun <D : DestinationSpec<*>, V> ResultRecipient<D, V>.OnNavResultValue(
onValue: @DisallowComposableCalls (value: V) -> Unit
) = onNavResult {
when (it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ class VpnSettingsViewModel(

fun onDnsDialogDismissed() {
if (vmState.value.customDnsList.isEmpty()) {
onToggleCustomDns(false)
onToggleCustomDns(enable = false)
}
}

fun onToggleCustomDns(enable: Boolean) {
repository.setDnsState(if (enable) DnsState.Custom else DnsState.Default)
if (enable && vmState.value.customDnsList.isEmpty()) {
viewModelScope.launch { _uiSideEffect.send(VpnSettingsSideEffect.NavigateToDnsDialog) }
} else {
} else if (vmState.value.customDnsList.isNotEmpty()) {
showApplySettingChangesWarningToast()
}
}
Expand Down Expand Up @@ -262,7 +262,7 @@ class VpnSettingsViewModel(
return isLinkLocalAddress || isSiteLocalAddress
}

private fun showApplySettingChangesWarningToast() {
fun showApplySettingChangesWarningToast() {
viewModelScope.launch {
_uiSideEffect.send(
VpnSettingsSideEffect.ShowToast(
Expand Down

0 comments on commit 6d10536

Please sign in to comment.