Colour client rows in the channel tree: for everyone, while talking, while muted or away
Design settings on desktop and Android offer a few see-through presets that suit light and dark themes alike, or a custom colour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -378,7 +378,7 @@ class ServerController internal constructor(
|
||||
treePending.set(false)
|
||||
if (structureChanged.getAndSet(false)) roots = conn.model.buildTree()
|
||||
_tree.value = ServerTree.of(roots, conn.model, conn.contacts, app.settings.colorContacts,
|
||||
app.settings.countryFlags)
|
||||
app.settings.countryFlags, app.settings.clientRowColors)
|
||||
val serverName = if (session.isConnected) conn.model.serverName.orEmpty() else ""
|
||||
val channelName = session.currentChannel()?.name.orEmpty()
|
||||
_chats.update {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.ts3client.android
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import com.ts3client.config.ClientRowColors
|
||||
import com.ts3client.contacts.ContactStore
|
||||
import com.ts3client.contacts.ContactType
|
||||
import com.ts3client.net.ChannelNode
|
||||
@@ -91,14 +92,15 @@ data class ServerTree(
|
||||
|
||||
companion object {
|
||||
fun of(roots: List<ChannelNode>, model: ServerModel, contacts: ContactStore, colorContacts: Boolean,
|
||||
countryFlags: Boolean): ServerTree =
|
||||
countryFlags: Boolean, rowColors: ClientRowColors): ServerTree =
|
||||
ServerTree(
|
||||
roots.map { channel(it, model, contacts, colorContacts) },
|
||||
roots.map { channel(it, model, contacts, colorContacts, rowColors) },
|
||||
model.serverIconId(),
|
||||
countryFlags,
|
||||
)
|
||||
|
||||
private fun channel(c: ChannelNode, model: ServerModel, contacts: ContactStore, colorContacts: Boolean): ChannelItem {
|
||||
private fun channel(c: ChannelNode, model: ServerModel, contacts: ContactStore, colorContacts: Boolean,
|
||||
rowColors: ClientRowColors): ChannelItem {
|
||||
val clients = c.clients
|
||||
val spacer = Spacers.parse(c.name)
|
||||
return ChannelItem(
|
||||
@@ -109,21 +111,24 @@ data class ServerTree(
|
||||
locked = c.hasPassword,
|
||||
full = c.maxClients >= 0 && clients.size >= c.maxClients,
|
||||
subscribed = c.subscribed,
|
||||
clients = clients.map { client(it, model, contacts, colorContacts) },
|
||||
children = c.children.map { channel(it, model, contacts, colorContacts) },
|
||||
clients = clients.map { client(it, model, contacts, colorContacts, rowColors) },
|
||||
children = c.children.map { channel(it, model, contacts, colorContacts, rowColors) },
|
||||
)
|
||||
}
|
||||
|
||||
private fun client(c: ClientEntry, model: ServerModel, contacts: ContactStore, colorContacts: Boolean): ClientItem {
|
||||
private fun client(c: ClientEntry, model: ServerModel, contacts: ContactStore, colorContacts: Boolean,
|
||||
rowColors: ClientRowColors): ClientItem {
|
||||
val contact = contacts.find(c.uniqueId)
|
||||
val away = c.away && c.awayMessage.isNotEmpty() && contact?.ignoreAwayMessage != true
|
||||
val status = ClientStatus.of(c)
|
||||
return ClientItem(
|
||||
id = c.id,
|
||||
uniqueId = c.uniqueId,
|
||||
nickname = c.nickname ?: "",
|
||||
name = contact?.displayName(c.nickname) ?: c.nickname ?: "",
|
||||
awayMessage = if (away) c.awayMessage else "",
|
||||
status = ClientStatus.of(c),
|
||||
status = status,
|
||||
background = rowColors.of(status),
|
||||
self = c.self,
|
||||
contactType = contact?.type,
|
||||
highlight = if (colorContacts) contact?.type ?: ContactType.NEUTRAL else ContactType.NEUTRAL,
|
||||
@@ -169,6 +174,8 @@ data class ClientItem(
|
||||
val name: String,
|
||||
val awayMessage: String,
|
||||
val status: ClientStatus,
|
||||
/** The row's background colour, ARGB; 0 for none. */
|
||||
val background: Int,
|
||||
val self: Boolean,
|
||||
/** How the client is filed in the contacts; null when it is not one. */
|
||||
val contactType: ContactType?,
|
||||
|
||||
@@ -354,6 +354,12 @@ class SessionController(private val context: Context) {
|
||||
servers.value.forEach { it.scheduleTree(structure = false) }
|
||||
}
|
||||
|
||||
/** Puts new client row colours, already set in [settings], into effect. */
|
||||
fun clientRowColorsChanged() {
|
||||
settings.save()
|
||||
servers.value.forEach { it.scheduleTree(structure = false) }
|
||||
}
|
||||
|
||||
fun setDescriptionPictures(shown: Boolean) {
|
||||
settings.descriptionPictures = shown
|
||||
settings.save()
|
||||
|
||||
@@ -236,12 +236,15 @@ private fun RowLayout(
|
||||
depth: Int,
|
||||
onClick: (() -> Unit)?,
|
||||
background: Color = Color.Transparent,
|
||||
/** The colour under [background], which a flash or find match goes over. */
|
||||
tint: Color = Color.Transparent,
|
||||
onDoubleClick: (() -> Unit)? = null,
|
||||
content: @Composable RowScope.() -> Unit,
|
||||
) {
|
||||
Row(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.background(tint)
|
||||
.background(background)
|
||||
.height(ROW)
|
||||
.then(if (onClick != null) Modifier.combinedClickable(onDoubleClick = onDoubleClick, onClick = onClick) else Modifier)
|
||||
@@ -314,7 +317,7 @@ private fun SpacerLabel(align: Char, caption: String, modifier: Modifier) {
|
||||
@Composable
|
||||
private fun ClientRow(row: TreeRow.Client, countryFlags: Boolean, background: Color, onClient: (ClientItem) -> Unit) {
|
||||
val client = row.client
|
||||
RowLayout(row.depth, onClick = { onClient(client) }, background = background) {
|
||||
RowLayout(row.depth, onClick = { onClient(client) }, background = background, tint = Color(client.background)) {
|
||||
Spacer(Modifier.width(ICON + 4.dp))
|
||||
StatusIcon(client.status)
|
||||
Row(Modifier.weight(1f), horizontalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
package com.ts3client.android.ui
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.ts3client.config.ClientRowColors
|
||||
|
||||
/** A row background: none, a preset, or a custom colour. [argb] is 0 for none. */
|
||||
@Composable
|
||||
internal fun RowColorPicker(label: String, argb: Int, onChange: (Int) -> Unit) {
|
||||
var open by remember { mutableStateOf(false) }
|
||||
var custom by remember { mutableStateOf(false) }
|
||||
Box {
|
||||
Row(Modifier.fillMaxWidth().clickable { open = true }.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically) {
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text(label)
|
||||
Text(nameOf(argb), style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
Swatch(argb, 28.dp)
|
||||
}
|
||||
DropdownMenu(open, { open = false }) {
|
||||
DropdownMenuItem({ Text("None") }, leadingIcon = { Swatch(0) }, onClick = {
|
||||
open = false
|
||||
onChange(0)
|
||||
})
|
||||
for (p in ClientRowColors.PRESETS) {
|
||||
DropdownMenuItem({ Text(p.name()) }, leadingIcon = { Swatch(p.argb()) }, onClick = {
|
||||
open = false
|
||||
onChange(p.argb())
|
||||
})
|
||||
}
|
||||
DropdownMenuItem({ Text("Custom…") }, onClick = {
|
||||
open = false
|
||||
custom = true
|
||||
})
|
||||
}
|
||||
}
|
||||
if (custom) {
|
||||
CustomColorDialog(if (argb != 0) argb else 0x59808080, onDismiss = { custom = false }) {
|
||||
custom = false
|
||||
onChange(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun nameOf(argb: Int): String =
|
||||
if (argb == 0) "None" else ClientRowColors.presetOf(argb)?.name() ?: "Custom"
|
||||
|
||||
@Composable
|
||||
private fun CustomColorDialog(initial: Int, onDismiss: () -> Unit, onPick: (Int) -> Unit) {
|
||||
var alpha by remember { mutableIntStateOf(initial ushr 24) }
|
||||
var red by remember { mutableIntStateOf(initial shr 16 and 0xFF) }
|
||||
var green by remember { mutableIntStateOf(initial shr 8 and 0xFF) }
|
||||
var blue by remember { mutableIntStateOf(initial and 0xFF) }
|
||||
val argb = (alpha shl 24) or (red shl 16) or (green shl 8) or blue
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text("Custom colour") },
|
||||
text = {
|
||||
Column {
|
||||
Box(Modifier.fillMaxWidth().height(40.dp).clip(RoundedCornerShape(6.dp))
|
||||
.background(MaterialTheme.colorScheme.surface)) {
|
||||
Box(Modifier.fillMaxWidth().height(40.dp).background(Color(argb)))
|
||||
}
|
||||
Channel("Red", red) { red = it }
|
||||
Channel("Green", green) { green = it }
|
||||
Channel("Blue", blue) { blue = it }
|
||||
Channel("Opacity", alpha) { alpha = it }
|
||||
}
|
||||
},
|
||||
confirmButton = { TextButton({ onPick(argb) }, enabled = argb != 0) { Text("OK") } },
|
||||
dismissButton = { TextButton(onDismiss) { Text("Cancel") } },
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Channel(label: String, value: Int, onChange: (Int) -> Unit) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(label, Modifier.width(64.dp), style = MaterialTheme.typography.bodySmall)
|
||||
Slider(value.toFloat(), { onChange(it.toInt()) }, Modifier.weight(1f), valueRange = 0f..255f)
|
||||
}
|
||||
}
|
||||
|
||||
/** The colour over the screen's background, as a row would show it; outlined so "none" shows too. */
|
||||
@Composable
|
||||
private fun Swatch(argb: Int, size: Dp = 20.dp) {
|
||||
val shape = RoundedCornerShape(4.dp)
|
||||
Box(Modifier.size(size).clip(shape).background(MaterialTheme.colorScheme.surface).background(Color(argb))
|
||||
.border(1.dp, MaterialTheme.colorScheme.outline, shape))
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
@@ -52,7 +53,7 @@ fun SettingsScreen(vm: SessionController, onContacts: () -> Unit, onBack: () ->
|
||||
LinkRow("Giant PTT", "A push-to-talk button filling the screen", "CAPTURE") {
|
||||
page = SettingsPage.GIANT_PTT
|
||||
}
|
||||
LinkRow("Design", "Icon pack, country flags, description pictures", "GUISETUP") {
|
||||
LinkRow("Design", "Icon pack, country flags, client colours, description pictures", "GUISETUP") {
|
||||
page = SettingsPage.DESIGN
|
||||
}
|
||||
LinkRow("Identities", "Create, import, export, security level",
|
||||
@@ -70,15 +71,35 @@ private fun DesignScreen(vm: SessionController, onBack: () -> Unit) {
|
||||
SubScreen("Design", onBack) { padding ->
|
||||
Column(Modifier.padding(padding).verticalScroll(rememberScrollState())) {
|
||||
IconPackPicker(vm.icons)
|
||||
var pictures by remember { mutableStateOf(vm.settings.descriptionPictures) }
|
||||
Toggle("Show pictures in descriptions", pictures) {
|
||||
pictures = it
|
||||
vm.setDescriptionPictures(it)
|
||||
}
|
||||
Section("Channel tree")
|
||||
var flags by remember { mutableStateOf(vm.settings.countryFlags) }
|
||||
Toggle("Show country flags in the channel tree", flags) {
|
||||
flags = it
|
||||
vm.setCountryFlags(it)
|
||||
}
|
||||
var pictures by remember { mutableStateOf(vm.settings.descriptionPictures) }
|
||||
Toggle("Show pictures in descriptions", pictures) {
|
||||
pictures = it
|
||||
vm.setDescriptionPictures(it)
|
||||
val colors = vm.settings.clientRowColors
|
||||
var any by remember { mutableIntStateOf(colors.any) }
|
||||
var talking by remember { mutableIntStateOf(colors.talking) }
|
||||
var mutedAway by remember { mutableIntStateOf(colors.mutedAway) }
|
||||
RowColorPicker("Client background", any) {
|
||||
any = it
|
||||
colors.any = it
|
||||
vm.clientRowColorsChanged()
|
||||
}
|
||||
RowColorPicker("While talking", talking) {
|
||||
talking = it
|
||||
colors.talking = it
|
||||
vm.clientRowColorsChanged()
|
||||
}
|
||||
RowColorPicker("Muted / away", mutedAway) {
|
||||
mutedAway = it
|
||||
colors.mutedAway = it
|
||||
vm.clientRowColorsChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user