Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move "Content blockers" closer to "Custom Dns" setting #5334

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,16 @@ class VpnSettingsScreenTest {
)
}

composeTestRule.apply {
onNodeWithText("WireGuard MTU").assertExists()
onNodeWithText("Default").assertExists()
}
composeTestRule.apply { onNodeWithText("Auto-connect").assertExists() }

composeTestRule
.onNodeWithTag(LAZY_LIST_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG))

// Assert
composeTestRule.apply {
onNodeWithText("Use custom DNS server").assertExists()
onNodeWithText("Add a server").assertDoesNotExist()
onNodeWithText("WireGuard MTU").assertExists()
onNodeWithText("Default").assertExists()
}
}

Expand All @@ -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()
}
Expand All @@ -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()

Expand Down Expand Up @@ -126,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<String>().asSharedFlow()
)
}
Expand Down Expand Up @@ -257,9 +265,7 @@ class VpnSettingsScreenTest {
toastMessagesSharedFlow = MutableSharedFlow<String>().asSharedFlow()
)
}
composeTestRule
.onNodeWithTag(LAZY_LIST_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG))

// Assert
composeTestRule.apply {
onNodeWithText(DUMMY_DNS_ADDRESS).assertExists()
Expand Down Expand Up @@ -365,9 +371,6 @@ class VpnSettingsScreenTest {
toastMessagesSharedFlow = MutableSharedFlow<String>().asSharedFlow()
)
}
composeTestRule
.onNodeWithTag(LAZY_LIST_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG))

// Assert
composeTestRule.apply {
Expand All @@ -386,9 +389,6 @@ class VpnSettingsScreenTest {
toastMessagesSharedFlow = MutableSharedFlow<String>().asSharedFlow()
)
}
composeTestRule
.onNodeWithTag(LAZY_LIST_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG))

// Act
composeTestRule.onNodeWithText("Add a server").performClick()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -363,7 +359,7 @@ fun VpnSettingsScreen(
)
}

itemWithDivider {
item {
NormalSwitchComposeCell(
title = stringResource(R.string.block_social_media_title),
isToggled = uiState.contentBlockersOptions.blockSocialMedia,
Expand All @@ -389,63 +385,55 @@ fun VpnSettingsScreen(
}
}

itemWithDivider {
Spacer(modifier = Modifier.height(Dimens.cellLabelVerticalPadding))
InformationComposeCell(
title = stringResource(R.string.obfuscation_title),
onInfoClicked = { onObfuscationInfoClick() }
)
}
itemWithDivider {
SelectableCell(
title = stringResource(id = R.string.automatic),
isSelected = uiState.selectedObfuscation == SelectedObfuscation.Auto,
onCellClicked = { onSelectObfuscationSetting(SelectedObfuscation.Auto) }
)
}
itemWithDivider {
SelectableCell(
title = stringResource(id = R.string.obfuscation_on_udp_over_tcp),
isSelected = uiState.selectedObfuscation == SelectedObfuscation.Udp2Tcp,
onCellClicked = { onSelectObfuscationSetting(SelectedObfuscation.Udp2Tcp) }
)
}
itemWithDivider {
SelectableCell(
title = stringResource(id = R.string.off),
isSelected = uiState.selectedObfuscation == SelectedObfuscation.Off,
onCellClicked = { onSelectObfuscationSetting(SelectedObfuscation.Off) }
item {
HeaderSwitchComposeCell(
title = stringResource(R.string.enable_custom_dns),
isToggled = uiState.isCustomDnsEnabled,
isEnabled = uiState.contentBlockersOptions.isAnyBlockerEnabled().not(),
onCellClicked = { newValue -> onToggleDnsClick(newValue) },
onInfoClicked = { onCustomDnsInfoClick() }
)
}

itemWithDivider {
Spacer(modifier = Modifier.height(Dimens.cellLabelVerticalPadding))
InformationComposeCell(
title = stringResource(R.string.quantum_resistant_title),
onInfoClicked = { onQuantumResistanceInfoClicked() }
)
}
itemWithDivider {
SelectableCell(
title = stringResource(id = R.string.automatic),
isSelected = uiState.quantumResistant == QuantumResistantState.Auto,
onCellClicked = { onSelectQuantumResistanceSetting(QuantumResistantState.Auto) }
)
}
itemWithDivider {
SelectableCell(
title = stringResource(id = R.string.on),
testTag = LAZY_LIST_QUANTUM_ITEM_ON_TEST_TAG,
isSelected = uiState.quantumResistant == QuantumResistantState.On,
onCellClicked = { onSelectQuantumResistanceSetting(QuantumResistantState.On) }
)
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,
)
}
}
itemWithDivider {
SelectableCell(
title = stringResource(id = R.string.off),
testTag = LAZY_LIST_QUANTUM_ITEM_OFF_TEST_TAG,
isSelected = uiState.quantumResistant == QuantumResistantState.Off,
onCellClicked = { onSelectQuantumResistanceSetting(QuantumResistantState.Off) }

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,
)
)
}

Expand Down Expand Up @@ -499,58 +487,71 @@ fun VpnSettingsScreen(
)
}

item {
itemWithDivider {
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() }
InformationComposeCell(
title = stringResource(R.string.obfuscation_title),
onInfoClicked = { onObfuscationInfoClick() }
)
}

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,
)
}
itemWithDivider {
SelectableCell(
title = stringResource(id = R.string.automatic),
isSelected = uiState.selectedObfuscation == SelectedObfuscation.Auto,
onCellClicked = { onSelectObfuscationSetting(SelectedObfuscation.Auto) }
)
}
itemWithDivider {
SelectableCell(
title = stringResource(id = R.string.obfuscation_on_udp_over_tcp),
isSelected = uiState.selectedObfuscation == SelectedObfuscation.Udp2Tcp,
onCellClicked = { onSelectObfuscationSetting(SelectedObfuscation.Udp2Tcp) }
)
}
itemWithDivider {
SelectableCell(
title = stringResource(id = R.string.off),
isSelected = uiState.selectedObfuscation == SelectedObfuscation.Off,
onCellClicked = { onSelectObfuscationSetting(SelectedObfuscation.Off) }
)
}

itemWithDivider {
Spacer(modifier = Modifier.height(Dimens.cellLabelVerticalPadding))
InformationComposeCell(
title = stringResource(R.string.quantum_resistant_title),
onInfoClicked = { onQuantumResistanceInfoClicked() }
)
}
itemWithDivider {
SelectableCell(
title = stringResource(id = R.string.automatic),
isSelected = uiState.quantumResistant == QuantumResistantState.Auto,
onCellClicked = { onSelectQuantumResistanceSetting(QuantumResistantState.Auto) }
)
}
itemWithDivider {
SelectableCell(
title = stringResource(id = R.string.on),
testTag = LAZY_LIST_QUANTUM_ITEM_ON_TEST_TAG,
isSelected = uiState.quantumResistant == QuantumResistantState.On,
onCellClicked = { onSelectQuantumResistanceSetting(QuantumResistantState.On) }
)
}
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,
)
SelectableCell(
title = stringResource(id = R.string.off),
testTag = LAZY_LIST_QUANTUM_ITEM_OFF_TEST_TAG,
isSelected = uiState.quantumResistant == QuantumResistantState.Off,
onCellClicked = { onSelectQuantumResistanceSetting(QuantumResistantState.Off) }
)
Spacer(modifier = Modifier.height(Dimens.cellLabelVerticalPadding))
}

item { MtuComposeCell(mtuValue = uiState.mtu, onEditMtu = { onMtuCellClick() }) }
item {
MtuSubtitle(modifier = Modifier.testTag(LAZY_LIST_LAST_ITEM_TEST_TAG))
Spacer(modifier = Modifier.height(Dimens.cellLabelVerticalPadding))
}
}
}
Expand Down
Loading