Rebuild Connection Info after the official dialog

Lay the window out as TeamSpeak 3's: name, times, ping and address
(with a copy button) beside the avatar, then Total / Speech / Keep Alive
/ Control tabs holding a Total / In / Out table, and a Quota tab. Android
gets the same tabs and table.

Wait for both notifyconnectioninfo reports for another client (the
server's cached copy, then the client's fresh counters) instead of
taking the first, often all zeros. Ask the server about ourselves too,
for our address and outgoing loss. Month transfer totals come from
clientgetvariables, our quota from the needed permissions, and file
transfers now count their bytes for our own transfer rate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 20:59:44 +00:00
co-authored by Claude Opus 5.5
parent 70aac6f5ce
commit 33317df2eb
11 changed files with 713 additions and 467 deletions
@@ -1,32 +1,54 @@
package com.ts3client.android.ui
import android.content.ClipData
import android.content.ClipboardManager
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.PrimaryScrollableTabRow
import androidx.compose.material3.Tab
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.ts3client.android.ClientItem
import com.ts3client.android.ServerController
import com.ts3client.net.ConnectionStats
import com.ts3client.net.ConnectionStatsFormat
import kotlinx.coroutines.delay
private const val REFRESH_MS = 1000L
private const val SELF_ADDRESS = "This device"
/** A client's connection figures, read again every second while shown, and what our playback made of their voice. */
private val TABS = ConnectionStatsFormat.TRAFFIC_TABS.map { it.title() } +
listOf(ConnectionStatsFormat.QUOTA_TAB, ConnectionStatsFormat.VOICE_TAB)
/**
* A client's connection figures, read again every second while shown, laid out as TeamSpeak's
* Connection Info window: name, times, ping and address beside the avatar, then a tab per
* traffic category with Total / In / Out columns, Quota, and what our playback made of their voice.
*/
@Composable
fun ConnectionInfoScreen(server: ServerController, clientId: Int, nickname: String, onBack: () -> Unit) {
fun ConnectionInfoScreen(server: ServerController, clientId: Int, client: ClientItem?, onBack: () -> Unit) {
var stats by remember { mutableStateOf<ConnectionStats?>(null) }
LaunchedEffect(clientId) {
while (true) {
@@ -34,35 +56,95 @@ fun ConnectionInfoScreen(server: ServerController, clientId: Int, nickname: Stri
delay(REFRESH_MS)
}
}
var tab by rememberSaveable { mutableIntStateOf(0) }
val s = stats
SubScreen("Connection info", onBack) { padding ->
Column(Modifier.padding(padding).verticalScroll(rememberScrollState()).padding(bottom = 16.dp)) {
Text(nickname, Modifier.padding(horizontal = 16.dp, vertical = 8.dp), style = MaterialTheme.typography.titleLarge)
Figures(ConnectionStatsFormat.summaryRows(s, SELF_ADDRESS))
Section("Voice received")
Figures(ConnectionStatsFormat.voiceRows(s?.voiceReceived))
Section("Total")
Figures(ConnectionStatsFormat.trafficRows(s, null))
for ((kind, title) in KINDS) {
Section(title)
Figures(ConnectionStatsFormat.trafficRows(s, kind))
Row(Modifier.padding(horizontal = 16.dp, vertical = 8.dp)) {
Summary(s, client?.nickname ?: "", Modifier.weight(1f))
if (client != null && client.avatarFlag.isNotEmpty()) {
Avatar(client.uniqueId, client.avatarFlag, Modifier.padding(start = 12.dp), size = 72.dp)
}
}
PrimaryScrollableTabRow(selectedTabIndex = tab, edgePadding = 8.dp) {
TABS.forEachIndexed { i, title -> Tab(tab == i, onClick = { tab = i }, text = { Text(title) }) }
}
val traffic = ConnectionStatsFormat.TRAFFIC_TABS
Column(Modifier.padding(horizontal = 16.dp, vertical = 8.dp)) {
when {
tab < traffic.size -> TrafficTable(ConnectionStatsFormat.trafficRows(s, traffic[tab].kind()))
tab == traffic.size -> Figures(ConnectionStatsFormat.quotaGroups(s))
else -> Figures(listOf(ConnectionStatsFormat.voiceRows(s?.voiceReceived)))
}
}
}
}
}
private val KINDS = listOf(
ConnectionStats.Kind.SPEECH to "Speech",
ConnectionStats.Kind.KEEPALIVE to "Keep alive",
ConnectionStats.Kind.CONTROL to "Control",
)
@Composable
private fun Figures(rows: List<ConnectionStatsFormat.Row>) {
for (row in rows) {
Row(Modifier.padding(horizontal = 16.dp, vertical = 4.dp)) {
Text(row.label, Modifier.weight(1f), color = MaterialTheme.colorScheme.onSurfaceVariant)
Text(row.value, Modifier.weight(1f), textAlign = TextAlign.End)
private fun Summary(s: ConnectionStats?, nickname: String, modifier: Modifier) {
val context = LocalContext.current
val address = ConnectionStatsFormat.copyableAddress(s)
val rows = ConnectionStatsFormat.summaryRows(s, nickname)
Column(modifier) {
rows.forEachIndexed { i, row ->
Row(Modifier.heightIn(min = 32.dp), verticalAlignment = Alignment.CenterVertically) {
Text(row.label, Modifier.weight(1f), color = MaterialTheme.colorScheme.onSurfaceVariant)
Text(row.value, textAlign = TextAlign.End)
if (i == rows.lastIndex) {
IconButton(
onClick = {
// The system confirms the copy itself.
context.getSystemService(ClipboardManager::class.java)
.setPrimaryClip(ClipData.newPlainText("Client address", address))
},
enabled = address != null,
modifier = Modifier.size(32.dp),
) { PackIcon("COPY", "Copy client address", size = 18.dp) }
}
}
}
}
}
/** Labelled figures in groups set apart by a rule. */
@Composable
private fun Figures(groups: List<List<ConnectionStatsFormat.Row>>) {
groups.forEachIndexed { g, rows ->
if (g > 0) HorizontalDivider(Modifier.padding(vertical = 8.dp))
for (row in rows) {
Row(Modifier.padding(vertical = 4.dp)) {
Text(row.label, Modifier.weight(1f), color = MaterialTheme.colorScheme.onSurfaceVariant)
Text(row.value, textAlign = TextAlign.End)
}
}
}
}
@Composable
private fun TrafficTable(rows: List<ConnectionStatsFormat.TrafficRow>) {
Row(Modifier.padding(vertical = 4.dp), horizontalArrangement = Arrangement.spacedBy(4.dp)) {
LabelCell("")
ConnectionStatsFormat.COLUMNS.forEachIndexed { i, column -> ValueCell(column, i == 0, FontStyle.Italic) }
}
for (row in rows) {
Row(Modifier.padding(vertical = 4.dp), horizontalArrangement = Arrangement.spacedBy(4.dp),
verticalAlignment = Alignment.CenterVertically) {
LabelCell(row.label)
ValueCell(row.total, narrow = true)
ValueCell(row.`in`)
ValueCell(row.out)
}
}
}
@Composable
private fun RowScope.LabelCell(text: String) =
Text(text, Modifier.weight(1.5f), color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodySmall)
/** The Total column only ever holds the loss percentage. */
@Composable
private fun RowScope.ValueCell(text: String, narrow: Boolean = false, fontStyle: FontStyle? = null) =
Text(text, Modifier.weight(if (narrow) 0.7f else 1f), style = MaterialTheme.typography.bodySmall, fontStyle = fontStyle,
textAlign = TextAlign.End)
@@ -209,7 +209,7 @@ fun ServerScreen(
return
}
connectionInfo?.let { id ->
ConnectionInfoScreen(server, id, tree.client(id)?.name ?: "", onBack = { connectionInfo = null })
ConnectionInfoScreen(server, id, tree.client(id), onBack = { connectionInfo = null })
return
}