@@ -25,12 +25,14 @@ import net.mullvad.mullvadvpn.compose.cell.BaseCell
25
25
import net.mullvad.mullvadvpn.compose.cell.HeaderSwitchComposeCell
26
26
import net.mullvad.mullvadvpn.compose.cell.SplitTunnelingCell
27
27
import net.mullvad.mullvadvpn.compose.component.MullvadCircularProgressIndicatorLarge
28
+ import net.mullvad.mullvadvpn.compose.component.MullvadSwitch
28
29
import net.mullvad.mullvadvpn.compose.component.NavigateBackIconButton
29
- import net.mullvad.mullvadvpn.compose.component.ScaffoldWithMediumTopBar
30
+ import net.mullvad.mullvadvpn.compose.component.ScaffoldWithLargeTopBarAndToggleButton
30
31
import net.mullvad.mullvadvpn.compose.constant.CommonContentKey
31
32
import net.mullvad.mullvadvpn.compose.constant.ContentType
32
33
import net.mullvad.mullvadvpn.compose.constant.SplitTunnelingContentKey
33
34
import net.mullvad.mullvadvpn.compose.extensions.itemWithDivider
35
+ import net.mullvad.mullvadvpn.compose.state.AppListState
34
36
import net.mullvad.mullvadvpn.compose.state.SplitTunnelingUiState
35
37
import net.mullvad.mullvadvpn.lib.theme.AppTheme
36
38
import net.mullvad.mullvadvpn.lib.theme.Dimens
@@ -41,29 +43,32 @@ private fun PreviewSplitTunnelingScreen() {
41
43
AppTheme {
42
44
SplitTunnelingScreen (
43
45
uiState =
44
- SplitTunnelingUiState .ShowAppList (
45
- excludedApps =
46
- listOf (
47
- AppData (
48
- packageName = " my.package.a" ,
49
- name = " TitleA" ,
50
- iconRes = R .drawable.icon_alert,
51
- ),
52
- AppData (
53
- packageName = " my.package.b" ,
54
- name = " TitleB" ,
55
- iconRes = R .drawable.icon_chevron,
56
- )
57
- ),
58
- includedApps =
59
- listOf (
60
- AppData (
61
- packageName = " my.package.c" ,
62
- name = " TitleC" ,
63
- iconRes = R .drawable.icon_alert
64
- )
65
- ),
66
- showSystemApps = true
46
+ SplitTunnelingUiState (
47
+ appListState =
48
+ AppListState .ShowAppList (
49
+ excludedApps =
50
+ listOf (
51
+ AppData (
52
+ packageName = " my.package.a" ,
53
+ name = " TitleA" ,
54
+ iconRes = R .drawable.icon_alert
55
+ ),
56
+ AppData (
57
+ packageName = " my.package.b" ,
58
+ name = " TitleB" ,
59
+ iconRes = R .drawable.icon_chevron
60
+ )
61
+ ),
62
+ includedApps =
63
+ listOf (
64
+ AppData (
65
+ packageName = " my.package.c" ,
66
+ name = " TitleC" ,
67
+ iconRes = R .drawable.icon_alert
68
+ )
69
+ ),
70
+ showSystemApps = true
71
+ )
67
72
)
68
73
)
69
74
}
@@ -72,18 +77,25 @@ private fun PreviewSplitTunnelingScreen() {
72
77
@Composable
73
78
@OptIn(ExperimentalFoundationApi ::class )
74
79
fun SplitTunnelingScreen (
75
- uiState : SplitTunnelingUiState = SplitTunnelingUiState .Loading ,
80
+ uiState : SplitTunnelingUiState = SplitTunnelingUiState (),
81
+ onShowSplitTunneling : (Boolean ) -> Unit = {},
76
82
onShowSystemAppsClick : (show: Boolean ) -> Unit = {},
77
83
onExcludeAppClick : (packageName: String ) -> Unit = {},
78
84
onIncludeAppClick : (packageName: String ) -> Unit = {},
79
85
onBackClick : () -> Unit = {},
80
- onResolveIcon : (String ) -> Bitmap ? = { null },
86
+ onResolveIcon : (String ) -> Bitmap ? = { null }
81
87
) {
82
88
val focusManager = LocalFocusManager .current
83
89
84
- ScaffoldWithMediumTopBar (
90
+ ScaffoldWithLargeTopBarAndToggleButton (
85
91
modifier = Modifier .fillMaxSize(),
86
92
appBarTitle = stringResource(id = R .string.split_tunneling),
93
+ switch = {
94
+ MullvadSwitch (
95
+ checked = uiState.checked,
96
+ onCheckedChange = { newValue -> onShowSplitTunneling(newValue) }
97
+ )
98
+ },
87
99
navigationIcon = { NavigateBackIconButton (onBackClick) }
88
100
) { modifier, lazyListState ->
89
101
LazyColumn (
@@ -105,14 +117,14 @@ fun SplitTunnelingScreen(
105
117
)
106
118
}
107
119
}
108
- when (uiState) {
109
- SplitTunnelingUiState .Loading -> {
120
+ when (val appList = uiState.appListState ) {
121
+ AppListState .Loading -> {
110
122
item(key = CommonContentKey .PROGRESS , contentType = ContentType .PROGRESS ) {
111
123
MullvadCircularProgressIndicatorLarge ()
112
124
}
113
125
}
114
- is SplitTunnelingUiState .ShowAppList -> {
115
- if (uiState .excludedApps.isNotEmpty()) {
126
+ is AppListState .ShowAppList -> {
127
+ if (appList .excludedApps.isNotEmpty()) {
116
128
itemWithDivider(
117
129
key = SplitTunnelingContentKey .EXCLUDED_APPLICATIONS ,
118
130
contentType = ContentType .HEADER
@@ -126,11 +138,11 @@ fun SplitTunnelingScreen(
126
138
)
127
139
},
128
140
bodyView = {},
129
- background = MaterialTheme .colorScheme.primary,
141
+ background = MaterialTheme .colorScheme.primary
130
142
)
131
143
}
132
144
itemsIndexed(
133
- items = uiState .excludedApps,
145
+ items = appList .excludedApps,
134
146
key = { _, listItem -> listItem.packageName },
135
147
contentType = { _, _ -> ContentType .ITEM }
136
148
) { index, listItem ->
@@ -143,7 +155,7 @@ fun SplitTunnelingScreen(
143
155
) {
144
156
// Move focus down unless the clicked item was the last in this
145
157
// section.
146
- if (index < uiState .excludedApps.size - 1 ) {
158
+ if (index < appList .excludedApps.size - 1 ) {
147
159
focusManager.moveFocus(FocusDirection .Down )
148
160
} else {
149
161
focusManager.moveFocus(FocusDirection .Up )
@@ -166,7 +178,7 @@ fun SplitTunnelingScreen(
166
178
) {
167
179
HeaderSwitchComposeCell (
168
180
title = stringResource(id = R .string.show_system_apps),
169
- isToggled = uiState .showSystemApps,
181
+ isToggled = appList .showSystemApps,
170
182
onCellClicked = { newValue -> onShowSystemAppsClick(newValue) },
171
183
modifier = Modifier .animateItemPlacement()
172
184
)
@@ -185,11 +197,11 @@ fun SplitTunnelingScreen(
185
197
)
186
198
},
187
199
bodyView = {},
188
- background = MaterialTheme .colorScheme.primary,
200
+ background = MaterialTheme .colorScheme.primary
189
201
)
190
202
}
191
203
itemsIndexed(
192
- items = uiState .includedApps,
204
+ items = appList .includedApps,
193
205
key = { _, listItem -> listItem.packageName },
194
206
contentType = { _, _ -> ContentType .ITEM }
195
207
) { index, listItem ->
@@ -202,7 +214,7 @@ fun SplitTunnelingScreen(
202
214
) {
203
215
// Move focus down unless the clicked item was the last in this
204
216
// section.
205
- if (index < uiState .includedApps.size - 1 ) {
217
+ if (index < appList .includedApps.size - 1 ) {
206
218
focusManager.moveFocus(FocusDirection .Down )
207
219
} else {
208
220
focusManager.moveFocus(FocusDirection .Up )
@@ -212,6 +224,7 @@ fun SplitTunnelingScreen(
212
224
}
213
225
}
214
226
}
227
+ AppListState .Disabled -> {}
215
228
}
216
229
}
217
230
}
0 commit comments