From 6d105363e2f5f1da2326a19e5da89387b5cad996 Mon Sep 17 00:00:00 2001 From: Jonatan Rhodin Date: Wed, 20 Mar 2024 11:07:10 +0100 Subject: [PATCH] Do not show a toast after dismissing the dns dialog --- .../mullvad/mullvadvpn/compose/dialog/DnsDialog.kt | 2 +- .../mullvadvpn/compose/screen/VpnSettingsScreen.kt | 12 ++++++------ .../mullvad/mullvadvpn/compose/util/Navigation.kt | 4 ++-- .../mullvadvpn/viewmodel/VpnSettingsViewModel.kt | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/DnsDialog.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/DnsDialog.kt index 0791f756b374..7ac1469f0943 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/DnsDialog.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/DnsDialog.kt @@ -112,7 +112,7 @@ fun DnsDialog( viewModel::onDnsInputChange, onSaveDnsClick = viewModel::onSaveDnsClick, onRemoveDnsClick = viewModel::onRemoveDnsClick, - onDismiss = { resultNavigator.navigateBack(false) } + onDismiss = { resultNavigator.navigateBack(result = false) } ) } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreen.kt index e926e2e97f35..5b4c9071032f 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreen.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreen.kt @@ -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 @@ -138,12 +139,11 @@ fun VpnSettings( val vm = koinViewModel() 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() } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/Navigation.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/Navigation.kt index 9566bc0da2ed..231c73950041 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/Navigation.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/Navigation.kt @@ -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 ResultRecipient.OnNavResultValue( +fun , V> ResultRecipient.OnNavResultValue( onValue: @DisallowComposableCalls (value: V) -> Unit ) = onNavResult { when (it) { diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt index b954aff5cff5..ba487c5a4057 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt @@ -120,7 +120,7 @@ class VpnSettingsViewModel( fun onDnsDialogDismissed() { if (vmState.value.customDnsList.isEmpty()) { - onToggleCustomDns(false) + onToggleCustomDns(enable = false) } } @@ -128,7 +128,7 @@ class VpnSettingsViewModel( 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() } } @@ -262,7 +262,7 @@ class VpnSettingsViewModel( return isLinkLocalAddress || isSiteLocalAddress } - private fun showApplySettingChangesWarningToast() { + fun showApplySettingChangesWarningToast() { viewModelScope.launch { _uiSideEffect.send( VpnSettingsSideEffect.ShowToast(