diff options
| author | Albin <albin@mullvad.net> | 2023-08-07 13:40:47 +0200 |
|---|---|---|
| committer | Albin <albin@mullvad.net> | 2023-08-07 13:42:36 +0200 |
| commit | 61526a3f508f02a0aec45d3bad966544604c4b46 (patch) | |
| tree | dec4410f6121f1dae089ac0b0aed140e13a991d0 | |
| parent | d3a7629eff3a72c20fe55b6ed3b76440a780820a (diff) | |
| download | mullvadvpn-61526a3f508f02a0aec45d3bad966544604c4b46.tar.xz mullvadvpn-61526a3f508f02a0aec45d3bad966544604c4b46.zip | |
Fix split tunneling focus
| -rw-r--r-- | android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreen.kt | 37 |
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) } } |
