-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement wireguard over shadowsocks
- Loading branch information
Showing
32 changed files
with
729 additions
and
147 deletions.
There are no files selected for viewing
121 changes: 121 additions & 0 deletions
121
android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/SelectObfuscationCell.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package net.mullvad.mullvadvpn.compose.cell | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.IntrinsicSize | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxHeight | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.VerticalDivider | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.tooling.preview.PreviewParameter | ||
import net.mullvad.mullvadvpn.R | ||
import net.mullvad.mullvadvpn.compose.preview.SelectObfuscationCellPreviewParameterProvider | ||
import net.mullvad.mullvadvpn.lib.model.Constraint | ||
import net.mullvad.mullvadvpn.lib.model.Port | ||
import net.mullvad.mullvadvpn.lib.model.SelectedObfuscation | ||
import net.mullvad.mullvadvpn.lib.theme.AppTheme | ||
import net.mullvad.mullvadvpn.lib.theme.Dimens | ||
import net.mullvad.mullvadvpn.lib.theme.color.selected | ||
import net.mullvad.mullvadvpn.lib.theme.typeface.listItemSubText | ||
import net.mullvad.mullvadvpn.lib.theme.typeface.listItemText | ||
|
||
@Preview | ||
@Composable | ||
private fun PreviewSelectObfuscationCellCell( | ||
@PreviewParameter(SelectObfuscationCellPreviewParameterProvider::class) | ||
selectedObfuscationCellData: Triple<SelectedObfuscation, Constraint<Port>?, Boolean>, | ||
) { | ||
AppTheme { | ||
SelectObfuscationCell( | ||
selectedObfuscation = selectedObfuscationCellData.first, | ||
port = selectedObfuscationCellData.second, | ||
isSelected = selectedObfuscationCellData.third, | ||
onSelected = {}, | ||
onNavigate = {} | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
fun SelectObfuscationCell( | ||
selectedObfuscation: SelectedObfuscation, | ||
port: Constraint<Port>? = null, | ||
isSelected: Boolean, | ||
onSelected: (SelectedObfuscation) -> Unit, | ||
onNavigate: () -> Unit = {} | ||
) { | ||
Row( | ||
modifier = | ||
Modifier.height(IntrinsicSize.Min) | ||
.fillMaxWidth() | ||
.background(MaterialTheme.colorScheme.surfaceContainerLow) | ||
) { | ||
TwoRowCell( | ||
modifier = Modifier.weight(1f), | ||
titleStyle = MaterialTheme.typography.listItemText, | ||
titleColor = MaterialTheme.colorScheme.onSurface, | ||
subtitleStyle = MaterialTheme.typography.listItemSubText, | ||
subtitleColor = MaterialTheme.colorScheme.onSurface, | ||
titleText = selectedObfuscation.toTitle(), | ||
subtitleText = port.toSubTitle()?.let { stringResource(id = R.string.port_x, it) }, | ||
onCellClicked = { onSelected(selectedObfuscation) }, | ||
minHeight = Dimens.cellHeight, | ||
background = | ||
if (isSelected) { | ||
MaterialTheme.colorScheme.selected | ||
} else { | ||
Color.Transparent | ||
}, | ||
iconView = { | ||
SelectableIcon( | ||
iconContentDescription = null, | ||
isSelected = isSelected, | ||
isEnabled = true | ||
) | ||
} | ||
) | ||
if (port != null) { | ||
VerticalDivider( | ||
color = Color.Transparent, | ||
modifier = | ||
Modifier.fillMaxHeight().padding(vertical = Dimens.verticalDividerPadding) | ||
) | ||
Icon( | ||
painterResource(id = R.drawable.icon_chevron), | ||
contentDescription = null, | ||
tint = MaterialTheme.colorScheme.onPrimary, | ||
modifier = | ||
Modifier.fillMaxHeight() | ||
.clickable { onNavigate() } | ||
.padding(horizontal = Dimens.obfuscationNavigationPadding) | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun SelectedObfuscation.toTitle() = | ||
when (this) { | ||
SelectedObfuscation.Auto -> stringResource(id = R.string.automatic) | ||
SelectedObfuscation.Off -> stringResource(id = R.string.off) | ||
SelectedObfuscation.Udp2Tcp -> stringResource(id = R.string.upd_over_tcp) | ||
SelectedObfuscation.Shadowsocks -> stringResource(id = R.string.shadowsocks) | ||
} | ||
|
||
@Composable | ||
private fun Constraint<Port>?.toSubTitle() = | ||
when (this) { | ||
Constraint.Any -> stringResource(id = R.string.automatic) | ||
is Constraint.Only -> this.value.toString() | ||
null -> null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...n/net/mullvad/mullvadvpn/compose/preview/SelectObfuscationCellPreviewParameterProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package net.mullvad.mullvadvpn.compose.preview | ||
|
||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider | ||
import net.mullvad.mullvadvpn.lib.model.Constraint | ||
import net.mullvad.mullvadvpn.lib.model.Port | ||
import net.mullvad.mullvadvpn.lib.model.SelectedObfuscation | ||
|
||
class SelectObfuscationCellPreviewParameterProvider : | ||
PreviewParameterProvider<Triple<SelectedObfuscation, Constraint<Port>?, Boolean>> { | ||
override val values: Sequence<Triple<SelectedObfuscation, Constraint<Port>?, Boolean>> = | ||
sequenceOf( | ||
Triple(SelectedObfuscation.Auto, null, false), | ||
Triple(SelectedObfuscation.Auto, null, true), | ||
Triple(SelectedObfuscation.Shadowsocks, Constraint.Any, false), | ||
Triple(SelectedObfuscation.Shadowsocks, Constraint.Any, true), | ||
Triple(SelectedObfuscation.Shadowsocks, Constraint.Only(Port(PORT)), false), | ||
Triple(SelectedObfuscation.Shadowsocks, Constraint.Only(Port(PORT)), true), | ||
Triple(SelectedObfuscation.Udp2Tcp, Constraint.Any, false), | ||
Triple(SelectedObfuscation.Udp2Tcp, Constraint.Any, true), | ||
Triple(SelectedObfuscation.Udp2Tcp, Constraint.Only(Port(PORT)), false), | ||
Triple(SelectedObfuscation.Udp2Tcp, Constraint.Only(Port(PORT)), true), | ||
Triple(SelectedObfuscation.Off, null, false), | ||
Triple(SelectedObfuscation.Off, null, true), | ||
) | ||
} | ||
|
||
private const val PORT = 44 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.