Skip to content

Commit

Permalink
Add toggle button for split tunneling
Browse files Browse the repository at this point in the history
Co-Authored-By: Boban Sijuk <[email protected]>
  • Loading branch information
2 people authored and Pururun committed Feb 7, 2024
1 parent 1b80203 commit f73477d
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,18 @@ private fun PreviewTunnelingCell() {
modifier =
Modifier.background(color = MaterialTheme.colorScheme.background).padding(20.dp)
) {
SplitTunnelingCell(title = "Mullvad VPN", packageName = "", isSelected = false)
SplitTunnelingCell(title = "Mullvad VPN", packageName = "", isSelected = true)
SplitTunnelingCell(
title = "Mullvad VPN",
packageName = "",
isSelected = false,
enabled = true
)
SplitTunnelingCell(
title = "Mullvad VPN",
packageName = "",
isSelected = true,
enabled = true
)
}
}
}
Expand All @@ -52,6 +62,7 @@ fun SplitTunnelingCell(
title: String,
packageName: String?,
isSelected: Boolean,
enabled: Boolean,
modifier: Modifier = Modifier,
backgroundColor: Color =
MaterialTheme.colorScheme.primary
Expand Down Expand Up @@ -110,6 +121,7 @@ fun SplitTunnelingCell(
},
onCellClicked = onCellClicked,
background = backgroundColor,
modifier = modifier
modifier = modifier,
isRowEnabled = enabled
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,51 @@ fun ScaffoldWithMediumTopBar(
)
}

@Composable
@OptIn(ExperimentalMaterial3Api::class)
fun ScaffoldWithMediumTopBar(
appBarTitle: String,
modifier: Modifier = Modifier,
navigationIcon: @Composable () -> Unit = {},
actions: @Composable RowScope.() -> Unit = {},
switch: @Composable RowScope.() -> Unit = {},
lazyListState: LazyListState = rememberLazyListState(),
scrollbarColor: Color = MaterialTheme.colorScheme.onBackground.copy(alpha = AlphaScrollbar),
snackbarHostState: SnackbarHostState = remember { SnackbarHostState() },
content: @Composable (modifier: Modifier, lazyListState: LazyListState) -> Unit
) {
val appBarState = rememberTopAppBarState()
val canScroll = lazyListState.canScrollForward || lazyListState.canScrollBackward
val scrollBehavior =
TopAppBarDefaults.exitUntilCollapsedScrollBehavior(appBarState, canScroll = { canScroll })
Scaffold(
modifier = modifier.fillMaxSize().nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
MullvadMediumTopBarWithSwitch(
title = appBarTitle,
navigationIcon = navigationIcon,
actions,
switch,
scrollBehavior = scrollBehavior
)
},
snackbarHost = {
SnackbarHost(
snackbarHostState,
snackbar = { snackbarData -> MullvadSnackbar(snackbarData = snackbarData) }
)
},
content = {
content(
Modifier.fillMaxSize()
.padding(it)
.drawVerticalScrollbar(state = lazyListState, color = scrollbarColor),
lazyListState
)
}
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ScaffoldWithMediumTopBar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,46 @@ fun MullvadMediumTopBar(
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MullvadMediumTopBarWithSwitch(
title: String,
navigationIcon: @Composable () -> Unit = {},
actions: @Composable RowScope.() -> Unit = {},
switch: @Composable RowScope.() -> Unit = {},
scrollBehavior: TopAppBarScrollBehavior? = null
) {
MediumTopAppBar(
title = {
Row(
modifier = Modifier.padding(end = Dimens.mediumPadding),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.Top
) {
Text(
text = title,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.weight(1f)
)

if (scrollBehavior?.state?.collapsedFraction == 0f) {
switch()
}
}
},
navigationIcon = navigationIcon,
scrollBehavior = scrollBehavior,
colors =
TopAppBarDefaults.mediumTopAppBarColors(
containerColor = MaterialTheme.colorScheme.background,
scrolledContainerColor = MaterialTheme.colorScheme.background,
actionIconContentColor = MaterialTheme.colorScheme.onPrimary.copy(AlphaTopBar),
),
actions = actions
)
}

@Preview
@Composable
private fun PreviewMullvadTopBarWithLongDeviceName() {
Expand Down
Loading

0 comments on commit f73477d

Please sign in to comment.