From f0a4fd18cd28cc0caf1f7734932aaf2c9079e725 Mon Sep 17 00:00:00 2001 From: jamie prince Date: Fri, 21 Aug 2026 04:09:41 +0100 Subject: [PATCH] Wear UI: intercept system back so Messages/Conversation/Accounts pop within app Add BackHandler in WearApp: back from thread: -> messages, messages/accounts -> dialer. At the root dialer route the handler is disabled so back finishes the Activity normally. Fixes back-from-Messages dropping to the clock face. --- .../java/com/tutpro/baresip/wear/MainActivity.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 {