From ae9967e2d78d08761269324aeb23d5c7bab98681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20G=C3=B6ransson?= Date: Fri, 20 Oct 2023 11:56:08 +0200 Subject: [PATCH 1/3] Move Content blockers closer to Use custom Dns setting --- .../compose/screen/VpnSettingsScreenTest.kt | 29 +++-- .../compose/screen/VpnSettingsScreen.kt | 112 +++++++++--------- 2 files changed, 72 insertions(+), 69 deletions(-) diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt index 3eee07e2e6c2..167aabd5ec13 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt @@ -55,10 +55,7 @@ class VpnSettingsScreenTest { ) } - composeTestRule.apply { - onNodeWithText("WireGuard MTU").assertExists() - onNodeWithText("Default").assertExists() - } + composeTestRule.apply { onNodeWithText("Auto-connect").assertExists() } composeTestRule .onNodeWithTag(LAZY_LIST_TEST_TAG) @@ -66,8 +63,8 @@ class VpnSettingsScreenTest { // Assert composeTestRule.apply { - onNodeWithText("Use custom DNS server").assertExists() - onNodeWithText("Add a server").assertDoesNotExist() + onNodeWithText("WireGuard MTU").assertExists() + onNodeWithText("Default").assertExists() } } @@ -81,6 +78,10 @@ class VpnSettingsScreenTest { ) } + composeTestRule + .onNodeWithTag(LAZY_LIST_TEST_TAG) + .performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG)) + // Assert composeTestRule.onNodeWithText(VALID_DUMMY_MTU_VALUE).assertExists() } @@ -97,6 +98,10 @@ class VpnSettingsScreenTest { ) } + composeTestRule + .onNodeWithTag(LAZY_LIST_TEST_TAG) + .performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG)) + // Act composeTestRule.onNodeWithText("WireGuard MTU").performClick() @@ -257,9 +262,9 @@ class VpnSettingsScreenTest { toastMessagesSharedFlow = MutableSharedFlow().asSharedFlow() ) } - composeTestRule - .onNodeWithTag(LAZY_LIST_TEST_TAG) - .performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG)) + // composeTestRule + // .onNodeWithTag(LAZY_LIST_TEST_TAG) + // .performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG)) // Assert composeTestRule.apply { onNodeWithText(DUMMY_DNS_ADDRESS).assertExists() @@ -386,9 +391,9 @@ class VpnSettingsScreenTest { toastMessagesSharedFlow = MutableSharedFlow().asSharedFlow() ) } - composeTestRule - .onNodeWithTag(LAZY_LIST_TEST_TAG) - .performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG)) + // composeTestRule + // .onNodeWithTag(LAZY_LIST_TEST_TAG) + // .performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG)) // Act composeTestRule.onNodeWithText("Add a server").performClick() 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 4e08e06a1de2..4178b6632993 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 @@ -293,12 +293,8 @@ fun VpnSettingsScreen( onCellClicked = { newValue -> onToggleLocalNetworkSharing(newValue) }, onInfoClicked = { onLocalNetworkSharingInfoClick() } ) - } - item { Spacer(modifier = Modifier.height(Dimens.cellLabelVerticalPadding)) - MtuComposeCell(mtuValue = uiState.mtu, onEditMtu = { onMtuCellClick() }) } - item { MtuSubtitle() } itemWithDivider { ExpandableComposeCell( @@ -363,7 +359,7 @@ fun VpnSettingsScreen( ) } - itemWithDivider { + item { NormalSwitchComposeCell( title = stringResource(R.string.block_social_media_title), isToggled = uiState.contentBlockersOptions.blockSocialMedia, @@ -389,6 +385,58 @@ fun VpnSettingsScreen( } } + item { + HeaderSwitchComposeCell( + title = stringResource(R.string.enable_custom_dns), + isToggled = uiState.isCustomDnsEnabled, + isEnabled = uiState.contentBlockersOptions.isAnyBlockerEnabled().not(), + onCellClicked = { newValue -> onToggleDnsClick(newValue) }, + onInfoClicked = { onCustomDnsInfoClick() } + ) + } + + if (uiState.isCustomDnsEnabled) { + itemsIndexed(uiState.customDnsItems) { index, item -> + DnsCell( + address = item.address, + isUnreachableLocalDnsWarningVisible = + item.isLocal && uiState.isAllowLanEnabled.not(), + onClick = { onDnsClick(index) }, + modifier = Modifier.animateItemPlacement() + ) + Divider() + } + + itemWithDivider { + BaseCell( + onCellClicked = { onDnsClick(null) }, + title = { + Text( + text = stringResource(id = R.string.add_a_server), + color = Color.White, + ) + }, + bodyView = {}, + background = MaterialTheme.colorScheme.secondaryContainer, + startPadding = biggerPadding, + ) + } + } + + item { + CustomDnsCellSubtitle( + isCellClickable = uiState.contentBlockersOptions.isAnyBlockerEnabled().not(), + modifier = + Modifier.background(MaterialTheme.colorScheme.secondary) + .padding( + start = Dimens.cellStartPadding, + top = topPadding, + end = Dimens.cellEndPadding, + bottom = Dimens.cellLabelVerticalPadding, + ) + ) + } + itemWithDivider { Spacer(modifier = Modifier.height(Dimens.cellLabelVerticalPadding)) InformationComposeCell( @@ -497,61 +545,11 @@ fun VpnSettingsScreen( mainTestTag = LAZY_LIST_WIREGUARD_CUSTOM_PORT_TEXT_TEST_TAG, numberTestTag = LAZY_LIST_WIREGUARD_CUSTOM_PORT_NUMBER_TEST_TAG ) - } - - item { Spacer(modifier = Modifier.height(Dimens.cellLabelVerticalPadding)) - HeaderSwitchComposeCell( - title = stringResource(R.string.enable_custom_dns), - isToggled = uiState.isCustomDnsEnabled, - isEnabled = uiState.contentBlockersOptions.isAnyBlockerEnabled().not(), - onCellClicked = { newValue -> onToggleDnsClick(newValue) }, - onInfoClicked = { onCustomDnsInfoClick() } - ) } - if (uiState.isCustomDnsEnabled) { - itemsIndexed(uiState.customDnsItems) { index, item -> - DnsCell( - address = item.address, - isUnreachableLocalDnsWarningVisible = - item.isLocal && uiState.isAllowLanEnabled.not(), - onClick = { onDnsClick(index) }, - modifier = Modifier.animateItemPlacement() - ) - Divider() - } - - itemWithDivider { - BaseCell( - onCellClicked = { onDnsClick(null) }, - title = { - Text( - text = stringResource(id = R.string.add_a_server), - color = Color.White, - ) - }, - bodyView = {}, - background = MaterialTheme.colorScheme.secondaryContainer, - startPadding = biggerPadding, - ) - } - } - - item { - CustomDnsCellSubtitle( - isCellClickable = uiState.contentBlockersOptions.isAnyBlockerEnabled().not(), - modifier = - Modifier.background(MaterialTheme.colorScheme.secondary) - .testTag(LAZY_LIST_LAST_ITEM_TEST_TAG) - .padding( - start = Dimens.cellStartPadding, - top = topPadding, - end = Dimens.cellEndPadding, - bottom = Dimens.cellLabelVerticalPadding, - ) - ) - } + item { MtuComposeCell(mtuValue = uiState.mtu, onEditMtu = { onMtuCellClick() }) } + item { MtuSubtitle(modifier = Modifier.testTag(LAZY_LIST_LAST_ITEM_TEST_TAG)) } } } } From 231d3869bbaa9fcdb1174141111152711b8618fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20G=C3=B6ransson?= Date: Wed, 25 Oct 2023 15:19:40 +0200 Subject: [PATCH 2/3] Re-order settings to be same as desktop --- .../compose/screen/VpnSettingsScreenTest.kt | 3 - .../compose/screen/VpnSettingsScreen.kt | 105 +++++++++--------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt index 167aabd5ec13..688c3c165b49 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt @@ -370,9 +370,6 @@ class VpnSettingsScreenTest { toastMessagesSharedFlow = MutableSharedFlow().asSharedFlow() ) } - composeTestRule - .onNodeWithTag(LAZY_LIST_TEST_TAG) - .performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG)) // Assert composeTestRule.apply { 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 4178b6632993..7290b9600fd3 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 @@ -437,6 +437,56 @@ fun VpnSettingsScreen( ) } + itemWithDivider { + Spacer(modifier = Modifier.height(Dimens.cellLabelVerticalPadding)) + InformationComposeCell( + title = stringResource(id = R.string.wireguard_port_title), + onInfoClicked = onWireguardPortInfoClicked + ) + } + + itemWithDivider { + SelectableCell( + title = stringResource(id = R.string.automatic), + isSelected = uiState.selectedWireguardPort is Constraint.Any, + onCellClicked = { onWireguardPortSelected(Constraint.Any()) } + ) + } + + WIREGUARD_PRESET_PORTS.forEach { port -> + itemWithDivider { + SelectableCell( + title = port.toString(), + testTag = String.format(LAZY_LIST_WIREGUARD_PORT_ITEM_X_TEST_TAG, port), + isSelected = uiState.selectedWireguardPort.hasValue(port), + onCellClicked = { onWireguardPortSelected(Constraint.Only(Port(port))) } + ) + } + } + + itemWithDivider { + CustomPortCell( + title = stringResource(id = R.string.wireguard_custon_port_title), + isSelected = uiState.selectedWireguardPort.isCustom(), + port = + if (uiState.selectedWireguardPort.isCustom()) { + uiState.selectedWireguardPort.toDisplayCustomPort() + } else { + savedCustomPort.value.toDisplayCustomPort() + }, + onMainCellClicked = { + if (savedCustomPort.value is Constraint.Only) { + onWireguardPortSelected(savedCustomPort.value) + } else { + onShowCustomPortDialog() + } + }, + onPortCellClicked = { onShowCustomPortDialog() }, + mainTestTag = LAZY_LIST_WIREGUARD_CUSTOM_PORT_TEXT_TEST_TAG, + numberTestTag = LAZY_LIST_WIREGUARD_CUSTOM_PORT_NUMBER_TEST_TAG + ) + } + itemWithDivider { Spacer(modifier = Modifier.height(Dimens.cellLabelVerticalPadding)) InformationComposeCell( @@ -488,68 +538,21 @@ fun VpnSettingsScreen( onCellClicked = { onSelectQuantumResistanceSetting(QuantumResistantState.On) } ) } - itemWithDivider { + item { SelectableCell( title = stringResource(id = R.string.off), testTag = LAZY_LIST_QUANTUM_ITEM_OFF_TEST_TAG, isSelected = uiState.quantumResistant == QuantumResistantState.Off, onCellClicked = { onSelectQuantumResistanceSetting(QuantumResistantState.Off) } ) - } - - itemWithDivider { Spacer(modifier = Modifier.height(Dimens.cellLabelVerticalPadding)) - InformationComposeCell( - title = stringResource(id = R.string.wireguard_port_title), - onInfoClicked = onWireguardPortInfoClicked - ) - } - - itemWithDivider { - SelectableCell( - title = stringResource(id = R.string.automatic), - isSelected = uiState.selectedWireguardPort is Constraint.Any, - onCellClicked = { onWireguardPortSelected(Constraint.Any()) } - ) - } - - WIREGUARD_PRESET_PORTS.forEach { port -> - itemWithDivider { - SelectableCell( - title = port.toString(), - testTag = String.format(LAZY_LIST_WIREGUARD_PORT_ITEM_X_TEST_TAG, port), - isSelected = uiState.selectedWireguardPort.hasValue(port), - onCellClicked = { onWireguardPortSelected(Constraint.Only(Port(port))) } - ) - } } - itemWithDivider { - CustomPortCell( - title = stringResource(id = R.string.wireguard_custon_port_title), - isSelected = uiState.selectedWireguardPort.isCustom(), - port = - if (uiState.selectedWireguardPort.isCustom()) { - uiState.selectedWireguardPort.toDisplayCustomPort() - } else { - savedCustomPort.value.toDisplayCustomPort() - }, - onMainCellClicked = { - if (savedCustomPort.value is Constraint.Only) { - onWireguardPortSelected(savedCustomPort.value) - } else { - onShowCustomPortDialog() - } - }, - onPortCellClicked = { onShowCustomPortDialog() }, - mainTestTag = LAZY_LIST_WIREGUARD_CUSTOM_PORT_TEXT_TEST_TAG, - numberTestTag = LAZY_LIST_WIREGUARD_CUSTOM_PORT_NUMBER_TEST_TAG - ) + item { MtuComposeCell(mtuValue = uiState.mtu, onEditMtu = { onMtuCellClick() }) } + item { + MtuSubtitle(modifier = Modifier.testTag(LAZY_LIST_LAST_ITEM_TEST_TAG)) Spacer(modifier = Modifier.height(Dimens.cellLabelVerticalPadding)) } - - item { MtuComposeCell(mtuValue = uiState.mtu, onEditMtu = { onMtuCellClick() }) } - item { MtuSubtitle(modifier = Modifier.testTag(LAZY_LIST_LAST_ITEM_TEST_TAG)) } } } } From 19618dbad68dd86d4c5e033b5c37130dde81510e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20G=C3=B6ransson?= Date: Wed, 25 Oct 2023 15:40:41 +0200 Subject: [PATCH 3/3] Adjust switch color --- .../compose/screen/VpnSettingsScreenTest.kt | 12 +++++------- .../mullvad/mullvadvpn/compose/component/Switch.kt | 9 +++++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt index 688c3c165b49..9b6dd9e492ba 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt @@ -131,7 +131,10 @@ class VpnSettingsScreenTest { // Arrange composeTestRule.setContentWithTheme { VpnSettingsScreen( - uiState = VpnSettingsUiState.createDefault(mtu = VALID_DUMMY_MTU_VALUE), + uiState = + VpnSettingsUiState.createDefault( + dialog = VpnSettingsDialog.Mtu(mtuEditValue = VALID_DUMMY_MTU_VALUE) + ), toastMessagesSharedFlow = MutableSharedFlow().asSharedFlow() ) } @@ -262,9 +265,7 @@ class VpnSettingsScreenTest { toastMessagesSharedFlow = MutableSharedFlow().asSharedFlow() ) } - // composeTestRule - // .onNodeWithTag(LAZY_LIST_TEST_TAG) - // .performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG)) + // Assert composeTestRule.apply { onNodeWithText(DUMMY_DNS_ADDRESS).assertExists() @@ -388,9 +389,6 @@ class VpnSettingsScreenTest { toastMessagesSharedFlow = MutableSharedFlow().asSharedFlow() ) } - // composeTestRule - // .onNodeWithTag(LAZY_LIST_TEST_TAG) - // .performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG)) // Act composeTestRule.onNodeWithText("Add a server").performClick() diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Switch.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Switch.kt index e1ed80db8e66..9ce6a61025b7 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Switch.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Switch.kt @@ -14,6 +14,7 @@ import androidx.compose.material3.SwitchDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.compositeOver import androidx.compose.ui.tooling.preview.Preview import net.mullvad.mullvadvpn.lib.theme.AppTheme @@ -67,18 +68,18 @@ fun MullvadSwitch( fun mullvadSwitchColors(): SwitchColors = SwitchDefaults.colors( checkedThumbColor = MaterialTheme.colorScheme.selected, - checkedTrackColor = MaterialTheme.colorScheme.primary, + checkedTrackColor = Color.Transparent, checkedBorderColor = MaterialTheme.colorScheme.onPrimary, // checkedIconColor= SwitchTokens.SelectedIconColor.toColor(), uncheckedThumbColor = MaterialTheme.colorScheme.error, - uncheckedTrackColor = MaterialTheme.colorScheme.primary, + uncheckedTrackColor = Color.Transparent, uncheckedBorderColor = MaterialTheme.colorScheme.onPrimary, // uncheckedIconColor= SwitchTokens.UnselectedIconColor.toColor(), disabledCheckedThumbColor = MaterialTheme.colorScheme.selected .copy(alpha = AlphaDisabled) .compositeOver(MaterialTheme.colorScheme.primary), - disabledCheckedTrackColor = MaterialTheme.colorScheme.primary, + disabledCheckedTrackColor = Color.Transparent, disabledCheckedBorderColor = MaterialTheme.colorScheme.onPrimary .copy(alpha = AlphaDisabled) @@ -87,7 +88,7 @@ fun mullvadSwitchColors(): SwitchColors = MaterialTheme.colorScheme.error .copy(alpha = AlphaDisabled) .compositeOver(MaterialTheme.colorScheme.primary), - disabledUncheckedTrackColor = MaterialTheme.colorScheme.primary, + disabledUncheckedTrackColor = Color.Transparent, disabledUncheckedBorderColor = MaterialTheme.colorScheme.onPrimary .copy(alpha = AlphaDisabled)