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 Sep 5, 2024
1 parent 4adbf3b commit 2bbcc3d
Show file tree
Hide file tree
Showing 42 changed files with 473 additions and 84 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/android-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ jobs:
name: relay-list
path: android/app/build/extraAssets

- name: Copy maybenot machines to asset directory
run: cp dist-assets/maybenot_machines android/app/build/extraAssets/maybenot_machines

- name: Build app
uses: burrunan/gradle-cache-action@v1
with:
Expand Down
10 changes: 10 additions & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ plugins {
val repoRootPath = rootProject.projectDir.absoluteFile.parentFile.absolutePath
val extraAssetsDirectory = "${project.buildDir}/extraAssets"
val relayListPath = "$extraAssetsDirectory/relays.json"
val maybenotMachinesDirectory = "$extraAssetsDirectory/maybenot_machines"
val defaultChangelogAssetsDirectory = "$repoRootPath/android/src/main/play/release-notes/"
val extraJniDirectory = "${project.buildDir}/extraJni"

Expand Down Expand Up @@ -239,6 +240,7 @@ android {
// Ensure all relevant assemble tasks depend on our ensure tasks.
tasks.get("assemble$capitalizedVariantName").apply {
dependsOn(tasks.get("ensureRelayListExist"))
dependsOn(tasks.get("ensureMaybenotMachinesExist"))
dependsOn(tasks.get("ensureJniDirectoryExist"))
dependsOn(tasks.get("ensureValidVersionCode"))
}
Expand Down Expand Up @@ -283,6 +285,14 @@ tasks.register("ensureRelayListExist") {
}
}

tasks.register("ensureMaybenotMachinesExist") {
doLast {
if (!file(maybenotMachinesDirectory).exists()) {
throw GradleException("Missing maybenot machines: $maybenotMachinesDirectory")
}
}
}

tasks.register("ensureJniDirectoryExist") {
doLast {
if (!file(extraJniDirectory).exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ private val DUMMY_RELAY_1 =
active = true,
provider =
Provider(providerId = ProviderId("PROVIDER RENTED"), ownership = Ownership.Rented),
daita = false,
)
private val DUMMY_RELAY_2 =
RelayItem.Location.Relay(
Expand All @@ -33,6 +34,7 @@ private val DUMMY_RELAY_2 =
active = true,
provider =
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 @@ -57,6 +57,7 @@ fun FilterRow(
is FilterChip.Ownership ->
OwnershipFilterChip(it.ownership, onRemoveOwnershipFilter)
is FilterChip.Provider -> ProviderFilterChip(it.count, onRemoveProviderFilter)
is FilterChip.Daita -> DaitaFilterChip()
}
}
}
Expand All @@ -67,6 +68,7 @@ fun ProviderFilterChip(providers: Int, onRemoveClick: () -> Unit) {
MullvadFilterChip(
text = stringResource(id = R.string.number_of_providers, providers),
onRemoveClick = onRemoveClick,
enabled = true,
)
}

Expand All @@ -75,6 +77,16 @@ fun OwnershipFilterChip(ownership: Ownership, onRemoveClick: () -> Unit) {
MullvadFilterChip(
text = stringResource(ownership.stringResources()),
onRemoveClick = onRemoveClick,
enabled = true,
)
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,24 @@ import net.mullvad.mullvadvpn.lib.theme.shape.chipShape

@Preview
@Composable
private fun PreviewMullvadFilterChip() {
private fun PreviewEnabledMullvadFilterChip() {
AppTheme {
MullvadFilterChip(
text = stringResource(id = R.string.number_of_providers),
onRemoveClick = {},
enabled = true,
)
}
}

@Preview
@Composable
private fun PreviewDisabledMullvadFilterChip() {
AppTheme {
MullvadFilterChip(
text = stringResource(id = R.string.number_of_providers),
onRemoveClick = {},
enabled = false,
)
}
}
Expand All @@ -36,30 +49,38 @@ fun MullvadFilterChip(
iconColor: Color = MaterialTheme.colorScheme.onPrimary,
text: String,
onRemoveClick: () -> Unit,
enabled: Boolean,
) {
InputChip(
enabled = enabled,
shape = MaterialTheme.shapes.chipShape,
colors =
FilterChipDefaults.filterChipColors(
containerColor = containerColor,
disabledContainerColor = containerColor,
labelColor = labelColor,
disabledLabelColor = labelColor,
iconColor = iconColor,
),
border =
FilterChipDefaults.filterChipBorder(
borderColor = borderColor,
disabledBorderColor = borderColor,
enabled = true,
selected = false,
),
selected = false,
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),
)
},
trailingIcon =
if (enabled) {
{
Icon(
painter = painterResource(id = R.drawable.icon_close),
contentDescription = null,
modifier = Modifier.size(Dimens.smallIconSize),
)
}
} else null,
)
}
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,36 @@ 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,101 @@
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 = null,
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,11 +51,13 @@ private fun generateRelayItemRelay(
cityCode: GeoLocationId.City,
hostName: String,
active: Boolean = true,
daita: Boolean = true,
) =
RelayItem.Location.Relay(
id = GeoLocationId.Hostname(city = cityCode, code = hostName),
active = active,
provider = Provider(ProviderId("Provider"), Ownership.MullvadOwned),
daita = daita,
)

private fun String.generateCountryCode() =
Expand Down
Loading

0 comments on commit 2bbcc3d

Please sign in to comment.