Android: client sheet's admin actions behind "Admin actions…"

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 <noreply@anthropic.com>
This commit is contained in:
2026-10-11 00:51:05 +00:00
co-authored by Claude Opus 5.5
parent 7fde4f502a
commit 204cbd6048
3 changed files with 97 additions and 24 deletions
@@ -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<GroupChoice>,
channelGroups: List<GroupChoice>,
kickChannel: Boolean,
kickServer: Boolean,
ban: Boolean,
showServerGroups: Boolean,
showChannelGroups: Boolean,
onDone: () -> Unit,
) {
var kick by remember { mutableStateOf<Boolean?>(null) }
var banning by remember { mutableStateOf(false) }
var groups by remember { mutableStateOf<Boolean?>(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(
@@ -451,7 +451,7 @@ fun ServerScreen(
showChat = false
reveal = TreeRef(false, id)
}),
moderation = { ClientModeration(server, client) { clientSheet = null } },
moderation = clientModeration(server, client) { clientSheet = null },
)
}
}
@@ -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(