mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-14 18:26:11 -04:00
fix(presscontrols): Auto-exit when device disconnects
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user