diff --git a/wear/src/main/java/com/tutpro/baresip/wear/MainActivity.kt b/wear/src/main/java/com/tutpro/baresip/wear/MainActivity.kt index e94064a0..fe9dabc8 100644 --- a/wear/src/main/java/com/tutpro/baresip/wear/MainActivity.kt +++ b/wear/src/main/java/com/tutpro/baresip/wear/MainActivity.kt @@ -8,6 +8,7 @@ import android.os.Build import android.os.Bundle import android.view.KeyEvent import androidx.activity.ComponentActivity +import androidx.activity.compose.BackHandler import androidx.activity.compose.setContent import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.foundation.layout.* @@ -189,6 +190,17 @@ class MainActivity : ComponentActivity() { fun WearApp(activity: MainActivity) { // Show the in-call screen whenever there is an active or incoming call. val hasCall by remember { derivedStateOf { CallState.calls.isNotEmpty() } } + // Intercept the system back gesture so navigation stays inside the app + // (Messages/Conversation/Accounts screens pop to their parent instead of + // finishing the Activity and dropping to the clock face). At the root + // "dialer" route the handler is disabled, so back behaves normally. + BackHandler(enabled = activity.route.value != "dialer") { + activity.route.value = when { + activity.route.value.startsWith("thread:") -> "messages" + activity.route.value == "messages" || activity.route.value == "accounts" -> "dialer" + else -> "dialer" + } + } MaterialTheme { Scaffold(timeText = { TimeText() }) { when {