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 <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,7 @@ import androidx.compose.material3.OutlinedButton
|
|||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.material3.TopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
@@ -184,7 +185,22 @@ fun MyTeamSpeakScreen(vm: SessionController, onBack: () -> Unit) {
|
|||||||
style = MaterialTheme.typography.titleSmall, color = MaterialTheme.colorScheme.primary)
|
style = MaterialTheme.typography.titleSmall, color = MaterialTheme.colorScheme.primary)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
items(rows, key = { it.item.uuid() }) { row ->
|
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 } }
|
val toggle = { rows = rows.map { if (it === row) it.copy(selected = !it.selected) else it } }
|
||||||
ListItem(
|
ListItem(
|
||||||
headlineContent = { Text(name(row.item), maxLines = 1, overflow = TextOverflow.Ellipsis) },
|
headlineContent = { Text(name(row.item), maxLines = 1, overflow = TextOverflow.Ellipsis) },
|
||||||
@@ -194,6 +210,7 @@ fun MyTeamSpeakScreen(vm: SessionController, onBack: () -> Unit) {
|
|||||||
modifier = Modifier.clickable(onClick = toggle),
|
modifier = Modifier.clickable(onClick = toggle),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (rows.isNotEmpty()) {
|
if (rows.isNotEmpty()) {
|
||||||
item {
|
item {
|
||||||
Button(
|
Button(
|
||||||
@@ -234,7 +251,7 @@ private fun Detail(label: String, value: String) {
|
|||||||
|
|
||||||
private fun name(item: SyncItem) = when (item) {
|
private fun name(item: SyncItem) = when (item) {
|
||||||
is SyncItem.Bookmark -> item.name().ifBlank { item.address() }
|
is SyncItem.Bookmark -> item.name().ifBlank { item.address() }
|
||||||
is SyncItem.Identity -> "Identity: ${item.name()}"
|
is SyncItem.Identity -> item.name()
|
||||||
else -> ""
|
else -> ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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. */
|
/** A group heading: the title in bold, followed by a rule to the right edge. */
|
||||||
static JComponent sectionHeader(String title) {
|
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());
|
JPanel header = new JPanel(new GridBagLayout());
|
||||||
JLabel label = new JLabel(title) {
|
JLabel label = new JLabel(title) {
|
||||||
@Override
|
@Override
|
||||||
@@ -91,6 +96,13 @@ class FormPanel extends JPanel implements Scrollable {
|
|||||||
c.fill = GridBagConstraints.HORIZONTAL;
|
c.fill = GridBagConstraints.HORIZONTAL;
|
||||||
c.insets = new Insets(0, 0, 0, 0);
|
c.insets = new Insets(0, 0, 0, 0);
|
||||||
header.add(new JSeparator(), c);
|
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;
|
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.
|
* unless it is the first row; leaves {@code c} as it found it.
|
||||||
*/
|
*/
|
||||||
static void addSection(JPanel p, GridBagConstraints c, int row, String title) {
|
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;
|
Insets insets = c.insets;
|
||||||
int width = c.gridwidth;
|
int width = c.gridwidth;
|
||||||
c.gridx = 0;
|
c.gridx = 0;
|
||||||
@@ -106,7 +123,7 @@ class FormPanel extends JPanel implements Scrollable {
|
|||||||
c.gridwidth = 2;
|
c.gridwidth = 2;
|
||||||
c.weightx = 0;
|
c.weightx = 0;
|
||||||
c.insets = UIScale.scale(new Insets(row == 0 ? 0 : 14, 0, 2, 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.insets = insets;
|
||||||
c.gridwidth = width;
|
c.gridwidth = width;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import java.time.format.DateTimeFormatter;
|
|||||||
import java.time.format.FormatStyle;
|
import java.time.format.FormatStyle;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options page for the myTeamSpeak account: sign in and out, and see what the
|
* 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 JLabel account = new JLabel();
|
||||||
private final JPanel details = new JPanel(new GridBagLayout());
|
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 refresh = new JButton("Refresh");
|
||||||
private final JButton importButton = new JButton("Import selected");
|
private final JButton importButton = new JButton("Import selected");
|
||||||
private final JLabel dataStatus = new JLabel(" ");
|
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)));
|
JPanel data = new JPanel(new BorderLayout(0, UIScale.scale(4)));
|
||||||
data.add(new JLabel("Synchronised by the account:"), BorderLayout.NORTH);
|
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);
|
data.add(buttons, BorderLayout.SOUTH);
|
||||||
|
|
||||||
JPanel panel = new JPanel(new BorderLayout(0, UIScale.scale(12)));
|
JPanel panel = new JPanel(new BorderLayout(0, UIScale.scale(12)));
|
||||||
@@ -181,7 +184,7 @@ final class MyTeamSpeakPanel extends JPanel {
|
|||||||
login.signOut();
|
login.signOut();
|
||||||
accountItems = List.of();
|
accountItems = List.of();
|
||||||
details.removeAll();
|
details.removeAll();
|
||||||
items.set(List.of());
|
setRows(List.of());
|
||||||
fetched = false;
|
fetched = false;
|
||||||
email.setText("");
|
email.setText("");
|
||||||
showState();
|
showState();
|
||||||
@@ -244,13 +247,13 @@ final class MyTeamSpeakPanel extends JPanel {
|
|||||||
boolean present = importer.isPresent(item);
|
boolean present = importer.isPresent(item);
|
||||||
rows.add(new Row(item, present, !present));
|
rows.add(new Row(item, present, !present));
|
||||||
}
|
}
|
||||||
items.set(rows);
|
setRows(rows);
|
||||||
status(dataStatus, rows.isEmpty() ? "The account holds no bookmarks or identities." : " ", false);
|
status(dataStatus, rows.isEmpty() ? "The account holds no bookmarks or identities." : " ", false);
|
||||||
updateImportButton();
|
updateImportButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importSelected() {
|
private void importSelected() {
|
||||||
List<SyncItem> chosen = items.rows.stream().filter(Row::selected).map(Row::item).toList();
|
List<SyncItem> chosen = allRows().filter(Row::selected).map(Row::item).toList();
|
||||||
if (chosen.isEmpty()) return;
|
if (chosen.isEmpty()) return;
|
||||||
try {
|
try {
|
||||||
TeamSpeakImporter.Result r = importer.importSelected(accountItems, chosen);
|
TeamSpeakImporter.Result r = importer.importSelected(accountItems, chosen);
|
||||||
@@ -261,8 +264,8 @@ final class MyTeamSpeakPanel extends JPanel {
|
|||||||
status(dataStatus, "Could not import: " + e.getMessage(), true);
|
status(dataStatus, "Could not import: " + e.getMessage(), true);
|
||||||
}
|
}
|
||||||
List<Row> rows = new ArrayList<>();
|
List<Row> rows = new ArrayList<>();
|
||||||
for (Row row : items.rows) rows.add(new Row(row.item(), importer.isPresent(row.item()), false));
|
allRows().forEach(row -> rows.add(new Row(row.item(), importer.isPresent(row.item()), false)));
|
||||||
items.set(rows);
|
setRows(rows);
|
||||||
updateImportButton();
|
updateImportButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,7 +299,34 @@ final class MyTeamSpeakPanel extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateImportButton() {
|
private void updateImportButton() {
|
||||||
importButton.setEnabled(refresh.isEnabled() && items.rows.stream().anyMatch(Row::selected));
|
importButton.setEnabled(refresh.isEnabled() && allRows().anyMatch(Row::selected));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Stream<Row> 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<Row> 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) {
|
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. */
|
/** 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 final class ItemTable extends AbstractTableModel {
|
||||||
|
|
||||||
private static final String[] COLUMNS = {"", "Type", "Name", "Details", "Imported"};
|
private final String[] columns;
|
||||||
|
final JTable table;
|
||||||
final JTable table = new JTable(this);
|
final JButton selectAll = new JButton();
|
||||||
List<Row> rows = List.of();
|
List<Row> rows = List.of();
|
||||||
|
|
||||||
ItemTable() {
|
ItemTable(String detailsColumn) {
|
||||||
table.setFillsViewportHeight(true);
|
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.getTableHeader().setReorderingAllowed(false);
|
||||||
table.getColumnModel().getColumn(0).setMaxWidth(UIScale.scale(28));
|
table.getColumnModel().getColumn(0).setMaxWidth(UIScale.scale(28));
|
||||||
table.getColumnModel().getColumn(1).setPreferredWidth(UIScale.scale(60));
|
table.getColumnModel().getColumn(3).setPreferredWidth(UIScale.scale(60));
|
||||||
table.getColumnModel().getColumn(4).setPreferredWidth(UIScale.scale(60));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void set(List<Row> rows) {
|
void set(List<Row> rows) {
|
||||||
this.rows = rows;
|
this.rows = rows;
|
||||||
fireTableDataChanged();
|
fireTableDataChanged();
|
||||||
|
updateSelectAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean allSelected() {
|
||||||
|
return rows.stream().allMatch(Row::selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSelectAll() {
|
||||||
|
selectAll.setText(allSelected() ? "Deselect all" : "Select all");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -343,12 +387,12 @@ final class MyTeamSpeakPanel extends JPanel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getColumnCount() {
|
public int getColumnCount() {
|
||||||
return COLUMNS.length;
|
return columns.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getColumnName(int column) {
|
public String getColumnName(int column) {
|
||||||
return COLUMNS[column];
|
return columns[column];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -366,13 +410,12 @@ final class MyTeamSpeakPanel extends JPanel {
|
|||||||
Row r = rows.get(row);
|
Row r = rows.get(row);
|
||||||
return switch (column) {
|
return switch (column) {
|
||||||
case 0 -> r.selected();
|
case 0 -> r.selected();
|
||||||
case 1 -> r.item() instanceof SyncItem.Bookmark ? "Bookmark" : "Identity";
|
case 1 -> switch (r.item()) {
|
||||||
case 2 -> switch (r.item()) {
|
|
||||||
case SyncItem.Bookmark b -> b.name();
|
case SyncItem.Bookmark b -> b.name();
|
||||||
case SyncItem.Identity i -> i.name();
|
case SyncItem.Identity i -> i.name();
|
||||||
default -> "";
|
default -> "";
|
||||||
};
|
};
|
||||||
case 3 -> switch (r.item()) {
|
case 2 -> switch (r.item()) {
|
||||||
case SyncItem.Bookmark b -> b.address() + ":" + b.port();
|
case SyncItem.Bookmark b -> b.address() + ":" + b.port();
|
||||||
case SyncItem.Identity i -> i.nickname();
|
case SyncItem.Identity i -> i.nickname();
|
||||||
default -> "";
|
default -> "";
|
||||||
@@ -388,6 +431,7 @@ final class MyTeamSpeakPanel extends JPanel {
|
|||||||
updated.set(row, new Row(r.item(), r.present(), Boolean.TRUE.equals(value)));
|
updated.set(row, new Row(r.item(), r.present(), Boolean.TRUE.equals(value)));
|
||||||
rows = updated;
|
rows = updated;
|
||||||
fireTableRowsUpdated(row, row);
|
fireTableRowsUpdated(row, row);
|
||||||
|
updateSelectAll();
|
||||||
updateImportButton();
|
updateImportButton();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user