fix: androidtv multiple tunnel control

Fixes a bug where androidTV was only allowing control of a single tunnel.
Closes #268
This commit is contained in:
Zane Schepke 2024-07-27 06:04:25 -04:00
parent ac18ac8274
commit 547686069f
3 changed files with 20 additions and 7 deletions

View File

@ -134,7 +134,7 @@ jobs:
- name: On nightly release
if: ${{ contains(env.TAG_NAME, 'nightly') }}
run: |
echo "RELEASE_NOTES=Nightly build of the latest development version of the android client." >> $GITHUB_ENV
echo "RELEASE_NOTES=Nightly build for the latest development version of the app." >> $GITHUB_ENV
gh release delete nightly --yes || true
# Setup TAG_NAME, which is used as a general "name"

View File

@ -15,6 +15,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@ -31,11 +33,12 @@ fun RowListItem(
onClick: () -> Unit,
rowButton: @Composable () -> Unit,
expanded: Boolean,
statistics: TunnelStatistics?
statistics: TunnelStatistics?,
focusRequester: FocusRequester,
) {
Box(
modifier =
Modifier
Modifier.focusRequester(focusRequester)
.animateContentSize()
.clip(RoundedCornerShape(30.dp))
.combinedClickable(

View File

@ -489,6 +489,7 @@ fun MainScreen(
}
item {
if (uiState.settings.isAutoTunnelEnabled) {
val itemFocusRequester = remember { FocusRequester() }
val autoTunnelingLabel = buildAnnotatedString {
append(stringResource(id = R.string.auto_tunneling))
append(": ")
@ -516,22 +517,29 @@ fun MainScreen(
rowButton = {
if (uiState.settings.isAutoTunnelPaused) {
TextButton(
modifier = Modifier.focusRequester(itemFocusRequester),
onClick = { viewModel.resumeAutoTunneling() },
) {
Text(stringResource(id = R.string.resume))
}
} else {
TextButton(
modifier = Modifier.focusRequester(itemFocusRequester),
onClick = { viewModel.pauseAutoTunneling() },
) {
Text(stringResource(id = R.string.pause))
}
}
},
onClick = {},
onClick = {
if (WireGuardAutoTunnel.isRunningOnAndroidTv()) {
itemFocusRequester.requestFocus()
}
},
onHold = {},
expanded = false,
statistics = null,
focusRequester = focusRequester
)
}
}
@ -562,6 +570,7 @@ fun MainScreen(
} else {
Color.Gray
})
val itemFocusRequester = remember { FocusRequester() }
val expanded = remember { mutableStateOf(false) }
RowListItem(
icon = {
@ -607,11 +616,12 @@ fun MainScreen(
}
} else {
selectedTunnel = tunnel
focusRequester.requestFocus()
itemFocusRequester.requestFocus()
}
},
statistics = uiState.vpnState.statistics,
expanded = expanded.value,
focusRequester = focusRequester,
rowButton = {
if (
tunnel.id == selectedTunnel?.id &&
@ -667,7 +677,7 @@ fun MainScreen(
@Composable
fun TunnelSwitch() =
Switch(
modifier = Modifier.focusRequester(focusRequester),
modifier = Modifier.focusRequester(itemFocusRequester),
checked = checked,
onCheckedChange = { checked ->
if (!checked) expanded.value = false
@ -678,7 +688,7 @@ fun MainScreen(
Row {
IconButton(
onClick = {
if (uiState.settings.isAutoTunnelEnabled) {
if (uiState.settings.isAutoTunnelEnabled && !uiState.settings.isAutoTunnelPaused) {
appViewModel.showSnackbarMessage(
context.getString(R.string.turn_off_auto),
)