mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-06-01 22:19:18 +02:00
refactor(firmware): replace PlatformBackHandler with NavigationBackHandler (#5376)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -21,7 +21,6 @@ package org.meshtastic.core.ui.util
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.provider.Settings
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -181,11 +180,6 @@ actual fun KeepScreenOn(enabled: Boolean) {
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
actual fun PlatformBackHandler(enabled: Boolean, onBack: () -> Unit) {
|
||||
BackHandler(enabled = enabled, onBack = onBack)
|
||||
}
|
||||
|
||||
@Composable
|
||||
actual fun rememberRequestLocationPermission(onGranted: () -> Unit, onDenied: () -> Unit): () -> Unit {
|
||||
val launcher =
|
||||
|
||||
@@ -55,9 +55,6 @@ expect fun rememberSaveFileLauncher(
|
||||
/** Keeps the screen awake while [enabled] is true. No-op on platforms that don't support it. */
|
||||
@Composable expect fun KeepScreenOn(enabled: Boolean)
|
||||
|
||||
/** Intercepts the platform back gesture/button while [enabled] is true. No-op on platforms without a system back. */
|
||||
@Composable expect fun PlatformBackHandler(enabled: Boolean, onBack: () -> Unit)
|
||||
|
||||
/** Returns a launcher to request location permissions. */
|
||||
@Composable expect fun rememberRequestLocationPermission(onGranted: () -> Unit, onDenied: () -> Unit = {}): () -> Unit
|
||||
|
||||
|
||||
@@ -50,8 +50,6 @@ actual fun rememberOpenFileLauncher(onUriReceived: (CommonUri?) -> Unit): (mimeT
|
||||
|
||||
@Composable actual fun KeepScreenOn(enabled: Boolean) {}
|
||||
|
||||
@Composable actual fun PlatformBackHandler(enabled: Boolean, onBack: () -> Unit) {}
|
||||
|
||||
@Composable actual fun rememberRequestLocationPermission(onGranted: () -> Unit, onDenied: () -> Unit): () -> Unit = {}
|
||||
|
||||
@Composable actual fun rememberOpenLocationSettings(): () -> Unit = {}
|
||||
|
||||
@@ -115,12 +115,6 @@ actual fun KeepScreenOn(enabled: Boolean) {
|
||||
// No-op on JVM/Desktop
|
||||
}
|
||||
|
||||
/** JVM no-op — Desktop has no system back gesture. */
|
||||
@Composable
|
||||
actual fun PlatformBackHandler(enabled: Boolean, onBack: () -> Unit) {
|
||||
// No-op on JVM/Desktop — no system back button
|
||||
}
|
||||
|
||||
@Composable
|
||||
actual fun rememberRequestLocationPermission(onGranted: () -> Unit, onDenied: () -> Unit): () -> Unit = {
|
||||
Logger.w { "Location permissions not implemented on Desktop" }
|
||||
|
||||
+9
-2
@@ -70,6 +70,9 @@ import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.navigationevent.NavigationEventInfo
|
||||
import androidx.navigationevent.compose.NavigationBackHandler
|
||||
import androidx.navigationevent.compose.rememberNavigationEventState
|
||||
import coil3.compose.AsyncImage
|
||||
import coil3.compose.LocalPlatformContext
|
||||
import coil3.request.ImageRequest
|
||||
@@ -141,7 +144,6 @@ import org.meshtastic.core.ui.icon.Usb
|
||||
import org.meshtastic.core.ui.icon.Warning
|
||||
import org.meshtastic.core.ui.icon.Wifi
|
||||
import org.meshtastic.core.ui.util.KeepScreenOn
|
||||
import org.meshtastic.core.ui.util.PlatformBackHandler
|
||||
import org.meshtastic.core.ui.util.rememberOpenFileLauncher
|
||||
import org.meshtastic.core.ui.util.rememberOpenUrl
|
||||
import org.meshtastic.core.ui.util.rememberSaveFileLauncher
|
||||
@@ -185,7 +187,12 @@ fun FirmwareUpdateScreen(onNavigateUp: () -> Unit, viewModel: FirmwareUpdateView
|
||||
|
||||
KeepScreenOn(shouldKeepFirmwareScreenOn(state))
|
||||
|
||||
PlatformBackHandler(enabled = shouldKeepFirmwareScreenOn(state)) { showExitConfirmation = true }
|
||||
val backHandlerState = rememberNavigationEventState(NavigationEventInfo.None)
|
||||
NavigationBackHandler(
|
||||
state = backHandlerState,
|
||||
isBackEnabled = shouldKeepFirmwareScreenOn(state),
|
||||
onBackCompleted = { showExitConfirmation = true },
|
||||
)
|
||||
|
||||
if (showExitConfirmation) {
|
||||
MeshtasticDialog(
|
||||
|
||||
Reference in New Issue
Block a user