Hide the default port in bookmark lists
Bookmark.hostPort gives the address alone for port 9987 and address:port otherwise. The Android connect screen, the myTeamSpeak item lists on desktop and Android, and the display name of an unnamed bookmark use it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -221,7 +221,7 @@ private fun BookmarkRow(
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
supportingContent = {
|
supportingContent = {
|
||||||
Text(listOfNotNull("${bookmark.address}:${bookmark.port}", bookmark.channel.ifBlank { null }, identity?.name)
|
Text(listOfNotNull(bookmark.hostPort(), bookmark.channel.ifBlank { null }, identity?.name)
|
||||||
.joinToString(" · "))
|
.joinToString(" · "))
|
||||||
},
|
},
|
||||||
leadingContent = { BookmarkIcon(bookmark.iconId) },
|
leadingContent = { BookmarkIcon(bookmark.iconId) },
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
|
|||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import eu.lixko.ts3j.client.android.SessionController
|
import eu.lixko.ts3j.client.android.SessionController
|
||||||
|
import eu.lixko.ts3j.client.config.Bookmark
|
||||||
import eu.lixko.ts3j.client.myts.AccountInfo
|
import eu.lixko.ts3j.client.myts.AccountInfo
|
||||||
import eu.lixko.ts3j.client.myts.MyTeamSpeak
|
import eu.lixko.ts3j.client.myts.MyTeamSpeak
|
||||||
import eu.lixko.ts3j.client.myts.MyTsException
|
import eu.lixko.ts3j.client.myts.MyTsException
|
||||||
@@ -256,7 +257,7 @@ private fun name(item: SyncItem) = when (item) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun details(item: SyncItem) = when (item) {
|
private fun details(item: SyncItem) = when (item) {
|
||||||
is SyncItem.Bookmark -> "${item.address()}:${item.port()}"
|
is SyncItem.Bookmark -> Bookmark.hostPort(item.address(), item.port())
|
||||||
is SyncItem.Identity -> item.nickname()
|
is SyncItem.Identity -> item.nickname()
|
||||||
else -> ""
|
else -> ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ import java.util.UUID;
|
|||||||
|
|
||||||
/** A saved server for quick connect. */
|
/** A saved server for quick connect. */
|
||||||
public final class Bookmark {
|
public final class Bookmark {
|
||||||
|
public static final int DEFAULT_PORT = 9987;
|
||||||
|
|
||||||
/** Stays the same through edits, for whatever refers to the bookmark from outside, like a launcher shortcut. */
|
/** Stays the same through edits, for whatever refers to the bookmark from outside, like a launcher shortcut. */
|
||||||
public String id = UUID.randomUUID().toString();
|
public String id = UUID.randomUUID().toString();
|
||||||
public String label;
|
public String label;
|
||||||
public String address;
|
public String address;
|
||||||
public int port = 9987;
|
public int port = DEFAULT_PORT;
|
||||||
public String nickname;
|
public String nickname;
|
||||||
public String password = "";
|
public String password = "";
|
||||||
/** Identity to connect with; empty means "use the default identity". */
|
/** Identity to connect with; empty means "use the default identity". */
|
||||||
@@ -53,10 +55,19 @@ public final class Bookmark {
|
|||||||
return this.port == port && this.address != null && this.address.trim().equalsIgnoreCase(address.trim());
|
return this.port == port && this.address != null && this.address.trim().equalsIgnoreCase(address.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Display name, falling back to "address:port" when no label is set. */
|
/** Display name, falling back to {@link #hostPort()} when no label is set. */
|
||||||
public String displayName() {
|
public String displayName() {
|
||||||
if (label != null && !label.isBlank()) return label;
|
if (label != null && !label.isBlank()) return label;
|
||||||
return address + ":" + port;
|
return hostPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String hostPort() {
|
||||||
|
return hostPort(address, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@code address}, followed by {@code :port} unless it is {@link #DEFAULT_PORT}. */
|
||||||
|
public static String hostPort(String address, int port) {
|
||||||
|
return port == DEFAULT_PORT ? address : address + ":" + port;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package eu.lixko.ts3j.client.config;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
class BookmarkTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void hostPortOmitsDefaultPort() {
|
||||||
|
assertEquals("ts.example.com", Bookmark.hostPort("ts.example.com", 9987));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void hostPortKeepsOtherPorts() {
|
||||||
|
assertEquals("ts.example.com:9988", Bookmark.hostPort("ts.example.com", 9988));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void displayNameWithoutLabelOmitsDefaultPort() {
|
||||||
|
assertEquals("ts.example.com", new Bookmark("", "ts.example.com", 9987, "nick", "").displayName());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package eu.lixko.ts3j.client.ui;
|
|||||||
|
|
||||||
import com.formdev.flatlaf.util.ScaledEmptyBorder;
|
import com.formdev.flatlaf.util.ScaledEmptyBorder;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
import eu.lixko.ts3j.client.config.Bookmark;
|
||||||
import eu.lixko.ts3j.client.myts.AccountInfo;
|
import eu.lixko.ts3j.client.myts.AccountInfo;
|
||||||
import eu.lixko.ts3j.client.myts.MyTeamSpeak;
|
import eu.lixko.ts3j.client.myts.MyTeamSpeak;
|
||||||
import eu.lixko.ts3j.client.myts.MyTeamSpeakLogin;
|
import eu.lixko.ts3j.client.myts.MyTeamSpeakLogin;
|
||||||
@@ -416,7 +417,7 @@ final class MyTeamSpeakPanel extends JPanel {
|
|||||||
default -> "";
|
default -> "";
|
||||||
};
|
};
|
||||||
case 2 -> switch (r.item()) {
|
case 2 -> switch (r.item()) {
|
||||||
case SyncItem.Bookmark b -> b.address() + ":" + b.port();
|
case SyncItem.Bookmark b -> Bookmark.hostPort(b.address(), b.port());
|
||||||
case SyncItem.Identity i -> i.nickname();
|
case SyncItem.Identity i -> i.nickname();
|
||||||
default -> "";
|
default -> "";
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user