@@ -23,6 +23,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
23
23
import androidx.compose.runtime.setValue
24
24
import androidx.compose.ui.Modifier
25
25
import androidx.compose.ui.graphics.Color
26
+ import androidx.compose.ui.platform.LocalContext
26
27
import androidx.compose.ui.platform.LocalLifecycleOwner
27
28
import androidx.compose.ui.platform.testTag
28
29
import androidx.compose.ui.res.stringResource
@@ -75,6 +76,7 @@ import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_WIREGUARD_CUSTOM_PORT_TEXT_
75
76
import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_WIREGUARD_PORT_ITEM_X_TEST_TAG
76
77
import net.mullvad.mullvadvpn.compose.transitions.SlideInFromRightTransition
77
78
import net.mullvad.mullvadvpn.constant.WIREGUARD_PRESET_PORTS
79
+ import net.mullvad.mullvadvpn.lib.common.util.vpnSettingsAvailable
78
80
import net.mullvad.mullvadvpn.lib.theme.AppTheme
79
81
import net.mullvad.mullvadvpn.lib.theme.Dimens
80
82
import net.mullvad.mullvadvpn.model.Constraint
@@ -122,135 +124,13 @@ private fun PreviewVpnSettings() {
122
124
}
123
125
}
124
126
125
- @Destination(style = SlideInFromRightTransition ::class )
126
- @Composable
127
- fun VpnSettings (
128
- navigator : DestinationsNavigator ,
129
- dnsDialogResult : ResultRecipient <DnsDialogDestination , Boolean >,
130
- customWgPortResult : ResultRecipient <WireguardCustomPortDialogDestination , Int ?>
131
- ) {
132
- val vm = koinViewModel<VpnSettingsViewModel >()
133
- val state = vm.uiState.collectAsState().value
134
-
135
- dnsDialogResult.onNavResult {
136
- when (it) {
137
- NavResult .Canceled -> {
138
- vm.onDnsDialogDismissed()
139
- }
140
- is NavResult .Value -> {}
141
- }
142
- }
143
-
144
- customWgPortResult.onNavResult {
145
- when (it) {
146
- NavResult .Canceled -> {}
147
- is NavResult .Value -> {
148
- val port = it.value
149
-
150
- if (port != null ) {
151
- vm.onWireguardPortSelected(Constraint .Only (Port (port)))
152
- } else {
153
- vm.resetCustomPort()
154
- }
155
- }
156
- }
157
- }
158
-
159
- val snackbarHostState = remember { SnackbarHostState () }
160
- LaunchedEffect (Unit ) {
161
- vm.uiSideEffect.collect {
162
- when (it) {
163
- is VpnSettingsSideEffect .ShowToast ->
164
- launch {
165
- snackbarHostState.currentSnackbarData?.dismiss()
166
- snackbarHostState.showSnackbar(message = it.message)
167
- }
168
- VpnSettingsSideEffect .NavigateToDnsDialog ->
169
- navigator.navigate(DnsDialogDestination (null , null )) { launchSingleTop = true }
170
- }
171
- }
172
- }
173
-
174
- val lifecycleOwner = LocalLifecycleOwner .current
175
- DisposableEffect (lifecycleOwner) {
176
- val observer = LifecycleEventObserver { _, event ->
177
- if (event == Lifecycle .Event .ON_STOP ) {
178
- vm.onStopEvent()
179
- }
180
- }
181
- lifecycleOwner.lifecycle.addObserver(observer)
182
- onDispose { lifecycleOwner.lifecycle.removeObserver(observer) }
183
- }
184
-
185
- VpnSettingsScreen (
186
- uiState = state,
187
- snackbarHostState = snackbarHostState,
188
- navigateToContentBlockersInfo = {
189
- navigator.navigate(ContentBlockersInfoDialogDestination ) { launchSingleTop = true }
190
- },
191
- navigateToCustomDnsInfo = {
192
- navigator.navigate(CustomDnsInfoDialogDestination ) { launchSingleTop = true }
193
- },
194
- navigateToMalwareInfo = {
195
- navigator.navigate(MalwareInfoDialogDestination ) { launchSingleTop = true }
196
- },
197
- navigateToObfuscationInfo = {
198
- navigator.navigate(ObfuscationInfoDialogDestination ) { launchSingleTop = true }
199
- },
200
- navigateToQuantumResistanceInfo = {
201
- navigator.navigate(QuantumResistanceInfoDialogDestination ) { launchSingleTop = true }
202
- },
203
- navigateUdp2TcpInfo = {
204
- navigator.navigate(UdpOverTcpPortInfoDialogDestination ) { launchSingleTop = true }
205
- },
206
- navigateToWireguardPortInfo = {
207
- navigator.navigate(
208
- WireguardPortInfoDialogDestination (WireguardPortInfoDialogArgument (it))
209
- ) {
210
- launchSingleTop = true
211
- }
212
- },
213
- navigateToLocalNetworkSharingInfo = {
214
- navigator.navigate(LocalNetworkSharingInfoDialogDestination ) { launchSingleTop = true }
215
- },
216
- onToggleBlockTrackers = vm::onToggleBlockTrackers,
217
- onToggleBlockAds = vm::onToggleBlockAds,
218
- onToggleBlockMalware = vm::onToggleBlockMalware,
219
- onToggleAutoConnect = vm::onToggleAutoConnect,
220
- onToggleLocalNetworkSharing = vm::onToggleLocalNetworkSharing,
221
- onToggleBlockAdultContent = vm::onToggleBlockAdultContent,
222
- onToggleBlockGambling = vm::onToggleBlockGambling,
223
- onToggleBlockSocialMedia = vm::onToggleBlockSocialMedia,
224
- navigateToMtuDialog = {
225
- navigator.navigate(MtuDialogDestination (it)) { launchSingleTop = true }
226
- },
227
- navigateToDns = { index, address ->
228
- navigator.navigate(DnsDialogDestination (index, address)) { launchSingleTop = true }
229
- },
230
- navigateToWireguardPortDialog = {
231
- val args =
232
- WireguardCustomPortNavArgs (
233
- state.customWireguardPort?.toValueOrNull(),
234
- state.availablePortRanges
235
- )
236
- navigator.navigate(WireguardCustomPortDialogDestination (args)) {
237
- launchSingleTop = true
238
- }
239
- },
240
- onToggleDnsClick = vm::onToggleCustomDns,
241
- onBackClick = navigator::navigateUp,
242
- onSelectObfuscationSetting = vm::onSelectObfuscationSetting,
243
- onSelectQuantumResistanceSetting = vm::onSelectQuantumResistanceSetting,
244
- onWireguardPortSelected = vm::onWireguardPortSelected,
245
- )
246
- }
247
-
248
127
@OptIn(ExperimentalFoundationApi ::class )
249
128
@Composable
250
129
fun VpnSettingsScreen (
251
130
uiState : VpnSettingsUiState ,
252
131
snackbarHostState : SnackbarHostState = remember { SnackbarHostState () },
253
132
navigateToContentBlockersInfo : () -> Unit = {},
133
+ onAutoConnectClick : () -> Unit = {},
254
134
navigateToCustomDnsInfo : () -> Unit = {},
255
135
navigateToMalwareInfo : () -> Unit = {},
256
136
navigateToObfuscationInfo : () -> Unit = {},
@@ -284,10 +164,25 @@ fun VpnSettingsScreen(
284
164
navigationIcon = { NavigateBackIconButton (onBackClick) },
285
165
snackbarHostState = snackbarHostState
286
166
) { modifier, lazyListState ->
167
+ val context = LocalContext .current
287
168
LazyColumn (
288
169
modifier = modifier.testTag(LAZY_LIST_TEST_TAG ).animateContentSize(),
289
170
state = lazyListState
290
171
) {
172
+ if (context.vpnSettingsAvailable()) {
173
+ item {
174
+ Spacer (modifier = Modifier .height(Dimens .cellLabelVerticalPadding))
175
+ NavigationComposeCell (
176
+ title = stringResource(id = R .string.auto_connect_and_lockdown_mode),
177
+ onClick = { onAutoConnectClick() },
178
+ )
179
+ }
180
+ item {
181
+ SwitchComposeSubtitleCell (
182
+ text = stringResource(id = R .string.auto_connect_and_lockdown_mode_footer)
183
+ )
184
+ }
185
+ }
291
186
item {
292
187
Spacer (modifier = Modifier .height(Dimens .cellLabelVerticalPadding))
293
188
HeaderSwitchComposeCell (
0 commit comments