From 204cbd6048e3424601f5507d88a6baeaa4b46627 Mon Sep 17 00:00:00 2001 From: ericek111 Date: Sun, 11 Oct 2026 00:51:05 +0000 Subject: [PATCH] =?UTF-8?q?Android:=20client=20sheet's=20admin=20actions?= =?UTF-8?q?=20behind=20"Admin=20actions=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move to channel, the kicks, the ban and the group pickers move under one row that, once tapped, gives its place to them, raises the sheet and scrolls them into view (ExpandableAction). The row shows only when one of them is ours to use; "Move to own channel" stays in the main list. Co-Authored-By: Claude Opus 5.5 --- .../ts3j/client/android/ui/Moderation.kt | 54 ++++++++++----- .../ts3j/client/android/ui/ServerScreen.kt | 2 +- .../eu/lixko/ts3j/client/android/ui/Sheets.kt | 65 +++++++++++++++++-- 3 files changed, 97 insertions(+), 24 deletions(-) diff --git a/android/app/src/main/java/eu/lixko/ts3j/client/android/ui/Moderation.kt b/android/app/src/main/java/eu/lixko/ts3j/client/android/ui/Moderation.kt index dd7d8a9..37851e4 100644 --- a/android/app/src/main/java/eu/lixko/ts3j/client/android/ui/Moderation.kt +++ b/android/app/src/main/java/eu/lixko/ts3j/client/android/ui/Moderation.kt @@ -182,28 +182,48 @@ fun GroupsDialog( ) } -/** The kicks, the ban and the groups of [client], as far as we may use them; [onDone] once one went out. */ +/** + * The kicks, the ban and the groups of [client], as far as we may use them; [onDone] once one went out. + * Null when there is none of them. + */ @Composable -fun ClientModeration(server: ServerController, client: ClientItem, onDone: () -> Unit) { +fun clientModeration(server: ServerController, client: ClientItem, onDone: () -> Unit): (@Composable () -> Unit)? { + val serverGroups = remember(client) { server.serverGroupChoices(client.id) } + val channelGroups = remember(client) { server.channelGroupChoices(client.id) } + val kickChannel = !client.self && server.canKickFromChannel + val kickServer = !client.self && server.canKickFromServer + val ban = !client.self && server.canBanClients + val showServerGroups = serverGroups.any { it.allowed() } + val showChannelGroups = channelGroups.any { it.allowed() && !it.assigned() } + if (!(kickChannel || kickServer || ban || showServerGroups || showChannelGroups)) return null + return { + ClientModeration(server, client, serverGroups, channelGroups, kickChannel, kickServer, ban, + showServerGroups, showChannelGroups, onDone) + } +} + +@Composable +private fun ClientModeration( + server: ServerController, + client: ClientItem, + serverGroups: List, + channelGroups: List, + kickChannel: Boolean, + kickServer: Boolean, + ban: Boolean, + showServerGroups: Boolean, + showChannelGroups: Boolean, + onDone: () -> Unit, +) { var kick by remember { mutableStateOf(null) } var banning by remember { mutableStateOf(false) } var groups by remember { mutableStateOf(null) } - val serverGroups = remember(client) { server.serverGroupChoices(client.id) } - val channelGroups = remember(client) { server.channelGroupChoices(client.id) } - if (!client.self) { - if (server.canKickFromChannel) Action("KICK_FROM_CHANNEL", "Kick from channel") { kick = false } - if (server.canKickFromServer) Action("KICK_FROM_SERVER", "Kick from server") { kick = true } - if (server.canBanClients) Action("BAN_CLIENT", "Ban") { banning = true } - } - val showServerGroups = serverGroups.any { it.allowed() } - val showChannelGroups = channelGroups.any { it.allowed() && !it.assigned() } - if (showServerGroups || showChannelGroups) { - Row { - if (showServerGroups) Action("PERMISSIONS_SERVER_GROUPS", "Server groups", Modifier.weight(1f)) { groups = true } - if (showChannelGroups) Action("PERMISSIONS_CHANNEL_GROUPS", "Channel group", Modifier.weight(1f)) { groups = false } - } - } + if (kickChannel) Action("KICK_FROM_CHANNEL", "Kick from channel") { kick = false } + if (kickServer) Action("KICK_FROM_SERVER", "Kick from server") { kick = true } + if (ban) Action("BAN_CLIENT", "Ban") { banning = true } + if (showServerGroups) Action("PERMISSIONS_SERVER_GROUPS", "Server groups") { groups = true } + if (showChannelGroups) Action("PERMISSIONS_CHANNEL_GROUPS", "Channel group") { groups = false } kick?.let { fromServer -> KickPrompt( diff --git a/android/app/src/main/java/eu/lixko/ts3j/client/android/ui/ServerScreen.kt b/android/app/src/main/java/eu/lixko/ts3j/client/android/ui/ServerScreen.kt index e60e5e8..a1e27c5 100644 --- a/android/app/src/main/java/eu/lixko/ts3j/client/android/ui/ServerScreen.kt +++ b/android/app/src/main/java/eu/lixko/ts3j/client/android/ui/ServerScreen.kt @@ -451,7 +451,7 @@ fun ServerScreen( showChat = false reveal = TreeRef(false, id) }), - moderation = { ClientModeration(server, client) { clientSheet = null } }, + moderation = clientModeration(server, client) { clientSheet = null }, ) } } diff --git a/android/app/src/main/java/eu/lixko/ts3j/client/android/ui/Sheets.kt b/android/app/src/main/java/eu/lixko/ts3j/client/android/ui/Sheets.kt index 833c647..504358d 100644 --- a/android/app/src/main/java/eu/lixko/ts3j/client/android/ui/Sheets.kt +++ b/android/app/src/main/java/eu/lixko/ts3j/client/android/ui/Sheets.kt @@ -1,6 +1,19 @@ package eu.lixko.ts3j.client.android.ui +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.expandVertically +import androidx.compose.animation.fadeIn import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.ColumnScope +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.KeyboardArrowDown +import androidx.compose.material3.Icon +import androidx.compose.foundation.relocation.BringIntoViewRequester +import androidx.compose.foundation.relocation.bringIntoViewRequester +import androidx.compose.material3.rememberModalBottomSheetState +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.layout.onSizeChanged +import kotlinx.coroutines.launch import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth @@ -63,11 +76,17 @@ fun ClientSheet( onMoveToOwnChannel: (() -> Unit)?, /** Null when the sheet was opened from the tree. */ onFindInTree: (() -> Unit)?, - /** Kicks, bans and groups, as far as we may use them. */ - moderation: @Composable () -> Unit = {}, + /** Kicks, bans and groups, as far as we may use them; null when there are none. */ + moderation: (@Composable () -> Unit)? = null, ) { var poking by remember { mutableStateOf(false) } - ModalBottomSheet(onDismissRequest = onDismiss) { + val sheetState = rememberModalBottomSheetState() + val scope = rememberCoroutineScope() + // A half-open sheet would fold the admin actions out below the screen's edge. + val adminActions = @Composable { content: @Composable ColumnScope.() -> Unit -> + ExpandableAction("PERMISSIONS_CLIENTS", "Admin actions…", onExpand = { scope.launch { sheetState.expand() } }, content) + } + ModalBottomSheet(onDismissRequest = onDismiss, sheetState = sheetState) { Column(Modifier.verticalScroll(rememberScrollState()).navigationBarsPadding().padding(bottom = 16.dp)) { Row(Modifier.padding(horizontal = 24.dp, vertical = 8.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp)) { @@ -93,15 +112,19 @@ fun ClientSheet( onFindInTree?.let { Action("CHANNEL_SWITCH", "Find client in channel tree", onClick = it) } if (client.self) { Action("AWAY", if (away) "Back" else "Away") { onAway(!away) } - moderation() + moderation?.let { adminActions { it() } } } else { Action("PLAYER_CHAT", "Send message", onClick = onMessage) Action("POKE", "Poke") { poking = true } onWhisper?.let { Action("PLAYER_WHISPER", "Whisper", onClick = it) } // "Add to whisper list…" (onAddToWhisperList) is left out for now. - onMove?.let { Action("CHANNEL_SWITCH", "Move to channel…", onClick = it) } onMoveToOwnChannel?.let { Action("MOVE_CLIENT_TO_OWN_CHANNEL", "Move to own channel", onClick = it) } - moderation() + if (onMove != null || moderation != null) { + adminActions { + onMove?.let { Action("CHANNEL_SWITCH", "Move to channel…", onClick = it) } + moderation?.invoke() + } + } if (client.contactType == null) { Row { Action("ADD_FRIEND", "Add as friend", Modifier.weight(1f)) { onAddContact(ContactType.FRIEND) } @@ -215,6 +238,36 @@ internal fun Action(iconKey: String, label: String, modifier: Modifier = Modifie ) } +/** A row that, once tapped, gives its place to the [content] it stands for, scrolled into view. */ +@Composable +internal fun ExpandableAction( + iconKey: String, + label: String, + onExpand: () -> Unit = {}, + content: @Composable ColumnScope.() -> Unit, +) { + var expanded by remember { mutableStateOf(false) } + val scope = rememberCoroutineScope() + val inView = remember { BringIntoViewRequester() } + if (!expanded) { + ListItem( + headlineContent = { Text(label) }, + leadingContent = { PackIcon(iconKey, null) }, + trailingContent = { Icon(Icons.Filled.KeyboardArrowDown, null) }, + colors = ListItemDefaults.colors(containerColor = Color.Transparent), + modifier = Modifier.fillMaxWidth().clickable { expanded = true; onExpand() }.padding(horizontal = 8.dp), + ) + } + AnimatedVisibility(expanded, enter = expandVertically() + fadeIn()) { + Column( + Modifier.bringIntoViewRequester(inView) + // Follows the items as they unfold. + .onSizeChanged { scope.launch { inView.bringIntoView() } }, + content = content, + ) + } +} + /** Asks for one line of text. */ @Composable fun TextPrompt(