Skip to content

Commit 4f87400

Browse files
committed
refactor(android): distill companion shell cleanup
1 parent 9159b3b commit 4f87400

3 files changed

Lines changed: 12 additions & 49 deletions

File tree

‎apps/android/app/src/main/java/ai/openclaw/app/ui/ShellScreen.kt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,10 +793,8 @@ private fun ChatShellScreen(
793793
) {
794794
ChatScreen(
795795
viewModel = viewModel,
796-
onBack = {},
797796
onVoice = onVoice,
798797
onOpenSessions = onOpenSessions,
799-
showBackButton = false,
800798
)
801799
}
802800
}

‎apps/android/app/src/main/java/ai/openclaw/app/ui/chat/ChatScreen.kt‎

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import androidx.compose.foundation.shape.CircleShape
3838
import androidx.compose.foundation.shape.RoundedCornerShape
3939
import androidx.compose.foundation.text.BasicTextField
4040
import androidx.compose.material.icons.Icons
41-
import androidx.compose.material.icons.automirrored.filled.ArrowBack
4241
import androidx.compose.material.icons.automirrored.filled.Send
4342
import androidx.compose.material.icons.filled.AttachFile
4443
import androidx.compose.material.icons.filled.Close
@@ -80,10 +79,8 @@ import java.util.Locale
8079
@Composable
8180
fun ChatScreen(
8281
viewModel: MainViewModel,
83-
onBack: () -> Unit,
8482
onVoice: () -> Unit,
85-
onOpenSessions: (() -> Unit)? = null,
86-
showBackButton: Boolean = true,
83+
onOpenSessions: () -> Unit,
8784
) {
8885
val messages by viewModel.chatMessages.collectAsState()
8986
val historyLoading by viewModel.chatHistoryLoading.collectAsState()
@@ -162,12 +159,10 @@ fun ChatScreen(
162159
thinkingLevel = thinkingLevel,
163160
healthOk = healthOk,
164161
pendingRunCount = pendingRunCount,
165-
onBack = onBack,
166162
onMore = {
167163
viewModel.refreshChat()
168164
viewModel.refreshChatSessions(limit = 100)
169165
},
170-
showBackButton = showBackButton,
171166
)
172167

173168
ChatSessionSwitcher(
@@ -236,7 +231,7 @@ private fun ChatSessionSwitcher(
236231
sessions: List<ChatSessionEntry>,
237232
mainSessionKey: String,
238233
onSelectSession: (String) -> Unit,
239-
onOpenSessions: (() -> Unit)?,
234+
onOpenSessions: () -> Unit,
240235
) {
241236
val choices =
242237
remember(sessionKey, sessions, mainSessionKey) {
@@ -260,7 +255,7 @@ private fun ChatSessionSwitcher(
260255
onClick = { onSelectSession(entry.key) },
261256
)
262257
}
263-
if (onOpenSessions != null && sessions.size > choices.size) {
258+
if (sessions.size > choices.size) {
264259
Surface(
265260
onClick = onOpenSessions,
266261
modifier = Modifier.heightIn(min = 36.dp),
@@ -312,20 +307,14 @@ private fun ChatHeader(
312307
thinkingLevel: String,
313308
healthOk: Boolean,
314309
pendingRunCount: Int,
315-
onBack: () -> Unit,
316310
onMore: () -> Unit,
317-
showBackButton: Boolean,
318311
) {
319312
Row(
320313
modifier = Modifier.fillMaxWidth(),
321314
verticalAlignment = Alignment.CenterVertically,
322315
horizontalArrangement = Arrangement.spacedBy(6.dp),
323316
) {
324-
if (showBackButton) {
325-
HeaderIcon(icon = Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back", onClick = onBack)
326-
} else {
327-
Box(modifier = Modifier.size(ClawTheme.spacing.touchTarget))
328-
}
317+
Box(modifier = Modifier.size(ClawTheme.spacing.touchTarget))
329318

330319
Column(
331320
modifier = Modifier.weight(1f),

‎apps/android/app/src/main/java/ai/openclaw/app/ui/chat/SessionFilters.kt‎

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,9 @@ import ai.openclaw.app.chat.ChatSessionEntry
44

55
private const val RECENT_WINDOW_MS = 24 * 60 * 60 * 1000L
66

7-
/**
8-
* Derive a human-friendly label from a raw session key.
9-
* Examples:
10-
* "telegram:g-agent-main-main" -> "Main"
11-
* "agent:main:main" -> "Main"
12-
* "discord:g-server-channel" -> "Server Channel"
13-
* "my-custom-session" -> "My Custom Session"
14-
*/
157
fun friendlySessionName(key: String): String {
16-
// Strip common prefixes like "telegram:", "agent:", "discord:" etc.
178
val stripped = key.substringAfterLast(":")
18-
19-
// Remove leading "g-" prefix (gateway artifact)
209
val cleaned = if (stripped.startsWith("g-")) stripped.removePrefix("g-") else stripped
21-
22-
// Split on hyphens/underscores, title-case each word, collapse "main main" -> "Main"
2310
val words =
2411
cleaned
2512
.split('-', '_')
@@ -79,7 +66,6 @@ fun resolveSessionChoices(
7966
return result
8067
}
8168

82-
/** Builds the compact top-of-chat session switcher without dropping main or the active session. */
8369
fun resolveCompactSessionChoices(
8470
currentSessionKey: String,
8571
sessions: List<ChatSessionEntry>,
@@ -94,24 +80,14 @@ fun resolveCompactSessionChoices(
9480
mainSessionKey = mainSessionKey,
9581
nowMs = nowMs,
9682
)
97-
if (allChoices.size <= maxOptions) return allChoices
98-
9983
val mainKey = mainSessionKey.trim().ifEmpty { "main" }
10084
val current = currentSessionKey.trim().let { if (it == "main" && mainKey != "main") mainKey else it }
101-
val pinnedKeys = listOf(mainKey, current).filter { it.isNotBlank() }
102-
val result = mutableListOf<ChatSessionEntry>()
103-
val seen = mutableSetOf<String>()
104-
105-
pinnedKeys.forEach { key ->
106-
allChoices.firstOrNull { it.key == key }?.let { entry ->
107-
if (seen.add(entry.key)) result.add(entry)
108-
}
109-
}
110-
111-
allChoices.forEach { entry ->
112-
if (result.size >= maxOptions) return@forEach
113-
if (seen.add(entry.key)) result.add(entry)
114-
}
115-
116-
return result
85+
val pinnedRank = listOf(mainKey, current).filter { it.isNotBlank() }.distinct().withIndex().associate { it.value to it.index }
86+
val unpinnedRank = pinnedRank.size
87+
88+
return allChoices
89+
.withIndex()
90+
.sortedWith(compareBy({ pinnedRank[it.value.key] ?: unpinnedRank }, { it.index }))
91+
.take(maxOptions)
92+
.map { it.value }
11793
}

0 commit comments

Comments
 (0)