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:
@@ -13,6 +13,7 @@ import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
@@ -139,6 +140,7 @@ fun ChannelTree(
|
||||
currentChannel: Int,
|
||||
onToggle: (ChannelItem) -> Unit,
|
||||
onChannel: (ChannelItem) -> Unit,
|
||||
onChannelDoubleTap: (ChannelItem) -> Unit,
|
||||
onClient: (ClientItem) -> Unit,
|
||||
onServer: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
@@ -207,7 +209,7 @@ fun ChannelTree(
|
||||
},
|
||||
)
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -234,6 +236,7 @@ private fun RowLayout(
|
||||
depth: Int,
|
||||
onClick: (() -> Unit)?,
|
||||
background: Color = Color.Transparent,
|
||||
onDoubleClick: (() -> Unit)? = null,
|
||||
content: @Composable RowScope.() -> Unit,
|
||||
) {
|
||||
Row(
|
||||
@@ -241,7 +244,7 @@ private fun RowLayout(
|
||||
.fillMaxWidth()
|
||||
.background(background)
|
||||
.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),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
@@ -251,10 +254,17 @@ private fun RowLayout(
|
||||
}
|
||||
|
||||
@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 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(
|
||||
Modifier.fillMaxHeight().width(ICON + 4.dp)
|
||||
.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.lifecycle.compose.LifecycleResumeEffect
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.ts3client.android.ChannelItem
|
||||
import com.ts3client.android.ChatKey
|
||||
import com.ts3client.android.ChatMatch
|
||||
import com.ts3client.android.ServerController
|
||||
@@ -123,6 +124,11 @@ fun ServerScreen(
|
||||
/** A row to show in the tree. */
|
||||
var reveal by remember { mutableStateOf<TreeRef?>(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 banList by rememberSaveable { mutableStateOf(false) }
|
||||
var connectionInfo by rememberSaveable { mutableStateOf<Int?>(null) }
|
||||
@@ -276,6 +282,14 @@ fun ServerScreen(
|
||||
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 },
|
||||
onServer = { serverSheet = true },
|
||||
modifier = Modifier.weight(1f),
|
||||
@@ -358,11 +372,21 @@ fun ServerScreen(
|
||||
onLink = onLink,
|
||||
current = id == state.channelId,
|
||||
onDismiss = { channelSheet = null },
|
||||
onJoin = { server.joinChannel(id, it); channelSheet = null },
|
||||
onJoin = { join(channel); 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) {
|
||||
remember(tree, infoUpdates) { server.serverDetails() }?.let {
|
||||
ServerSheet(it, onLink, onDismiss = { serverSheet = false },
|
||||
|
||||
@@ -138,19 +138,16 @@ fun ChannelSheet(
|
||||
onLink: (String) -> Unit,
|
||||
current: Boolean,
|
||||
onDismiss: () -> Unit,
|
||||
onJoin: (String?) -> Unit,
|
||||
onJoin: () -> Unit,
|
||||
onSubscribe: (Boolean) -> Unit,
|
||||
) {
|
||||
var askPassword by remember { mutableStateOf(false) }
|
||||
ModalBottomSheet(onDismissRequest = onDismiss) {
|
||||
Column(Modifier.verticalScroll(rememberScrollState()).navigationBarsPadding().padding(bottom = 16.dp)) {
|
||||
Text(channel.name, Modifier.padding(horizontal = 24.dp, vertical = 8.dp),
|
||||
style = MaterialTheme.typography.titleLarge)
|
||||
details?.let { DetailsSection(it, onLink, Modifier.padding(bottom = 8.dp)) }
|
||||
if (!current) {
|
||||
Action("CHANNEL_SWITCH", "Join") {
|
||||
if (channel.locked) askPassword = true else onJoin(null)
|
||||
}
|
||||
Action("CHANNEL_SWITCH", "Join", onClick = onJoin)
|
||||
}
|
||||
if (channel.subscribed) {
|
||||
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. */
|
||||
|
||||
Reference in New Issue
Block a user