summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2023-08-07 13:40:47 +0200
committerAlbin <albin@mullvad.net>2023-08-07 13:42:36 +0200
commit61526a3f508f02a0aec45d3bad966544604c4b46 (patch)
treedec4410f6121f1dae089ac0b0aed140e13a991d0 /android
parentd3a7629eff3a72c20fe55b6ed3b76440a780820a (diff)
downloadmullvadvpn-61526a3f508f02a0aec45d3bad966544604c4b46.tar.xz
mullvadvpn-61526a3f508f02a0aec45d3bad966544604c4b46.zip
Fix split tunneling focus
Diffstat (limited to 'android')
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreen.kt37
1 files changed, 28 insertions, 9 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreen.kt
index 6ce1c6c3b9..174a1ad0e4 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreen.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreen.kt
@@ -10,7 +10,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
-import androidx.compose.foundation.lazy.items
+import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
@@ -18,6 +18,8 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
+import androidx.compose.ui.focus.FocusDirection
+import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import me.onebone.toolbar.ScrollStrategy
@@ -85,6 +87,7 @@ fun SplitTunnelingScreen(
val state = rememberCollapsingToolbarScaffoldState()
val progress = state.toolbarState.progress
val lazyListState = rememberLazyListState()
+ val focusManager = LocalFocusManager.current
CollapsingToolbarScaffold(
backgroundColor = MaterialTheme.colorScheme.background,
@@ -157,11 +160,11 @@ fun SplitTunnelingScreen(
background = MaterialTheme.colorScheme.primary,
)
}
- items(
+ itemsIndexed(
items = uiState.excludedApps,
- key = { listItem -> listItem.packageName },
- contentType = { ContentType.ITEM }
- ) { listItem ->
+ key = { _, listItem -> listItem.packageName },
+ contentType = { _, _ -> ContentType.ITEM }
+ ) { index, listItem ->
SplitTunnelingCell(
title = listItem.name,
packageName = listItem.packageName,
@@ -169,6 +172,14 @@ fun SplitTunnelingScreen(
modifier = Modifier.animateItemPlacement().fillMaxWidth(),
onResolveIcon = onResolveIcon
) {
+ // Move focus down unless the clicked item was the last in this
+ // section.
+ if (index < uiState.excludedApps.size - 1) {
+ focusManager.moveFocus(FocusDirection.Down)
+ } else {
+ focusManager.moveFocus(FocusDirection.Up)
+ }
+
onIncludeAppClick(listItem.packageName)
}
}
@@ -202,11 +213,11 @@ fun SplitTunnelingScreen(
background = MaterialTheme.colorScheme.primary,
)
}
- items(
+ itemsIndexed(
items = uiState.includedApps,
- key = { listItem -> listItem.packageName },
- contentType = { ContentType.ITEM }
- ) { listItem ->
+ key = { _, listItem -> listItem.packageName },
+ contentType = { _, _ -> ContentType.ITEM }
+ ) { index, listItem ->
SplitTunnelingCell(
title = listItem.name,
packageName = listItem.packageName,
@@ -214,6 +225,14 @@ fun SplitTunnelingScreen(
modifier = Modifier.animateItemPlacement().fillMaxWidth(),
onResolveIcon = onResolveIcon
) {
+ // Move focus down unless the clicked item was the last in this
+ // section.
+ if (index < uiState.includedApps.size - 1) {
+ focusManager.moveFocus(FocusDirection.Down)
+ } else {
+ focusManager.moveFocus(FocusDirection.Up)
+ }
+
onExcludeAppClick(listItem.packageName)
}
}