Join a channel by double-tapping it in the tree

The channel sheet's Join and the double-tap share one password prompt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 21:32:41 +00:00
co-authored by Claude Opus 5.5
parent ec3a43a689
commit 4cdbdea9a2
3 changed files with 41 additions and 20 deletions
@@ -13,6 +13,7 @@ import androidx.compose.runtime.derivedStateOf
import androidx.compose.animation.core.tween import androidx.compose.animation.core.tween
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
@@ -139,6 +140,7 @@ fun ChannelTree(
currentChannel: Int, currentChannel: Int,
onToggle: (ChannelItem) -> Unit, onToggle: (ChannelItem) -> Unit,
onChannel: (ChannelItem) -> Unit, onChannel: (ChannelItem) -> Unit,
onChannelDoubleTap: (ChannelItem) -> Unit,
onClient: (ClientItem) -> Unit, onClient: (ClientItem) -> Unit,
onServer: () -> Unit, onServer: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
@@ -207,7 +209,7 @@ fun ChannelTree(
}, },
) )
when (row) { when (row) {
is TreeRow.Channel -> ChannelRow(row, background, onToggle, onChannel) is TreeRow.Channel -> ChannelRow(row, background, onToggle, onChannel, onChannelDoubleTap)
is TreeRow.Client -> ClientRow(row, tree.countryFlags, background, onClient) is TreeRow.Client -> ClientRow(row, tree.countryFlags, background, onClient)
} }
} }
@@ -234,6 +236,7 @@ private fun RowLayout(
depth: Int, depth: Int,
onClick: (() -> Unit)?, onClick: (() -> Unit)?,
background: Color = Color.Transparent, background: Color = Color.Transparent,
onDoubleClick: (() -> Unit)? = null,
content: @Composable RowScope.() -> Unit, content: @Composable RowScope.() -> Unit,
) { ) {
Row( Row(
@@ -241,7 +244,7 @@ private fun RowLayout(
.fillMaxWidth() .fillMaxWidth()
.background(background) .background(background)
.height(ROW) .height(ROW)
.then(if (onClick != null) Modifier.clickable(onClick = onClick) else Modifier) .then(if (onClick != null) Modifier.combinedClickable(onDoubleClick = onDoubleClick, onClick = onClick) else Modifier)
.padding(start = 4.dp + INDENT * depth, end = 8.dp), .padding(start = 4.dp + INDENT * depth, end = 8.dp),
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(4.dp), horizontalArrangement = Arrangement.spacedBy(4.dp),
@@ -251,10 +254,17 @@ private fun RowLayout(
} }
@Composable @Composable
private fun ChannelRow(row: TreeRow.Channel, background: Color, onToggle: (ChannelItem) -> Unit, onChannel: (ChannelItem) -> Unit) { private fun ChannelRow(
row: TreeRow.Channel,
background: Color,
onToggle: (ChannelItem) -> Unit,
onChannel: (ChannelItem) -> Unit,
onDoubleTap: (ChannelItem) -> Unit,
) {
val channel = row.channel val channel = row.channel
val spacer = channel.spacer val spacer = channel.spacer
RowLayout(row.depth, onClick = { onChannel(channel) }, background = background) { RowLayout(row.depth, onClick = { onChannel(channel) }, background = background,
onDoubleClick = if (spacer == null) ({ onDoubleTap(channel) }) else null) {
Box( Box(
Modifier.fillMaxHeight().width(ICON + 4.dp) Modifier.fillMaxHeight().width(ICON + 4.dp)
.then(if (row.expandable) Modifier.clickable { onToggle(channel) } else Modifier), .then(if (row.expandable) Modifier.clickable { onToggle(channel) } else Modifier),
@@ -68,6 +68,7 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.LifecycleResumeEffect import androidx.lifecycle.compose.LifecycleResumeEffect
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.ts3client.android.ChannelItem
import com.ts3client.android.ChatKey import com.ts3client.android.ChatKey
import com.ts3client.android.ChatMatch import com.ts3client.android.ChatMatch
import com.ts3client.android.ServerController import com.ts3client.android.ServerController
@@ -123,6 +124,11 @@ fun ServerScreen(
/** A row to show in the tree. */ /** A row to show in the tree. */
var reveal by remember { mutableStateOf<TreeRef?>(null) } var reveal by remember { mutableStateOf<TreeRef?>(null) }
var channelSheet by remember { mutableStateOf<Int?>(null) } var channelSheet by remember { mutableStateOf<Int?>(null) }
/** A locked channel being joined, while its password is asked for. */
var joinLocked by remember { mutableStateOf<Int?>(null) }
val join = { channel: ChannelItem ->
if (channel.locked) joinLocked = channel.id else server.joinChannel(channel.id)
}
var serverSheet by remember { mutableStateOf(false) } var serverSheet by remember { mutableStateOf(false) }
var banList by rememberSaveable { mutableStateOf(false) } var banList by rememberSaveable { mutableStateOf(false) }
var connectionInfo by rememberSaveable { mutableStateOf<Int?>(null) } var connectionInfo by rememberSaveable { mutableStateOf<Int?>(null) }
@@ -276,6 +282,14 @@ fun ServerScreen(
else -> channelSheet = channel.id else -> channelSheet = channel.id
} }
}, },
onChannelDoubleTap = { channel ->
val client = moving
when {
client != null -> { server.moveClient(client, channel.id); moving = null }
channel.id == state.channelId -> {}
else -> join(channel)
}
},
onClient = { clientSheet = it.id; clientSheetFromTree = true }, onClient = { clientSheet = it.id; clientSheetFromTree = true },
onServer = { serverSheet = true }, onServer = { serverSheet = true },
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
@@ -358,11 +372,21 @@ fun ServerScreen(
onLink = onLink, onLink = onLink,
current = id == state.channelId, current = id == state.channelId,
onDismiss = { channelSheet = null }, onDismiss = { channelSheet = null },
onJoin = { server.joinChannel(id, it); channelSheet = null }, onJoin = { join(channel); channelSheet = null },
onSubscribe = { server.setSubscribed(id, it); channelSheet = null }, onSubscribe = { server.setSubscribed(id, it); channelSheet = null },
) )
} }
} }
joinLocked?.let { id ->
TextPrompt(
title = "Join ${tree.channel(id)?.name.orEmpty()}",
label = "Channel password",
confirm = "Join",
password = true,
onDismiss = { joinLocked = null },
onConfirm = { joinLocked = null; server.joinChannel(id, it) },
)
}
if (serverSheet) { if (serverSheet) {
remember(tree, infoUpdates) { server.serverDetails() }?.let { remember(tree, infoUpdates) { server.serverDetails() }?.let {
ServerSheet(it, onLink, onDismiss = { serverSheet = false }, ServerSheet(it, onLink, onDismiss = { serverSheet = false },
@@ -138,19 +138,16 @@ fun ChannelSheet(
onLink: (String) -> Unit, onLink: (String) -> Unit,
current: Boolean, current: Boolean,
onDismiss: () -> Unit, onDismiss: () -> Unit,
onJoin: (String?) -> Unit, onJoin: () -> Unit,
onSubscribe: (Boolean) -> Unit, onSubscribe: (Boolean) -> Unit,
) { ) {
var askPassword by remember { mutableStateOf(false) }
ModalBottomSheet(onDismissRequest = onDismiss) { ModalBottomSheet(onDismissRequest = onDismiss) {
Column(Modifier.verticalScroll(rememberScrollState()).navigationBarsPadding().padding(bottom = 16.dp)) { Column(Modifier.verticalScroll(rememberScrollState()).navigationBarsPadding().padding(bottom = 16.dp)) {
Text(channel.name, Modifier.padding(horizontal = 24.dp, vertical = 8.dp), Text(channel.name, Modifier.padding(horizontal = 24.dp, vertical = 8.dp),
style = MaterialTheme.typography.titleLarge) style = MaterialTheme.typography.titleLarge)
details?.let { DetailsSection(it, onLink, Modifier.padding(bottom = 8.dp)) } details?.let { DetailsSection(it, onLink, Modifier.padding(bottom = 8.dp)) }
if (!current) { if (!current) {
Action("CHANNEL_SWITCH", "Join") { Action("CHANNEL_SWITCH", "Join", onClick = onJoin)
if (channel.locked) askPassword = true else onJoin(null)
}
} }
if (channel.subscribed) { if (channel.subscribed) {
Action("UNSUBSCRIBE_FROM_CHANNEL", "Unsubscribe") { onSubscribe(false) } Action("UNSUBSCRIBE_FROM_CHANNEL", "Unsubscribe") { onSubscribe(false) }
@@ -159,16 +156,6 @@ fun ChannelSheet(
} }
} }
} }
if (askPassword) {
TextPrompt(
title = "Join ${channel.name}",
label = "Channel password",
confirm = "Join",
password = true,
onDismiss = { askPassword = false },
onConfirm = { askPassword = false; onJoin(it) },
)
}
} }
/** The server's details: its version, who is on it, its welcome message. */ /** The server's details: its version, who is on it, its welcome message. */