Skip to content

Commit

Permalink
Add daita grpc and ui
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-mullvad committed Aug 28, 2024
1 parent 63cb6a8 commit def3fa2
Show file tree
Hide file tree
Showing 40 changed files with 481 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ private val DUMMY_RELAY_1 =
Provider(
providerId = ProviderId("PROVIDER RENTED"),
ownership = Ownership.Rented,
)
),
daita = false
)
private val DUMMY_RELAY_2 =
RelayItem.Location.Relay(
Expand All @@ -35,7 +36,8 @@ private val DUMMY_RELAY_2 =
),
active = true,
provider =
Provider(providerId = ProviderId("PROVIDER OWNED"), ownership = Ownership.MullvadOwned)
Provider(providerId = ProviderId("PROVIDER OWNED"), ownership = Ownership.MullvadOwned),
daita = false
)
private val DUMMY_RELAY_CITY_1 =
RelayItem.Location.City(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fun FilterRow(
is FilterChip.Ownership ->
OwnershipFilterChip(it.ownership, onRemoveOwnershipFilter)
is FilterChip.Provider -> ProviderFilterChip(it.count, onRemoveProviderFilter)
is FilterChip.Daita -> DaitaFilterChip()
}
}
}
Expand All @@ -68,15 +69,26 @@ fun FilterRow(
fun ProviderFilterChip(providers: Int, onRemoveClick: () -> Unit) {
MullvadFilterChip(
text = stringResource(id = R.string.number_of_providers, providers),
onRemoveClick = onRemoveClick
onRemoveClick = onRemoveClick,
showIcon = true
)
}

@Composable
fun OwnershipFilterChip(ownership: Ownership, onRemoveClick: () -> Unit) {
MullvadFilterChip(
text = stringResource(ownership.stringResources()),
onRemoveClick = onRemoveClick
onRemoveClick = onRemoveClick,
showIcon = true
)
}

@Composable
fun DaitaFilterChip() {
MullvadFilterChip(
text = stringResource(id = R.string.setting_chip, stringResource(id = R.string.daita)),
onRemoveClick = {},
showIcon = false
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ private fun PreviewMullvadFilterChip() {
AppTheme {
MullvadFilterChip(
text = stringResource(id = R.string.number_of_providers),
onRemoveClick = {}
onRemoveClick = {},
showIcon = true
)
}
}
Expand All @@ -35,7 +36,8 @@ fun MullvadFilterChip(
labelColor: Color = MaterialTheme.colorScheme.onPrimary,
iconColor: Color = MaterialTheme.colorScheme.onPrimary,
text: String,
onRemoveClick: () -> Unit
onRemoveClick: () -> Unit,
showIcon: Boolean
) {
InputChip(
shape = MaterialTheme.shapes.chipShape,
Expand All @@ -55,11 +57,13 @@ fun MullvadFilterChip(
onClick = onRemoveClick,
label = { Text(text = text, style = MaterialTheme.typography.labelMedium) },
trailingIcon = {
Icon(
painter = painterResource(id = R.drawable.icon_close),
contentDescription = null,
modifier = Modifier.size(Dimens.smallIconSize)
)
if (showIcon) {
Icon(
painter = painterResource(id = R.drawable.icon_close),
contentDescription = null,
modifier = Modifier.size(Dimens.smallIconSize)
)
}
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private fun PreviewLocationInfo() {
isVisible = true,
isExpanded = true,
location = null,
isUsingDaita = false,
inAddress = null,
outAddress = ""
)
Expand All @@ -48,6 +49,7 @@ fun LocationInfo(
isVisible: Boolean,
isExpanded: Boolean,
location: GeoIpLocation?,
isUsingDaita: Boolean,
inAddress: Triple<String, Int, TransportProtocol>?,
outAddress: String
) {
Expand All @@ -61,15 +63,12 @@ fun LocationInfo(
.then(modifier)
) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = location?.hostname ?: "",
color =
if (isExpanded) {
colorExpanded
} else {
colorCollapsed
},
style = MaterialTheme.typography.labelLarge.copy(fontWeight = FontWeight.SemiBold)
RelayHostname(
hostname = location?.hostname,
isUsingDaita = isUsingDaita,
isExpanded = isExpanded,
colorExpanded = colorExpanded,
colorCollapsed = colorCollapsed,
)
Chevron(
isExpanded = isExpanded,
Expand Down Expand Up @@ -119,3 +118,38 @@ fun LocationInfo(
)
}
}

@Composable
private fun RelayHostname(
hostname: String?,
isUsingDaita: Boolean,
isExpanded: Boolean,
colorExpanded: Color,
colorCollapsed: Color
) {
val hostnameTitle =
when {
hostname != null && isUsingDaita -> {
stringResource(
id = R.string.connected_using_daita,
hostname,
stringResource(
id = R.string.daita,
)
)
}
hostname != null -> hostname
else -> ""
}

Text(
text = hostnameTitle,
color =
if (isExpanded) {
colorExpanded
} else {
colorCollapsed
},
style = MaterialTheme.typography.labelLarge.copy(fontWeight = FontWeight.SemiBold),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package net.mullvad.mullvadvpn.compose.dialog

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.annotation.RootGraph
import com.ramcosta.composedestinations.result.EmptyResultBackNavigator
import com.ramcosta.composedestinations.result.ResultBackNavigator
import com.ramcosta.composedestinations.spec.DestinationStyle
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.button.PrimaryButton
import net.mullvad.mullvadvpn.compose.component.drawVerticalScrollbar
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.lib.theme.Dimens
import net.mullvad.mullvadvpn.lib.theme.color.AlphaScrollbar

@Preview
@Composable
private fun PreviewDaitaConfirmationDialog() {
AppTheme { DaitaConfirmation(EmptyResultBackNavigator()) }
}

@Destination<RootGraph>(style = DestinationStyle.Dialog::class)
@Composable
fun DaitaConfirmation(navigator: ResultBackNavigator<Boolean>) {
AlertDialog(
onDismissRequest = dropUnlessResumed { navigator.navigateBack(false) },
icon = {
Icon(
modifier = Modifier.fillMaxWidth().height(Dimens.dialogIconHeight),
painter = painterResource(id = R.drawable.icon_alert),
contentDescription = "",
tint = MaterialTheme.colorScheme.onSurface
)
},
text = {
val scrollState = rememberScrollState()
Column(
Modifier.drawVerticalScrollbar(
scrollState,
MaterialTheme.colorScheme.onPrimary.copy(alpha = AlphaScrollbar)
)
.verticalScroll(scrollState),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(
text = stringResource(id = R.string.daita_relay_subset_warning),
color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.fillMaxWidth(),
)

Spacer(modifier = Modifier.height(Dimens.verticalSpace))

Text(
text =
stringResource(
id = R.string.daita_warning,
stringResource(
id = R.string.daita,
),
),
color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.fillMaxWidth(),
)
}
},
confirmButton = {
Column(verticalArrangement = Arrangement.spacedBy(Dimens.buttonSpacing)) {
PrimaryButton(
modifier = Modifier.fillMaxWidth(),
text = stringResource(R.string.enable_anyway),
onClick = { navigator.navigateBack(true) },
)

PrimaryButton(
modifier = Modifier.fillMaxWidth(),
text = stringResource(R.string.back),
onClick = dropUnlessResumed { navigator.navigateBack(false) },
)
}
},
containerColor = MaterialTheme.colorScheme.surface,
titleContentColor = MaterialTheme.colorScheme.onSurface,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package net.mullvad.mullvadvpn.compose.dialog

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.annotation.RootGraph
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator
import com.ramcosta.composedestinations.spec.DestinationStyle
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.lib.theme.AppTheme

@Preview
@Composable
private fun PreviewDaitaInfoDialog() {
AppTheme { DaitaInfo(EmptyDestinationsNavigator) }
}

@Destination<RootGraph>(style = DestinationStyle.Dialog::class)
@Composable
fun DaitaInfo(navigator: DestinationsNavigator) {
InfoDialog(
message =
stringResource(
id = R.string.daita_info,
stringResource(id = R.string.daita),
stringResource(id = R.string.daita_full),
),
additionalInfo =
stringResource(id = R.string.daita_warning, stringResource(id = R.string.daita)),
onDismiss = dropUnlessResumed { navigator.navigateUp() },
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private fun generateRelayItemRelay(
cityCode: GeoLocationId.City,
hostName: String,
active: Boolean = true,
daita: Boolean = true,
) =
RelayItem.Location.Relay(
id =
Expand All @@ -60,6 +61,7 @@ private fun generateRelayItemRelay(
),
active = active,
provider = Provider(ProviderId("Provider"), Ownership.MullvadOwned),
daita = daita
)

private fun String.generateCountryCode() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ object TunnelStatePreviewData {

fun generateConnectingState(featureIndicators: Int, quantumResistant: Boolean) =
TunnelState.Connecting(
endpoint = generateTunnelEndpoint(quantumResistant = quantumResistant),
endpoint = generateTunnelEndpoint(quantumResistant = quantumResistant, daita = false),
location = generateLocation(),
featureIndicators = generateFeatureIndicators(featureIndicators)
)

fun generateConnectedState(featureIndicators: Int, quantumResistant: Boolean) =
TunnelState.Connected(
endpoint = generateTunnelEndpoint(quantumResistant = quantumResistant),
endpoint = generateTunnelEndpoint(quantumResistant = quantumResistant, daita = true),
location = generateLocation(),
featureIndicators = generateFeatureIndicators(featureIndicators)
)
Expand All @@ -39,15 +39,16 @@ object TunnelStatePreviewData {
)
}

private fun generateTunnelEndpoint(quantumResistant: Boolean): TunnelEndpoint =
private fun generateTunnelEndpoint(quantumResistant: Boolean, daita: Boolean): TunnelEndpoint =
TunnelEndpoint(
endpoint = generateEndpoint(TransportProtocol.Udp),
quantumResistant = quantumResistant,
obfuscation =
ObfuscationEndpoint(
endpoint = generateEndpoint(TransportProtocol.Tcp),
ObfuscationType.Udp2Tcp
)
),
daita = daita
)

private fun generateEndpoint(transportProtocol: TransportProtocol) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ private fun ConnectionInfo(state: ConnectUiState) {
isVisible = state.showLocationInfo,
isExpanded = expanded,
location = state.location,
isUsingDaita = state.tunnelState.isUsingDaita(),
inAddress = state.inAddress,
outAddress = state.outAddress,
modifier =
Expand Down
Loading

0 comments on commit def3fa2

Please sign in to comment.