Pinned chats and folders in the drawer: pin, move, new, rename, fold, delete
CI / check (push) Canceled after 0s

The web sidebar's order: Pinned chats (wherever filed), the folders as a tree (folderTree:
position order, a folder whose parent is missing goes to the top), then today / earlier /
agent chats unfiled. PATCH /chats/{id} `pinned` and `folder_id` (server 96240be, f7f2ff2);
POST/PATCH/DELETE /folders. A tap folds a folder through PATCH `collapsed`, so the web folds
the same. Long press: Pin chat / Move to folder / Archive; on a folder Rename / Delete (its
chats stay). Strings from the server's catalogue. ChatGroupsTest, ContractTest (folders.json,
folder.json); the drawer shot now has a pinned chat, nested and collapsed folders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Opus 5.5 committed 2026-11-10 13:49:03 +00:00
1 parent cd88c3e712
commit 737105add2
19 files changed
+586 -24

No files matched your search

+5
View File
@@ -19,6 +19,11 @@ is in alpha and releases come off `main`.
- **Read aloud on a reply** in a chat, beside Copy, when your instance has text-to-speech: the
same voice the assistant answers in. Tap again (or another reply's) to stop; leaving the chat
stops it too.
- **Pinned chats and folders** in the drawer, as on the web: pinned chats at the top wherever
they are filed, then your folders as a tree (a tap folds or opens one, and the web folds it
too), then the rest. A long press on a chat offers **Pin chat** and **Move to folder**; on a
folder, **Rename folder** and **Delete folder** (its chats stay). **New folder** is beside New
chat at the top of the drawer.
- **A scheduled task that watches a web page** says so on its page (*Only when this page
changes*, and the address), and a run that found the page unchanged is shown as *Unchanged*.
- **A scheduled task's notification shows its result.** Unlocked, it carries the task's name
@@ -33,6 +33,7 @@ import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import eu.llembas.android.api.Chat
import eu.llembas.android.api.Folder
import eu.llembas.android.auth.Instance
import eu.llembas.android.auth.Prefs
import eu.llembas.android.push.Notifications
@@ -204,6 +205,18 @@ class MainActivity : ComponentActivity() {
override fun archive(chat: Chat) = chats.archive(chat)
override fun pin(chat: Chat, pinned: Boolean) = chats.pin(chat, pinned)
override fun move(chat: Chat, folderId: String?) = chats.move(chat, folderId)
override fun newFolder(name: String, then: Chat?) = chats.newFolder(name, then)
override fun renameFolder(folder: Folder, name: String) = chats.renameFolder(folder, name)
override fun toggleFolder(folder: Folder) = chats.toggleFolder(folder)
override fun deleteFolder(folder: Folder) = chats.deleteFolder(folder)
override fun files() = over("files")
override fun scheduled() = over("scheduled")
@@ -155,6 +155,22 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli
suspend fun folders(): List<Folder> = get<FolderList>("/folders").folders
/** A new folder, at the top or inside [parentId] (`folder.manage`; nesting is capped). */
suspend fun createFolder(name: String, parentId: String? = null): Folder = send<FolderEnvelope>(
"POST",
"/folders",
buildJsonObject {
put("name", name)
if (parentId != null) put("parent_id", parentId)
},
).folder
/** Any of `name`, `parent_id`, `collapsed`. */
suspend fun updateFolder(id: String, changes: JsonObject): Folder = send<FolderEnvelope>("PATCH", "/folders/${segment(id)}", changes).folder
/** The folder and the folders inside it; their chats fall back to no folder. */
suspend fun deleteFolder(id: String) = empty(authed("$v2/folders/${segment(id)}").delete().build())
suspend fun devices(): List<LinkedDevice> = get<DeviceList>("/devices").devices
/** The token revokes itself (`lembas logout`'s route). */
@@ -176,7 +176,17 @@ data class AgentSubagents(val offered: Boolean = false, @SerialName("device_runs
data class SubagentsOffer(val offered: Boolean = false, @SerialName("named_only") val namedOnly: Boolean = false, val cap: Int? = null)
@Serializable
data class Folder(val id: String, val name: String = "", @SerialName("parent_id") val parentId: String? = null, val kind: String = "", val position: Int = 0)
data class Folder(
val id: String,
val name: String = "",
@SerialName("parent_id") val parentId: String? = null,
val kind: String = "",
val position: Int = 0,
val collapsed: Boolean = false,
)
@Serializable
data class FolderEnvelope(val folder: Folder)
@Serializable
data class FolderList(val folders: List<Folder> = emptyList())
@@ -1,16 +1,30 @@
package eu.llembas.android.ui.home
import eu.llembas.android.api.Chat
import eu.llembas.android.api.Folder
import java.time.LocalDate
import java.time.OffsetDateTime
import java.time.ZoneId
/** A folder in the drawer, [depth] levels in, with the chats filed in it that are shown. */
data class FolderGroup(val folder: Folder, val depth: Int, val chats: List<Chat>)
/**
* The drawer's list in its sections: the chats of today, the earlier ones, and the agent chats
* (which run on a linked computer) on their own. Each keeps the server's order, newest first.
* The drawer's list in its sections, as the web's sidebar has them: the pinned chats (wherever
* they are filed), the folders as a tree with their chats, then the unfiled chats of today, the
* earlier ones, and the agent chats (which run on a linked computer) on their own. Each keeps
* the server's order, newest first.
*/
data class ChatGroups(val today: List<Chat> = emptyList(), val earlier: List<Chat> = emptyList(), val agents: List<Chat> = emptyList()) {
val isEmpty: Boolean get() = today.isEmpty() && earlier.isEmpty() && agents.isEmpty()
data class ChatGroups(
val today: List<Chat> = emptyList(),
val earlier: List<Chat> = emptyList(),
val agents: List<Chat> = emptyList(),
val pinned: List<Chat> = emptyList(),
val folders: List<FolderGroup> = emptyList(),
) {
/** Nothing to show: no chat in any section (a collapsed folder may hold some, so it counts). */
val isEmpty: Boolean get() =
today.isEmpty() && earlier.isEmpty() && agents.isEmpty() && pinned.isEmpty() && folders.all { it.chats.isEmpty() && !it.folder.collapsed }
}
/** The day a chat was last written in, where the phone is; null when the server did not say. */
@@ -19,13 +33,55 @@ fun Chat.day(zone: ZoneId): LocalDate? = (updatedAt ?: createdAt)?.let { stamp -
}
/**
* Split [chats] for the drawer, keeping those whose title holds [query] (any case; blank keeps
* all). A chat without a date counts as earlier.
* The folders as the tree they are, each after its parent and siblings in the server's
* `position` order, with its depth. A folder whose parent is not in the list counts as a top
* one, so nothing is lost.
*/
fun groupChats(chats: List<Chat>, query: String, today: LocalDate, zone: ZoneId): ChatGroups {
fun folderTree(folders: List<Folder>): List<Pair<Folder, Int>> {
val ids = folders.map { it.id }.toSet()
val children = folders.groupBy { it.parentId?.takeIf { p -> p in ids } }
val out = mutableListOf<Pair<Folder, Int>>()
val seen = mutableSetOf<String>()
fun walk(parent: String?, depth: Int) {
children[parent].orEmpty().sortedBy { it.position }.forEach { f ->
if (seen.add(f.id)) {
out += f to depth
walk(f.id, depth + 1)
}
}
}
walk(null, 0)
return out
}
/**
* Split [chats] for the drawer, keeping those whose title holds [query] (any case; blank keeps
* all). A chat without a date counts as earlier; one filed in a folder the list does not have
* counts as unfiled. A collapsed folder hides its chats and the folders inside it; while
* searching, folders without a match are left out and none is collapsed.
*/
fun groupChats(chats: List<Chat>, query: String, today: LocalDate, zone: ZoneId, folders: List<Folder> = emptyList()): ChatGroups {
val wanted = query.trim()
val shown = if (wanted.isEmpty()) chats else chats.filter { it.title.contains(wanted, ignoreCase = true) }
val (agents, plain) = shown.partition { it.isAgent }
val searching = wanted.isNotEmpty()
val shown = if (!searching) chats else chats.filter { it.title.contains(wanted, ignoreCase = true) }
val (pinned, rest) = shown.partition { it.pinned }
val ids = folders.map { it.id }.toSet()
val (filed, unfiled) = rest.partition { it.folderId != null && it.folderId in ids }
val byFolder = filed.groupBy { it.folderId }
val groups = mutableListOf<FolderGroup>()
var hiddenBelow: Int? = null
for ((folder, depth) in folderTree(folders)) {
if (hiddenBelow != null && depth > hiddenBelow) continue
hiddenBelow = null
val own = byFolder[folder.id].orEmpty()
if (searching) {
if (own.isNotEmpty()) groups += FolderGroup(folder, depth, own)
continue
}
groups += FolderGroup(folder, depth, if (folder.collapsed) emptyList() else own)
if (folder.collapsed) hiddenBelow = depth
}
val (agents, plain) = unfiled.partition { it.isAgent }
val (now, before) = plain.partition { it.day(zone) == today }
return ChatGroups(today = now, earlier = before, agents = agents)
return ChatGroups(today = now, earlier = before, agents = agents, pinned = pinned, folders = groups)
}
@@ -3,6 +3,7 @@ package eu.llembas.android.ui.home
import android.app.Application
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@@ -20,15 +21,23 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.DriveFileMove
import androidx.compose.material.icons.filled.Archive
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.CreateNewFolder
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.DriveFileRenameOutline
import androidx.compose.material.icons.filled.EditNote
import androidx.compose.material.icons.filled.ExpandLess
import androidx.compose.material.icons.filled.ExpandMore
import androidx.compose.material.icons.filled.Folder
import androidx.compose.material.icons.filled.Inventory2
import androidx.compose.material.icons.filled.PushPin
import androidx.compose.material.icons.filled.Schedule
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.filled.Terminal
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.HorizontalDivider
@@ -36,6 +45,7 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalDrawerSheet
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
@@ -61,6 +71,7 @@ import androidx.lifecycle.viewModelScope
import eu.llembas.android.R
import eu.llembas.android.api.Chat
import eu.llembas.android.api.Doorstep
import eu.llembas.android.api.Folder
import eu.llembas.android.api.fit
import eu.llembas.android.lembas
import eu.llembas.android.ui.explain
@@ -70,12 +81,20 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
import java.time.LocalDate
import java.time.ZoneId
data class ChatsState(val chats: List<Chat> = emptyList(), val more: Boolean = false, val loading: Boolean = false, val error: String? = null)
data class ChatsState(
val chats: List<Chat> = emptyList(),
val more: Boolean = false,
val loading: Boolean = false,
val error: String? = null,
/** The person's chat folders (`GET /folders`); empty where they have none. */
val folders: List<Folder> = emptyList(),
)
/** The drawer's list: every chat of the instance in use, both kinds, newest first. */
class ChatsViewModel(app: Application) : AndroidViewModel(app) {
@@ -105,7 +124,9 @@ class ChatsViewModel(app: Application) : AndroidViewModel(app) {
return@launch
}
val page = api.chats()
_state.value = ChatsState(chats = page.chats, more = page.more)
// Folders are a side dish: the chats show without them if they cannot be read.
val folders = runCatching { api.folders() }.getOrDefault(_state.value.folders)
_state.value = ChatsState(chats = page.chats, more = page.more, folders = folders)
} catch (e: Exception) {
_state.update { it.copy(loading = false, error = getApplication<Application>().explain(e)) }
}
@@ -138,6 +159,60 @@ class ChatsViewModel(app: Application) : AndroidViewModel(app) {
}
}
}
/** Pinned chats stay at the top of the list, wherever they are filed (the web's Pin). */
fun pin(chat: Chat, pinned: Boolean) = changeChat(chat.copy(pinned = pinned), buildJsonObject { put("pinned", pinned) })
/** File [chat] in [folderId], or take it out of its folder with null. */
fun move(chat: Chat, folderId: String?) = changeChat(chat.copy(folderId = folderId), buildJsonObject { put("folder_id", folderId) })
private fun changeChat(changed: Chat, body: JsonObject) {
_state.update { s -> s.copy(chats = s.chats.map { if (it.id == changed.id) changed else it }) }
viewModelScope.launch {
runCatching { getApplication<Application>().lembas.instances.client()?.updateChat(changed.id, body) }
.onFailure { e -> failed(e) }
}
}
/** A new folder at the top, and [then] the chat to file in it, if any. */
fun newFolder(name: String, then: Chat? = null) {
viewModelScope.launch {
runCatching {
val api = getApplication<Application>().lembas.instances.client() ?: return@launch
val folder = api.createFolder(name)
_state.update { it.copy(folders = it.folders + folder) }
if (then != null) move(then, folder.id)
}.onFailure { e -> failed(e) }
}
}
fun renameFolder(folder: Folder, name: String) = changeFolder(folder.copy(name = name), buildJsonObject { put("name", name) })
/** Open or fold a folder; the server keeps it, so the web's sidebar folds the same. */
fun toggleFolder(folder: Folder) = changeFolder(folder.copy(collapsed = !folder.collapsed), buildJsonObject { put("collapsed", !folder.collapsed) })
private fun changeFolder(changed: Folder, body: JsonObject) {
_state.update { s -> s.copy(folders = s.folders.map { if (it.id == changed.id) changed else it }) }
viewModelScope.launch {
runCatching { getApplication<Application>().lembas.instances.client()?.updateFolder(changed.id, body) }
.onFailure { e -> failed(e) }
}
}
/** The folder and those inside it go; their chats stay, in no folder (the server's rule). */
fun deleteFolder(folder: Folder) {
viewModelScope.launch {
runCatching { getApplication<Application>().lembas.instances.client()?.deleteFolder(folder.id) }
.onSuccess { load() }
.onFailure { e -> failed(e) }
}
}
/** A refusal is the server's sentence; the list is read again so it shows what is true. */
private fun failed(e: Throwable) {
_state.update { it.copy(error = getApplication<Application>().explain(e)) }
load()
}
}
/** Where the drawer can go, besides a chat. */
@@ -146,6 +221,12 @@ interface DrawerActions {
fun newAgentChat() {}
fun open(chatId: String) {}
fun archive(chat: Chat) {}
fun pin(chat: Chat, pinned: Boolean) {}
fun move(chat: Chat, folderId: String?) {}
fun newFolder(name: String, then: Chat?) {}
fun renameFolder(folder: Folder, name: String) {}
fun toggleFolder(folder: Folder) {}
fun deleteFolder(folder: Folder) {}
fun files() {}
fun scheduled() {}
fun archived() {}
@@ -155,9 +236,10 @@ interface DrawerActions {
}
/**
* The navigation drawer: New chat at the top, search, Files, Scheduled and Archived, then the chats --
* today's, the earlier ones, and the agent chats -- and Settings with the account at the foot.
* A long press on a chat offers Archive.
* The navigation drawer: New chat (and New folder) at the top, search, Files, Scheduled and
* Archived, then the chats -- the pinned ones, the folders as a tree with theirs, then today's,
* the earlier ones and the agent chats -- and Settings with the account at the foot. A long press
* on a chat offers Pin, Move to folder and Archive; on a folder, Rename and Delete.
*/
@Composable
fun DrawerContent(
@@ -171,11 +253,21 @@ fun DrawerContent(
) {
val palette = LocalPalette.current
var query by rememberSaveable { mutableStateOf("") }
val groups = remember(state.chats, query, today) { groupChats(state.chats, query, today, zone) }
val groups = remember(state.chats, state.folders, query, today) { groupChats(state.chats, query, today, zone, state.folders) }
// The one dialog open at a time: a chat to file, a folder to name (new or renamed), one to delete.
var moving by remember { mutableStateOf<Chat?>(null) }
var naming by remember { mutableStateOf<FolderNaming?>(null) }
var deleting by remember { mutableStateOf<Folder?>(null) }
val chatActions = remember(actions) {
ChatRowActions(open = actions::open, archive = actions::archive, pin = actions::pin, move = { moving = it })
}
ModalDrawerSheet(modifier = modifier, drawerContainerColor = palette.surface, drawerShape = RoundedCornerShape(topEnd = 24.dp, bottomEnd = 24.dp)) {
Column(Modifier.fillMaxHeight()) {
Row(Modifier.fillMaxWidth().padding(start = 24.dp, end = 8.dp, top = 12.dp), verticalAlignment = Alignment.CenterVertically) {
Text(stringResource(R.string.app_name), style = MaterialTheme.typography.titleLarge, modifier = Modifier.weight(1f))
IconButton(onClick = { naming = FolderNaming() }) {
Icon(Icons.Filled.CreateNewFolder, contentDescription = stringResource(R.string.folder_new))
}
IconButton(onClick = actions::newChat) { Icon(Icons.Filled.EditNote, contentDescription = stringResource(R.string.new_chat)) }
}
TextField(
@@ -213,9 +305,24 @@ fun DrawerContent(
}
}
}
section(R.string.chats_today, groups.today, current, actions)
section(R.string.chats_earlier, groups.earlier, current, actions)
section(R.string.chats_agents, groups.agents, current, actions)
section(R.string.chats_pinned, groups.pinned, current, chatActions, key = "pinned")
groups.folders.forEach { group ->
item(key = "f${group.folder.id}") {
FolderItem(
group.folder,
group.depth,
onToggle = { actions.toggleFolder(group.folder) },
onRename = { naming = FolderNaming(group.folder) },
onDelete = { deleting = group.folder },
)
}
items(group.chats, key = { "f${group.folder.id}/${it.id}" }) { chat ->
ChatItem(chat, chat.id == current, chatActions, indent = 16 * (group.depth + 1))
}
}
section(R.string.chats_today, groups.today, current, chatActions)
section(R.string.chats_earlier, groups.earlier, current, chatActions)
section(R.string.chats_agents, groups.agents, current, chatActions)
if (groups.isEmpty && !state.loading && state.error == null) {
item {
Text(
@@ -235,9 +342,54 @@ fun DrawerContent(
Spacer(Modifier.size(8.dp))
}
}
moving?.let { chat ->
MoveDialog(
chat,
state.folders,
onPick = { folder ->
moving = null
actions.move(chat, folder)
},
onNewFolder = {
moving = null
naming = FolderNaming(then = chat)
},
onDismiss = { moving = null },
)
}
naming?.let { asked ->
FolderNameDialog(
asked.folder?.name.orEmpty(),
title = if (asked.folder != null) R.string.folder_rename else R.string.folder_new,
onSave = { name ->
naming = null
if (asked.folder != null) actions.renameFolder(asked.folder, name) else actions.newFolder(name, asked.then)
},
onDismiss = { naming = null },
)
}
deleting?.let { folder ->
AlertDialog(
onDismissRequest = { deleting = null },
text = { Text(stringResource(R.string.folder_delete_confirm, folder.name)) },
confirmButton = {
TextButton(onClick = {
deleting = null
actions.deleteFolder(folder)
}) { Text(stringResource(R.string.folder_delete), color = LocalPalette.current.danger) }
},
dismissButton = { TextButton(onClick = { deleting = null }) { Text(stringResource(R.string.cancel)) } },
)
}
}
private fun LazyListScope.section(title: Int, chats: List<Chat>, current: String?, actions: DrawerActions) {
/** A folder to name: [folder] to rename, or a new one (into which [then] is filed, if given). */
private data class FolderNaming(val folder: Folder? = null, val then: Chat? = null)
/** What a chat's row can do: open it, and from its long-press menu Pin, Move to folder, Archive. */
private class ChatRowActions(val open: (String) -> Unit, val archive: (Chat) -> Unit, val pin: (Chat, Boolean) -> Unit, val move: (Chat) -> Unit)
private fun LazyListScope.section(title: Int, chats: List<Chat>, current: String?, actions: ChatRowActions, key: String = "c") {
if (chats.isEmpty()) return
item(key = "h$title") {
Text(
@@ -247,7 +399,134 @@ private fun LazyListScope.section(title: Int, chats: List<Chat>, current: String
modifier = Modifier.padding(start = 28.dp, end = 28.dp, top = 12.dp, bottom = 4.dp),
)
}
items(chats, key = { it.id }) { chat -> ChatItem(chat, chat.id == current, actions) }
items(chats, key = { "$key${it.id}" }) { chat -> ChatItem(chat, chat.id == current, actions) }
}
/**
* A folder's row: its name (which gives), indented by its depth, and a chevron that says whether
* it is open. A tap folds or opens it; a long press offers Rename folder and Delete folder.
*/
@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun FolderItem(folder: Folder, depth: Int, onToggle: () -> Unit, onRename: () -> Unit, onDelete: () -> Unit) {
val palette = LocalPalette.current
var menu by remember { mutableStateOf(false) }
Box(Modifier.fillMaxWidth().padding(start = 12.dp + (16 * depth).dp, end = 12.dp)) {
Row(
Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(28.dp))
.combinedClickable(onClick = onToggle, onLongClick = { menu = true })
.heightIn(min = 48.dp)
.padding(horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Icon(Icons.Filled.Folder, contentDescription = null, tint = palette.inkFaint, modifier = Modifier.size(20.dp))
Spacer(Modifier.width(12.dp))
Text(
folder.name,
style = MaterialTheme.typography.bodyLarge,
color = palette.inkMuted,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.weight(1f),
)
Icon(
if (folder.collapsed) Icons.Filled.ExpandMore else Icons.Filled.ExpandLess,
contentDescription = null,
tint = palette.inkFaint,
modifier = Modifier.size(20.dp),
)
}
DropdownMenu(expanded = menu, onDismissRequest = { menu = false }) {
DropdownMenuItem(
leadingIcon = { Icon(Icons.Filled.DriveFileRenameOutline, contentDescription = null) },
text = { Text(stringResource(R.string.folder_rename)) },
onClick = {
menu = false
onRename()
},
)
DropdownMenuItem(
leadingIcon = { Icon(Icons.Filled.Delete, contentDescription = null) },
text = { Text(stringResource(R.string.folder_delete)) },
onClick = {
menu = false
onDelete()
},
)
}
}
}
/** Move to folder: No folder, every folder as its tree, and New folder at the foot. */
@Composable
private fun MoveDialog(chat: Chat, folders: List<Folder>, onPick: (String?) -> Unit, onNewFolder: () -> Unit, onDismiss: () -> Unit) {
val palette = LocalPalette.current
val tree = remember(folders) { folderTree(folders) }
AlertDialog(
onDismissRequest = onDismiss,
title = { Text(stringResource(R.string.folder_move)) },
text = {
LazyColumn {
item { PickRow(stringResource(R.string.folder_none), depth = 0, chosen = chat.folderId == null) { onPick(null) } }
items(tree, key = { it.first.id }) { (folder, depth) ->
PickRow(folder.name, depth, chosen = chat.folderId == folder.id) { onPick(folder.id) }
}
item {
TextButton(onClick = onNewFolder, modifier = Modifier.heightIn(min = 48.dp)) {
Icon(Icons.Filled.CreateNewFolder, contentDescription = null, tint = palette.accent)
Spacer(Modifier.width(8.dp))
Text(stringResource(R.string.folder_new))
}
}
}
},
confirmButton = {},
dismissButton = { TextButton(onClick = onDismiss) { Text(stringResource(R.string.cancel)) } },
)
}
@Composable
private fun PickRow(label: String, depth: Int, chosen: Boolean, onClick: () -> Unit) {
val palette = LocalPalette.current
Row(
Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(12.dp))
.background(if (chosen) palette.accentSoft else Color.Transparent)
.clickable(onClick = onClick)
.heightIn(min = 48.dp)
.padding(start = 8.dp + (16 * depth).dp, end = 8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Icon(Icons.Filled.Folder, contentDescription = null, tint = palette.inkFaint, modifier = Modifier.size(20.dp))
Spacer(Modifier.width(12.dp))
Text(label, style = MaterialTheme.typography.bodyLarge, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
}
/** New folder / Rename folder: one line, saved only with a name. */
@Composable
private fun FolderNameDialog(initial: String, title: Int, onSave: (String) -> Unit, onDismiss: () -> Unit) {
var name by remember { mutableStateOf(initial) }
AlertDialog(
onDismissRequest = onDismiss,
title = { Text(stringResource(title)) },
text = {
OutlinedTextField(
value = name,
onValueChange = { name = it },
singleLine = true,
label = { Text(stringResource(R.string.folder_name)) },
modifier = Modifier.fillMaxWidth(),
)
},
confirmButton = {
TextButton(onClick = { onSave(name.trim()) }, enabled = name.isNotBlank()) { Text(stringResource(R.string.save)) }
},
dismissButton = { TextButton(onClick = onDismiss) { Text(stringResource(R.string.cancel)) } },
)
}
@Composable
@@ -273,10 +552,10 @@ private fun DrawerItem(icon: ImageVector, label: String, subtitle: String? = nul
/** One chat: its title (which gives), and a dot for news or for a reply being written. */
@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun ChatItem(chat: Chat, selected: Boolean, actions: DrawerActions) {
private fun ChatItem(chat: Chat, selected: Boolean, actions: ChatRowActions, indent: Int = 0) {
val palette = LocalPalette.current
var menu by remember { mutableStateOf(false) }
Box(Modifier.fillMaxWidth().padding(horizontal = 12.dp)) {
Box(Modifier.fillMaxWidth().padding(start = 12.dp + indent.dp, end = 12.dp)) {
Row(
Modifier
.fillMaxWidth()
@@ -301,6 +580,22 @@ private fun ChatItem(chat: Chat, selected: Boolean, actions: DrawerActions) {
}
}
DropdownMenu(expanded = menu, onDismissRequest = { menu = false }) {
DropdownMenuItem(
leadingIcon = { Icon(Icons.Filled.PushPin, contentDescription = null) },
text = { Text(stringResource(if (chat.pinned) R.string.chat_unpin else R.string.chat_pin)) },
onClick = {
menu = false
actions.pin(chat, !chat.pinned)
},
)
DropdownMenuItem(
leadingIcon = { Icon(Icons.AutoMirrored.Filled.DriveFileMove, contentDescription = null) },
text = { Text(stringResource(R.string.folder_move)) },
onClick = {
menu = false
actions.move(chat)
},
)
DropdownMenuItem(
leadingIcon = { Icon(Icons.Filled.Archive, contentDescription = null) },
text = { Text(stringResource(R.string.archive)) },
+10
View File
@@ -26,6 +26,16 @@
<string name="archived">Archivované</string>
<string name="archived_restore">Obnovit konverzaci</string>
<string name="archived_none">Žádné archivované konverzace.</string>
<string name="chats_pinned">Připnuté konverzace</string>
<string name="chat_pin">Připnout konverzaci</string>
<string name="chat_unpin">Odepnout konverzaci</string>
<string name="folder_move">Přesunout do složky</string>
<string name="folder_none">Bez složky</string>
<string name="folder_new">Nová složka</string>
<string name="folder_name">Název složky</string>
<string name="folder_rename">Přejmenovat složku</string>
<string name="folder_delete">Smazat složku</string>
<string name="folder_delete_confirm">Smazat složku „%1$s“? Konverzace v ní zůstanou.</string>
<string name="delete">Smazat</string>
<string name="edit">Upravit</string>
<string name="regenerate">Vygenerovat znovu</string>
+10
View File
@@ -26,6 +26,16 @@
<string name="archived">Archiviert</string>
<string name="archived_restore">Chat wiederherstellen</string>
<string name="archived_none">Keine archivierten Chats.</string>
<string name="chats_pinned">Angeheftete Chats</string>
<string name="chat_pin">Chat anheften</string>
<string name="chat_unpin">Chat loslösen</string>
<string name="folder_move">In Ordner verschieben</string>
<string name="folder_none">Kein Ordner</string>
<string name="folder_new">Neuer Ordner</string>
<string name="folder_name">Ordnername</string>
<string name="folder_rename">Ordner umbenennen</string>
<string name="folder_delete">Ordner löschen</string>
<string name="folder_delete_confirm">Den Ordner „%1$s“ löschen? Die Chats darin bleiben erhalten.</string>
<string name="delete">Löschen</string>
<string name="edit">Bearbeiten</string>
<string name="regenerate">Neu generieren</string>
+10
View File
@@ -26,6 +26,16 @@
<string name="archived">Archivados</string>
<string name="archived_restore">Restaurar chat</string>
<string name="archived_none">No hay chats archivados.</string>
<string name="chats_pinned">Chats fijados</string>
<string name="chat_pin">Fijar chat</string>
<string name="chat_unpin">Dejar de fijar el chat</string>
<string name="folder_move">Mover a carpeta</string>
<string name="folder_none">Sin carpeta</string>
<string name="folder_new">Nueva carpeta</string>
<string name="folder_name">Nombre de la carpeta</string>
<string name="folder_rename">Renombrar carpeta</string>
<string name="folder_delete">Eliminar carpeta</string>
<string name="folder_delete_confirm">¿Eliminar la carpeta «%1$s»? Los chats que contiene se conservan.</string>
<string name="delete">Eliminar</string>
<string name="edit">Editar</string>
<string name="regenerate">Regenerar</string>
+10
View File
@@ -26,6 +26,16 @@
<string name="archived">Archivées</string>
<string name="archived_restore">Restaurer la conversation</string>
<string name="archived_none">Aucune conversation archivée.</string>
<string name="chats_pinned">Discussions épinglées</string>
<string name="chat_pin">Épingler la discussion</string>
<string name="chat_unpin">Désépingler la discussion</string>
<string name="folder_move">Déplacer vers un dossier</string>
<string name="folder_none">Aucun dossier</string>
<string name="folder_new">Nouveau dossier</string>
<string name="folder_name">Nom du dossier</string>
<string name="folder_rename">Renommer le dossier</string>
<string name="folder_delete">Supprimer le dossier</string>
<string name="folder_delete_confirm">Supprimer le dossier « %1$s » ? Les conversations qu\'il contient sont conservées.</string>
<string name="delete">Supprimer</string>
<string name="edit">Modifier</string>
<string name="regenerate">Régénérer</string>
+10
View File
@@ -26,6 +26,16 @@
<string name="archived">Archivált</string>
<string name="archived_restore">Csevegés visszaállítása</string>
<string name="archived_none">Nincs archivált csevegés.</string>
<string name="chats_pinned">Kitűzött beszélgetések</string>
<string name="chat_pin">Beszélgetés kitűzése</string>
<string name="chat_unpin">Kitűzés megszüntetése</string>
<string name="folder_move">Áthelyezés mappába</string>
<string name="folder_none">Nincs mappa</string>
<string name="folder_new">Új mappa</string>
<string name="folder_name">Mappa neve</string>
<string name="folder_rename">Mappa átnevezése</string>
<string name="folder_delete">Mappa törlése</string>
<string name="folder_delete_confirm">Törli a(z) „%1$s” mappát? A benne lévő csevegések megmaradnak.</string>
<string name="delete">Törlés</string>
<string name="edit">Szerkesztés</string>
<string name="regenerate">Újragenerálás</string>
+10
View File
@@ -26,6 +26,16 @@
<string name="archived">Archiviate</string>
<string name="archived_restore">Ripristina chat</string>
<string name="archived_none">Nessuna chat archiviata.</string>
<string name="chats_pinned">Chat fissate</string>
<string name="chat_pin">Fissa la chat</string>
<string name="chat_unpin">Togli la chat dalle fissate</string>
<string name="folder_move">Sposta nella cartella</string>
<string name="folder_none">Nessuna cartella</string>
<string name="folder_new">Nuova cartella</string>
<string name="folder_name">Nome della cartella</string>
<string name="folder_rename">Rinomina cartella</string>
<string name="folder_delete">Elimina cartella</string>
<string name="folder_delete_confirm">Eliminare la cartella “%1$s”? Le chat al suo interno vengono conservate.</string>
<string name="delete">Elimina</string>
<string name="edit">Modifica</string>
<string name="regenerate">Rigenera</string>
+10
View File
@@ -26,6 +26,16 @@
<string name="archived">Zarchiwizowane</string>
<string name="archived_restore">Przywróć czat</string>
<string name="archived_none">Brak zarchiwizowanych czatów.</string>
<string name="chats_pinned">Przypięte czaty</string>
<string name="chat_pin">Przypnij czat</string>
<string name="chat_unpin">Odepnij czat</string>
<string name="folder_move">Przenieś do folderu</string>
<string name="folder_none">Bez folderu</string>
<string name="folder_new">Nowy folder</string>
<string name="folder_name">Nazwa folderu</string>
<string name="folder_rename">Zmień nazwę folderu</string>
<string name="folder_delete">Usuń folder</string>
<string name="folder_delete_confirm">Usunąć folder „%1$s”? Czaty w nim zostaną zachowane.</string>
<string name="delete">Usuń</string>
<string name="edit">Edytuj</string>
<string name="regenerate">Wygeneruj ponownie</string>
+10
View File
@@ -26,6 +26,16 @@
<string name="archived">Archivované</string>
<string name="archived_restore">Obnoviť konverzáciu</string>
<string name="archived_none">Žiadne archivované konverzácie.</string>
<string name="chats_pinned">Pripnuté konverzácie</string>
<string name="chat_pin">Pripnúť konverzáciu</string>
<string name="chat_unpin">Odopnúť konverzáciu</string>
<string name="folder_move">Presunúť do zložky</string>
<string name="folder_none">Bez zložky</string>
<string name="folder_new">Nová zložka</string>
<string name="folder_name">Názov zložky</string>
<string name="folder_rename">Premenovať zložku</string>
<string name="folder_delete">Zmazať zložku</string>
<string name="folder_delete_confirm">Zmazať zložku „%1$s“? Konverzácie v nej zostanú.</string>
<string name="delete">Zmazať</string>
<string name="edit">Upraviť</string>
<string name="regenerate">Vygenerovať znova</string>
+10
View File
@@ -27,6 +27,16 @@
<string name="archived">Archived</string>
<string name="archived_restore">Restore chat</string>
<string name="archived_none">No archived chats.</string>
<string name="chats_pinned">Pinned chats</string>
<string name="chat_pin">Pin chat</string>
<string name="chat_unpin">Unpin chat</string>
<string name="folder_move">Move to folder</string>
<string name="folder_none">No folder</string>
<string name="folder_new">New folder</string>
<string name="folder_name">Folder name</string>
<string name="folder_rename">Rename folder</string>
<string name="folder_delete">Delete folder</string>
<string name="folder_delete_confirm">Delete the folder “%1$s”? Chats inside it are kept.</string>
<string name="delete">Delete</string>
<string name="edit">Edit</string>
<string name="regenerate">Regenerate</string>
@@ -1,8 +1,11 @@
package eu.llembas.android
import eu.llembas.android.api.Chat
import eu.llembas.android.api.Folder
import eu.llembas.android.ui.home.folderTree
import eu.llembas.android.ui.home.groupChats
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import java.time.LocalDate
@@ -41,4 +44,47 @@ class ChatGroupsTest {
assertEquals(listOf("a"), groupChats(chats, " BREAD ", today, zone).earlier.map { it.id })
assertTrue(groupChats(chats, "nothing", today, zone).isEmpty)
}
@Test
fun pinnedFirstWhereverFiledAndFoldersAsATree() {
val folders = listOf(
Folder("inner", "Recipes", parentId = "top", position = 0),
Folder("top", "Waybread", position = 1),
Folder("first", "Letters", position = 0),
// Its parent is not in the list: shown at the top rather than lost.
Folder("stray", "Stray", parentId = "gone", position = 2),
)
assertEquals(listOf("first" to 0, "top" to 0, "inner" to 1, "stray" to 0), folderTree(folders).map { it.first.id to it.second })
val chats = listOf(
Chat(id = "p", title = "Pinned and filed", folderId = "inner", pinned = true),
Chat(id = "r", title = "Rye", folderId = "inner"),
Chat(id = "w", title = "Wrapping", folderId = "top"),
Chat(id = "u", title = "Unfiled", updatedAt = "2026-03-10T08:00:00+00:00"),
Chat(id = "x", title = "In a folder this list does not have", folderId = "elsewhere"),
)
val groups = groupChats(chats, "", today, zone, folders)
assertEquals(listOf("p"), groups.pinned.map { it.id })
assertEquals(
listOf("first" to emptyList(), "top" to listOf("w"), "inner" to listOf("r"), "stray" to emptyList<String>()),
groups.folders.map {
it.folder.id to
it.chats.map { c -> c.id }
},
)
assertEquals(listOf("u"), groups.today.map { it.id })
assertEquals(listOf("x"), groups.earlier.map { it.id })
}
@Test
fun aCollapsedFolderHidesItsChatsAndTheFoldersInside() {
val folders = listOf(Folder("top", "Waybread", collapsed = true), Folder("inner", "Recipes", parentId = "top"), Folder("next", "Letters", position = 1))
val chats = listOf(Chat(id = "r", title = "Rye", folderId = "inner"), Chat(id = "w", title = "Wrapping", folderId = "top"))
val groups = groupChats(chats, "", today, zone, folders)
assertEquals(listOf("top" to emptyList(), "next" to emptyList<String>()), groups.folders.map { it.folder.id to it.chats.map { c -> c.id } })
assertFalse(groups.isEmpty)
// Searching opens everything, and leaves out folders without a match.
val found = groupChats(chats, "rye", today, zone, folders)
assertEquals(listOf("inner" to listOf("r")), found.folders.map { it.folder.id to it.chats.map { c -> c.id } })
}
}
@@ -9,6 +9,8 @@ import eu.llembas.android.api.ChatPage
import eu.llembas.android.api.DoneFrame
import eu.llembas.android.api.FileContent
import eu.llembas.android.api.FileListing
import eu.llembas.android.api.FolderEnvelope
import eu.llembas.android.api.FolderList
import eu.llembas.android.api.JobsFrame
import eu.llembas.android.api.LembasJson
import eu.llembas.android.api.LiveReply
@@ -47,6 +49,15 @@ class ContractTest {
private fun <T> read(name: String, serializer: KSerializer<T>): T = LembasJson.decodeFromString(serializer, text(name))
@Test
fun theFoldersAndOne() {
val folders = read("folders", FolderList.serializer()).folders
assertEquals(listOf("fold1", "fold2"), folders.map { it.id })
assertEquals("fold1", folders[1].parentId)
assertTrue(folders[1].collapsed)
assertEquals("Waybread", read("folder", FolderEnvelope.serializer()).folder.name)
}
@Test
fun theVersionIsOneThisAppReads() {
val version = LembasJson.parseToJsonElement(text("version")).toString()
@@ -8,6 +8,7 @@ import eu.llembas.android.api.AgentsSetting
import eu.llembas.android.api.Attachment
import eu.llembas.android.api.Chat
import eu.llembas.android.api.ContextPart
import eu.llembas.android.api.Folder
import eu.llembas.android.api.LembasJson
import eu.llembas.android.api.LinkedDevice
import eu.llembas.android.api.LiveReply
@@ -264,6 +265,14 @@ object Fakes {
Chat(id = "c5", title = "Translate the recipe into Slovak", updatedAt = "2026-03-08T10:00:00+00:00"),
Chat(id = "c6", title = "Why do leaves keep bread fresh, and does it work with any leaf or only some?", updatedAt = "2026-03-01T10:00:00+00:00"),
Chat(id = "c7", title = "Clean up the build scripts", kind = "agent", updatedAt = "2026-03-02T10:00:00+00:00"),
Chat(id = "c8", title = "The cram recipe, for the long road", folderId = "f2", pinned = true, updatedAt = "2026-02-20T10:00:00+00:00"),
Chat(id = "c9", title = "Honey cakes for the party", folderId = "f2", updatedAt = "2026-02-21T10:00:00+00:00"),
Chat(id = "c10", title = "Which leaves to wrap it in", folderId = "f1", updatedAt = "2026-02-22T10:00:00+00:00"),
),
folders = listOf(
Folder(id = "f1", name = "Baking", position = 0),
Folder(id = "f2", name = "Recipes from the Shire, the long list", parentId = "f1", position = 0),
Folder(id = "f3", name = "Letters", position = 1, collapsed = true),
),
)
+11
View File
@@ -39,6 +39,16 @@ STRINGS: dict[str, str] = {
"archived": "Archived",
"archived_restore": "Restore chat",
"archived_none": "No archived chats.",
"chats_pinned": "Pinned chats",
"chat_pin": "Pin chat",
"chat_unpin": "Unpin chat",
"folder_move": "Move to folder",
"folder_none": "No folder",
"folder_new": "New folder",
"folder_name": "Folder name",
"folder_rename": "Rename folder",
"folder_delete": "Delete folder",
"folder_delete_confirm": "Delete the folder “%1$s”? Chats inside it are kept.",
"delete": "Delete",
"edit": "Edit",
"regenerate": "Regenerate",
@@ -438,4 +448,5 @@ SERVER_ENGLISH: dict[str, str] = {
"agent_steps": "%(steps)s steps, %(tools)s tools",
"agent_stop": "Stop %(name)s",
"agent_stop_member_confirm": "Stop %(name)s and the members under it? They leave the team.",
"folder_delete_confirm": "Delete the folder “%(name)s”? Chats inside it are kept.",
}