From 455fc514f5fcf55cada4b0262df016c3249dd4ac Mon Sep 17 00:00:00 2001 From: ericek111 Date: Sat, 10 Oct 2026 15:26:10 +0000 Subject: [PATCH] myTeamSpeak: account items under Identities and Bookmarks The items the account synchronises are listed in an Identities and a Bookmarks section, each with a Select all / Deselect all button on its heading line, on desktop and Android. The desktop tables drop the Type column and name the details column Nickname or Address. FormPanel.sectionHeader and addSection take an optional trailing component. Co-Authored-By: Claude Opus 5.5 --- .../client/android/ui/MyTeamSpeakScreen.kt | 37 +++++--- .../eu/lixko/ts3j/client/ui/FormPanel.java | 19 ++++- .../ts3j/client/ui/MyTeamSpeakPanel.java | 84 ++++++++++++++----- 3 files changed, 109 insertions(+), 31 deletions(-) diff --git a/android/app/src/main/java/eu/lixko/ts3j/client/android/ui/MyTeamSpeakScreen.kt b/android/app/src/main/java/eu/lixko/ts3j/client/android/ui/MyTeamSpeakScreen.kt index da73fac..263c026 100644 --- a/android/app/src/main/java/eu/lixko/ts3j/client/android/ui/MyTeamSpeakScreen.kt +++ b/android/app/src/main/java/eu/lixko/ts3j/client/android/ui/MyTeamSpeakScreen.kt @@ -27,6 +27,7 @@ import androidx.compose.material3.OutlinedButton import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Scaffold import androidx.compose.material3.Text +import androidx.compose.material3.TextButton import androidx.compose.material3.TopAppBar import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -184,15 +185,31 @@ fun MyTeamSpeakScreen(vm: SessionController, onBack: () -> Unit) { style = MaterialTheme.typography.titleSmall, color = MaterialTheme.colorScheme.primary) } } - items(rows, key = { it.item.uuid() }) { row -> - val toggle = { rows = rows.map { if (it === row) it.copy(selected = !it.selected) else it } } - ListItem( - headlineContent = { Text(name(row.item), maxLines = 1, overflow = TextOverflow.Ellipsis) }, - supportingContent = { Text(details(row.item), maxLines = 1, overflow = TextOverflow.Ellipsis) }, - leadingContent = { Checkbox(row.selected, { toggle() }) }, - trailingContent = if (row.imported) ({ Text("Imported", style = MaterialTheme.typography.labelMedium) }) else null, - modifier = Modifier.clickable(onClick = toggle), - ) + for ((title, section) in listOf( + "Identities" to rows.filter { it.item is SyncItem.Identity }, + "Bookmarks" to rows.filter { it.item is SyncItem.Bookmark }, + )) { + if (section.isEmpty()) continue + item { + val select = section.any { !it.selected } + Row(Modifier.padding(start = 16.dp, top = 8.dp, end = 8.dp), verticalAlignment = Alignment.CenterVertically) { + Text(title, Modifier.weight(1f), + style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.onSurfaceVariant) + TextButton(onClick = { + rows = rows.map { if (it in section) it.copy(selected = select) else it } + }) { Text(if (select) "Select all" else "Deselect all") } + } + } + items(section, key = { it.item.uuid() }) { row -> + val toggle = { rows = rows.map { if (it === row) it.copy(selected = !it.selected) else it } } + ListItem( + headlineContent = { Text(name(row.item), maxLines = 1, overflow = TextOverflow.Ellipsis) }, + supportingContent = { Text(details(row.item), maxLines = 1, overflow = TextOverflow.Ellipsis) }, + leadingContent = { Checkbox(row.selected, { toggle() }) }, + trailingContent = if (row.imported) ({ Text("Imported", style = MaterialTheme.typography.labelMedium) }) else null, + modifier = Modifier.clickable(onClick = toggle), + ) + } } if (rows.isNotEmpty()) { item { @@ -234,7 +251,7 @@ private fun Detail(label: String, value: String) { private fun name(item: SyncItem) = when (item) { is SyncItem.Bookmark -> item.name().ifBlank { item.address() } - is SyncItem.Identity -> "Identity: ${item.name()}" + is SyncItem.Identity -> item.name() else -> "" } diff --git a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/FormPanel.java b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/FormPanel.java index 9c843b9..b451745 100644 --- a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/FormPanel.java +++ b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/FormPanel.java @@ -75,6 +75,11 @@ class FormPanel extends JPanel implements Scrollable { /** A group heading: the title in bold, followed by a rule to the right edge. */ static JComponent sectionHeader(String title) { + return sectionHeader(title, null); + } + + /** A {@link #sectionHeader(String)} with {@code trailing}, such as a button, after the rule. */ + static JComponent sectionHeader(String title, Component trailing) { JPanel header = new JPanel(new GridBagLayout()); JLabel label = new JLabel(title) { @Override @@ -91,6 +96,13 @@ class FormPanel extends JPanel implements Scrollable { c.fill = GridBagConstraints.HORIZONTAL; c.insets = new Insets(0, 0, 0, 0); header.add(new JSeparator(), c); + if (trailing != null) { + c.gridx = 2; + c.weightx = 0; + c.fill = GridBagConstraints.NONE; + c.insets = UIScale.scale(new Insets(0, 8, 0, 0)); + header.add(trailing, c); + } return header; } @@ -99,6 +111,11 @@ class FormPanel extends JPanel implements Scrollable { * unless it is the first row; leaves {@code c} as it found it. */ static void addSection(JPanel p, GridBagConstraints c, int row, String title) { + addSection(p, c, row, title, null); + } + + /** {@link #addSection(JPanel, GridBagConstraints, int, String)} with a {@code trailing} component. */ + static void addSection(JPanel p, GridBagConstraints c, int row, String title, Component trailing) { Insets insets = c.insets; int width = c.gridwidth; c.gridx = 0; @@ -106,7 +123,7 @@ class FormPanel extends JPanel implements Scrollable { c.gridwidth = 2; c.weightx = 0; c.insets = UIScale.scale(new Insets(row == 0 ? 0 : 14, 0, 2, 0)); - p.add(sectionHeader(title), c); + p.add(sectionHeader(title, trailing), c); c.insets = insets; c.gridwidth = width; } diff --git a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/MyTeamSpeakPanel.java b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/MyTeamSpeakPanel.java index b1941dc..23b8216 100644 --- a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/MyTeamSpeakPanel.java +++ b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/MyTeamSpeakPanel.java @@ -31,6 +31,7 @@ import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; import java.util.ArrayList; import java.util.List; +import java.util.stream.Stream; /** * Options page for the myTeamSpeak account: sign in and out, and see what the @@ -57,7 +58,9 @@ final class MyTeamSpeakPanel extends JPanel { private final JLabel account = new JLabel(); private final JPanel details = new JPanel(new GridBagLayout()); - private final ItemTable items = new ItemTable(); + private final ItemTable identities = new ItemTable("Nickname"); + private final ItemTable bookmarks = new ItemTable("Address"); + private final FormPanel sections = new FormPanel(false); private final JButton refresh = new JButton("Refresh"); private final JButton importButton = new JButton("Import selected"); private final JLabel dataStatus = new JLabel(" "); @@ -133,7 +136,7 @@ final class MyTeamSpeakPanel extends JPanel { JPanel data = new JPanel(new BorderLayout(0, UIScale.scale(4))); data.add(new JLabel("Synchronised by the account:"), BorderLayout.NORTH); - data.add(new JScrollPane(items.table), BorderLayout.CENTER); + data.add(new JScrollPane(sections), BorderLayout.CENTER); data.add(buttons, BorderLayout.SOUTH); JPanel panel = new JPanel(new BorderLayout(0, UIScale.scale(12))); @@ -181,7 +184,7 @@ final class MyTeamSpeakPanel extends JPanel { login.signOut(); accountItems = List.of(); details.removeAll(); - items.set(List.of()); + setRows(List.of()); fetched = false; email.setText(""); showState(); @@ -244,13 +247,13 @@ final class MyTeamSpeakPanel extends JPanel { boolean present = importer.isPresent(item); rows.add(new Row(item, present, !present)); } - items.set(rows); + setRows(rows); status(dataStatus, rows.isEmpty() ? "The account holds no bookmarks or identities." : " ", false); updateImportButton(); } private void importSelected() { - List chosen = items.rows.stream().filter(Row::selected).map(Row::item).toList(); + List chosen = allRows().filter(Row::selected).map(Row::item).toList(); if (chosen.isEmpty()) return; try { TeamSpeakImporter.Result r = importer.importSelected(accountItems, chosen); @@ -261,8 +264,8 @@ final class MyTeamSpeakPanel extends JPanel { status(dataStatus, "Could not import: " + e.getMessage(), true); } List rows = new ArrayList<>(); - for (Row row : items.rows) rows.add(new Row(row.item(), importer.isPresent(row.item()), false)); - items.set(rows); + allRows().forEach(row -> rows.add(new Row(row.item(), importer.isPresent(row.item()), false))); + setRows(rows); updateImportButton(); } @@ -296,7 +299,34 @@ final class MyTeamSpeakPanel extends JPanel { } private void updateImportButton() { - importButton.setEnabled(refresh.isEnabled() && items.rows.stream().anyMatch(Row::selected)); + importButton.setEnabled(refresh.isEnabled() && allRows().anyMatch(Row::selected)); + } + + private Stream allRows() { + return Stream.concat(identities.rows.stream(), bookmarks.rows.stream()); + } + + /** Splits the rows into the Identities and Bookmarks sections, leaving out an empty one. */ + private void setRows(List rows) { + identities.set(rows.stream().filter(r -> r.item() instanceof SyncItem.Identity).toList()); + bookmarks.set(rows.stream().filter(r -> r.item() instanceof SyncItem.Bookmark).toList()); + sections.removeAll(); + GridBagConstraints c = FormPanel.gbc(); + int row = 0; + if (!identities.rows.isEmpty()) row = addSection(c, row, "Identities", identities); + if (!bookmarks.rows.isEmpty()) row = addSection(c, row, "Bookmarks", bookmarks); + FormPanel.addFiller(sections, c, row); + sections.revalidate(); + sections.repaint(); + } + + private int addSection(GridBagConstraints c, int row, String title, ItemTable items) { + FormPanel.addSection(sections, c, row++, title, items.selectAll); + JPanel table = new JPanel(new BorderLayout()); + table.add(items.table.getTableHeader(), BorderLayout.NORTH); + table.add(items.table, BorderLayout.CENTER); + FormPanel.addWide(sections, c, row++, table); + return row; } private static void status(JLabel label, String text, boolean error) { @@ -318,22 +348,36 @@ final class MyTeamSpeakPanel extends JPanel { /** The account's items, each with a box to pick it for importing and whether it is here already. */ private final class ItemTable extends AbstractTableModel { - private static final String[] COLUMNS = {"", "Type", "Name", "Details", "Imported"}; - - final JTable table = new JTable(this); + private final String[] columns; + final JTable table; + final JButton selectAll = new JButton(); List rows = List.of(); - ItemTable() { - table.setFillsViewportHeight(true); + ItemTable(String detailsColumn) { + columns = new String[] {"", "Name", detailsColumn, "Imported"}; + table = new JTable(this); + selectAll.addActionListener(e -> { + boolean select = !allSelected(); + set(rows.stream().map(r -> new Row(r.item(), r.present(), select)).toList()); + updateImportButton(); + }); table.getTableHeader().setReorderingAllowed(false); table.getColumnModel().getColumn(0).setMaxWidth(UIScale.scale(28)); - table.getColumnModel().getColumn(1).setPreferredWidth(UIScale.scale(60)); - table.getColumnModel().getColumn(4).setPreferredWidth(UIScale.scale(60)); + table.getColumnModel().getColumn(3).setPreferredWidth(UIScale.scale(60)); } void set(List rows) { this.rows = rows; fireTableDataChanged(); + updateSelectAll(); + } + + private boolean allSelected() { + return rows.stream().allMatch(Row::selected); + } + + private void updateSelectAll() { + selectAll.setText(allSelected() ? "Deselect all" : "Select all"); } @Override @@ -343,12 +387,12 @@ final class MyTeamSpeakPanel extends JPanel { @Override public int getColumnCount() { - return COLUMNS.length; + return columns.length; } @Override public String getColumnName(int column) { - return COLUMNS[column]; + return columns[column]; } @Override @@ -366,13 +410,12 @@ final class MyTeamSpeakPanel extends JPanel { Row r = rows.get(row); return switch (column) { case 0 -> r.selected(); - case 1 -> r.item() instanceof SyncItem.Bookmark ? "Bookmark" : "Identity"; - case 2 -> switch (r.item()) { + case 1 -> switch (r.item()) { case SyncItem.Bookmark b -> b.name(); case SyncItem.Identity i -> i.name(); default -> ""; }; - case 3 -> switch (r.item()) { + case 2 -> switch (r.item()) { case SyncItem.Bookmark b -> b.address() + ":" + b.port(); case SyncItem.Identity i -> i.nickname(); default -> ""; @@ -388,6 +431,7 @@ final class MyTeamSpeakPanel extends JPanel { updated.set(row, new Row(r.item(), r.present(), Boolean.TRUE.equals(value))); rows = updated; fireTableRowsUpdated(row, row); + updateSelectAll(); updateImportButton(); } }