Skip to content

Commit fb576e3

Browse files
authored
feat(android): group sidebar sessions (#128092)
* fix(android): group drawer sessions * fix(android): isolate generated locale files * fix(android): hide empty sidebar groups --------- Co-authored-by: IWhatsskill <[email protected]>
1 parent d50dbfc commit fb576e3

3 files changed

Lines changed: 119 additions & 18 deletions

File tree

‎apps/.i18n/native-source.json‎

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import androidx.compose.material.icons.Icons
2828
import androidx.compose.material.icons.filled.Close
2929
import androidx.compose.material.icons.filled.Home
3030
import androidx.compose.material.icons.filled.KeyboardArrowDown
31+
import androidx.compose.material.icons.filled.KeyboardArrowUp
3132
import androidx.compose.material.icons.filled.Settings
3233
import androidx.compose.material.icons.filled.Storage
3334
import androidx.compose.material.icons.outlined.AccessTime
@@ -40,6 +41,7 @@ import androidx.compose.material3.Icon
4041
import androidx.compose.material3.IconButton
4142
import androidx.compose.material3.Text
4243
import androidx.compose.runtime.Composable
44+
import androidx.compose.runtime.collectAsState
4345
import androidx.compose.runtime.getValue
4446
import androidx.compose.runtime.mutableStateOf
4547
import androidx.compose.runtime.remember
@@ -109,9 +111,15 @@ internal fun sidebarAgentRoster(
109111
)
110112
}
111113

114+
private const val SIDEBAR_SESSION_LIMIT = 8
115+
116+
internal data class SidebarSessionPresentation(
117+
val sections: List<SessionSection>,
118+
val canExpand: Boolean,
119+
)
120+
112121
internal fun sidebarRecentSessions(
113122
sessions: List<ChatSessionEntry>,
114-
limit: Int = 8,
115123
): List<ChatSessionEntry> =
116124
sessions
117125
.asSequence()
@@ -120,8 +128,21 @@ internal fun sidebarRecentSessions(
120128
compareByDescending<ChatSessionEntry> { it.pinned == true }
121129
.thenByDescending { it.lastActivityAt ?: it.updatedAtMs ?: 0L }
122130
.thenBy { it.key },
123-
).take(limit.coerceAtLeast(0))
124-
.toList()
131+
).toList()
132+
133+
internal fun sidebarSessionPresentation(
134+
sessions: List<ChatSessionEntry>,
135+
knownGroups: List<String>,
136+
expanded: Boolean,
137+
): SidebarSessionPresentation {
138+
val recentSessions = sidebarRecentSessions(sessions)
139+
val visibleSessions =
140+
if (expanded) recentSessions else recentSessions.take(SIDEBAR_SESSION_LIMIT)
141+
return SidebarSessionPresentation(
142+
sections = groupSessionEntries(visibleSessions, knownGroups).filter { it.entries.isNotEmpty() },
143+
canExpand = recentSessions.size > SIDEBAR_SESSION_LIMIT,
144+
)
145+
}
125146

126147
internal fun sessionPresentationTitle(
127148
session: ChatSessionEntry,
@@ -193,9 +214,16 @@ internal fun OpenClawSidebar(
193214
) {
194215
val palette = sidebarPalette()
195216
val roster = sidebarAgentRoster(agents, selectedAgentId)
217+
val storedGroups by viewModel.sessionCustomGroups.collectAsState()
196218
var query by rememberSaveable { mutableStateOf("") }
197219
var agentsExpanded by remember { mutableStateOf(false) }
198-
val recentSessions = sidebarRecentSessions(sessions)
220+
var sessionsExpanded by rememberSaveable { mutableStateOf(false) }
221+
val recentPresentation =
222+
sidebarSessionPresentation(
223+
sessions = sessions,
224+
knownGroups = storedGroups,
225+
expanded = sessionsExpanded,
226+
)
199227
val connectionLabel = gatewayStatusLabel(connection)
200228
// Canonical debounced gateway search shared with the Sessions browser; the
201229
// controller falls back to filtering cached rows when the gateway is offline.
@@ -355,24 +383,40 @@ internal fun OpenClawSidebar(
355383
}
356384

357385
SidebarSectionTitle(nativeString("Recent sessions"), palette, modifier = Modifier.padding(top = 12.dp))
358-
if (recentSessions.isEmpty()) {
386+
if (recentPresentation.sections.isEmpty()) {
359387
Text(
360388
text = nativeString("No recent sessions"),
361389
style = ClawTheme.type.caption,
362390
color = palette.muted,
363391
modifier = Modifier.padding(horizontal = 12.dp, vertical = 12.dp),
364392
)
365393
} else {
366-
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
367-
recentSessions.forEach { session ->
368-
SidebarSessionRow(
369-
session = session,
370-
selected = session.key == activeSessionKey,
371-
palette = palette,
372-
onClick = { onSelectSession(session) },
373-
)
394+
recentPresentation.sections.forEach { section ->
395+
section.title?.let { title -> SidebarSectionTitle(title, palette) }
396+
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
397+
section.entries.forEach { session ->
398+
SidebarSessionRow(
399+
session = session,
400+
selected = session.key == activeSessionKey,
401+
palette = palette,
402+
onClick = { onSelectSession(session) },
403+
)
404+
}
374405
}
375406
}
407+
if (recentPresentation.canExpand) {
408+
SidebarActionRow(
409+
label = nativeString(if (sessionsExpanded) "Show less" else "Show more"),
410+
icon =
411+
if (sessionsExpanded) {
412+
Icons.Default.KeyboardArrowUp
413+
} else {
414+
Icons.Default.KeyboardArrowDown
415+
},
416+
palette = palette,
417+
onClick = { sessionsExpanded = !sessionsExpanded },
418+
)
419+
}
376420
}
377421
}
378422
}

‎apps/android/app/src/test/java/ai/openclaw/app/ui/SidebarShellLogicTest.kt‎

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,46 @@ class SidebarShellLogicTest {
124124
}
125125

126126
@Test
127-
fun recentSessionsStayBoundedInsideTheSharedScrollableSidebar() {
128-
val rows =
129-
sidebarRecentSessions(
130-
sessions = (1L..12L).map { activity -> session("session-$activity", activity = activity) },
127+
fun collapsedSessionPresentationGroupsOnlyTheEightHighestPriorityActiveRows() {
128+
val presentation =
129+
sidebarSessionPresentation(
130+
sessions =
131+
listOf(
132+
session("pinned", activity = 1, pinned = true),
133+
session("archived", activity = 100, archived = true),
134+
) +
135+
(1L..10L).map { activity ->
136+
session(
137+
key = "session-$activity",
138+
activity = activity,
139+
category = if (activity % 2L == 0L) "Work" else null,
140+
)
141+
},
142+
knownGroups = listOf("Personal"),
143+
expanded = false,
131144
)
132145

133-
assertEquals(8, rows.size)
146+
val keys = presentation.sections.flatMap { it.entries }.map(ChatSessionEntry::key)
147+
assertEquals(8, keys.size)
148+
assertEquals(setOf("pinned", "session-10", "session-9", "session-8", "session-7", "session-6", "session-5", "session-4"), keys.toSet())
149+
assertEquals(listOf("Pinned", "Work", "Ungrouped"), presentation.sections.map { it.title })
150+
assertTrue(presentation.sections.all { it.entries.isNotEmpty() })
151+
assertTrue(presentation.canExpand)
152+
}
153+
154+
@Test
155+
fun expandedSessionPresentationRevealsAllRowsAndCollapsesToTheSameResult() {
156+
val sessions = (1L..12L).map { activity -> session("session-$activity", activity = activity) }
157+
158+
val collapsed = sidebarSessionPresentation(sessions, knownGroups = emptyList(), expanded = false)
159+
val expanded = sidebarSessionPresentation(sessions, knownGroups = emptyList(), expanded = true)
160+
161+
assertEquals(8, collapsed.sections.flatMap { it.entries }.size)
162+
assertEquals(12, expanded.sections.flatMap { it.entries }.size)
163+
assertFalse(collapsed.sections.flatMap { it.entries }.any { it.key == "session-1" })
164+
assertTrue(expanded.sections.flatMap { it.entries }.any { it.key == "session-1" })
165+
assertTrue(expanded.canExpand)
166+
assertEquals(collapsed, sidebarSessionPresentation(sessions, knownGroups = emptyList(), expanded = false))
134167
}
135168

136169
@Test
@@ -166,6 +199,7 @@ class SidebarShellLogicTest {
166199
displayName: String? = null,
167200
label: String? = null,
168201
owner: String? = null,
202+
category: String? = null,
169203
): ChatSessionEntry =
170204
ChatSessionEntry(
171205
key = key,
@@ -176,5 +210,6 @@ class SidebarShellLogicTest {
176210
displayName = displayName,
177211
label = label,
178212
ownerAgentId = owner,
213+
category = category,
179214
)
180215
}

0 commit comments

Comments
 (0)