fix(presscontrols): Auto-exit when device disconnects

This commit is contained in:
darken
2026-04-28 22:39:42 +02:00
committed by Matthias Urhahn
parent 367c8d28ff
commit d0aab583d2
3 changed files with 22 additions and 1 deletions
@@ -439,6 +439,11 @@ class DeviceSettingsViewModel @Inject constructor(
fun navToPressControls() = launch {
log(TAG, INFO) { "navToPressControls()" }
val profileId = targetProfileId.value ?: return@launch
val device = deviceMonitor.getDeviceForProfile(profileId)
if (device?.isAapReady != true) {
log(TAG, INFO) { "navToPressControls(): aborted, device not AAP-ready" }
return@launch
}
navTo(Nav.Main.PressControls(profileId = profileId))
}
@@ -133,7 +133,10 @@ internal fun NoiseControlCard(
text = stringResource(R.string.press_controls_long_press_anc_cycle_info),
type = InfoBoxType.INFO,
action = {
TextButton(onClick = onPressControlsClick) {
TextButton(
onClick = onPressControlsClick,
enabled = enabled,
) {
Text(stringResource(R.string.device_settings_noise_control_open_press_controls_action))
}
},
@@ -23,6 +23,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
@@ -70,6 +71,18 @@ fun PressControlsScreenHost(
val state by vm.state.collectAsStateWithLifecycle(initialValue = null)
val currentState = state ?: return
val isAapConnected = currentState.device?.isAapConnected == true
var hasSeenAapConnected by rememberSaveable(profileId) { mutableStateOf(false) }
var didAutoNavigate by rememberSaveable(profileId) { mutableStateOf(false) }
LaunchedEffect(profileId, isAapConnected) {
if (isAapConnected) {
hasSeenAapConnected = true
} else if (hasSeenAapConnected && !didAutoNavigate) {
didAutoNavigate = true
vm.navUp()
}
}
PressControlsScreen(
state = currentState,
snackbarHostState = snackbarHostState,