Skip to content

Commit 53c198e

Browse files
MaryamShaghaghiBoki91
authored andcommitted
Add toggle button for split tunneling
Co-Authored-By: Boban Sijuk <49131853+Boki91@users.noreply.github.com>
1 parent d3ed3cd commit 53c198e

File tree

10 files changed

+343
-129
lines changed

10 files changed

+343
-129
lines changed

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/SplitTunnelingCell.kt

+15-3
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,18 @@ private fun PreviewTunnelingCell() {
4141
modifier =
4242
Modifier.background(color = MaterialTheme.colorScheme.background).padding(20.dp)
4343
) {
44-
SplitTunnelingCell(title = "Mullvad VPN", packageName = "", isSelected = false)
45-
SplitTunnelingCell(title = "Mullvad VPN", packageName = "", isSelected = true)
44+
SplitTunnelingCell(
45+
title = "Mullvad VPN",
46+
packageName = "",
47+
isSelected = false,
48+
enabled = true
49+
)
50+
SplitTunnelingCell(
51+
title = "Mullvad VPN",
52+
packageName = "",
53+
isSelected = true,
54+
enabled = true
55+
)
4656
}
4757
}
4858
}
@@ -52,6 +62,7 @@ fun SplitTunnelingCell(
5262
title: String,
5363
packageName: String?,
5464
isSelected: Boolean,
65+
enabled: Boolean,
5566
modifier: Modifier = Modifier,
5667
backgroundColor: Color =
5768
MaterialTheme.colorScheme.primary
@@ -110,6 +121,7 @@ fun SplitTunnelingCell(
110121
},
111122
onCellClicked = onCellClicked,
112123
background = backgroundColor,
113-
modifier = modifier
124+
modifier = modifier,
125+
isRowEnabled = enabled
114126
)
115127
}

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Scaffolding.kt

+45
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,51 @@ fun ScaffoldWithMediumTopBar(
148148
)
149149
}
150150

151+
@Composable
152+
@OptIn(ExperimentalMaterial3Api::class)
153+
fun ScaffoldWithMediumTopBar(
154+
appBarTitle: String,
155+
modifier: Modifier = Modifier,
156+
navigationIcon: @Composable () -> Unit = {},
157+
actions: @Composable RowScope.() -> Unit = {},
158+
switch: @Composable RowScope.() -> Unit = {},
159+
lazyListState: LazyListState = rememberLazyListState(),
160+
scrollbarColor: Color = MaterialTheme.colorScheme.onBackground.copy(alpha = AlphaScrollbar),
161+
snackbarHostState: SnackbarHostState = remember { SnackbarHostState() },
162+
content: @Composable (modifier: Modifier, lazyListState: LazyListState) -> Unit
163+
) {
164+
val appBarState = rememberTopAppBarState()
165+
val canScroll = lazyListState.canScrollForward || lazyListState.canScrollBackward
166+
val scrollBehavior =
167+
TopAppBarDefaults.exitUntilCollapsedScrollBehavior(appBarState, canScroll = { canScroll })
168+
Scaffold(
169+
modifier = modifier.fillMaxSize().nestedScroll(scrollBehavior.nestedScrollConnection),
170+
topBar = {
171+
MullvadMediumTopBarWithSwitch(
172+
title = appBarTitle,
173+
navigationIcon = navigationIcon,
174+
actions,
175+
switch,
176+
scrollBehavior = scrollBehavior
177+
)
178+
},
179+
snackbarHost = {
180+
SnackbarHost(
181+
snackbarHostState,
182+
snackbar = { snackbarData -> MullvadSnackbar(snackbarData = snackbarData) }
183+
)
184+
},
185+
content = {
186+
content(
187+
Modifier.fillMaxSize()
188+
.padding(it)
189+
.drawVerticalScrollbar(state = lazyListState, color = scrollbarColor),
190+
lazyListState
191+
)
192+
}
193+
)
194+
}
195+
151196
@OptIn(ExperimentalMaterial3Api::class)
152197
@Composable
153198
fun ScaffoldWithMediumTopBar(

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/TopBar.kt

+40
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,46 @@ fun MullvadMediumTopBar(
237237
)
238238
}
239239

240+
@OptIn(ExperimentalMaterial3Api::class)
241+
@Composable
242+
fun MullvadMediumTopBarWithSwitch(
243+
title: String,
244+
navigationIcon: @Composable () -> Unit = {},
245+
actions: @Composable RowScope.() -> Unit = {},
246+
switch: @Composable RowScope.() -> Unit = {},
247+
scrollBehavior: TopAppBarScrollBehavior? = null
248+
) {
249+
MediumTopAppBar(
250+
title = {
251+
Row(
252+
modifier = Modifier.padding(end = Dimens.mediumPadding),
253+
horizontalArrangement = Arrangement.SpaceBetween,
254+
verticalAlignment = Alignment.Top
255+
) {
256+
Text(
257+
text = title,
258+
maxLines = 1,
259+
overflow = TextOverflow.Ellipsis,
260+
modifier = Modifier.weight(1f)
261+
)
262+
263+
if (scrollBehavior?.state?.collapsedFraction == 0f) {
264+
switch()
265+
}
266+
}
267+
},
268+
navigationIcon = navigationIcon,
269+
scrollBehavior = scrollBehavior,
270+
colors =
271+
TopAppBarDefaults.mediumTopAppBarColors(
272+
containerColor = MaterialTheme.colorScheme.background,
273+
scrolledContainerColor = MaterialTheme.colorScheme.background,
274+
actionIconContentColor = MaterialTheme.colorScheme.onPrimary.copy(AlphaTopBar),
275+
),
276+
actions = actions
277+
)
278+
}
279+
240280
@Preview
241281
@Composable
242282
private fun PreviewMullvadTopBarWithLongDeviceName() {

0 commit comments

Comments
 (0)