Android: bookmark edit page, and bookmarks that join a channel
Edit from a bookmark's menu or create from the connect form: name, address, passwords, identity, nickname, and the channel to join, picked from the server's channels while connected there. The channel and server sheets add the server as a bookmark joining that channel. Bookmarking the current server takes the connect's own nickname and password (core ServerSession.toBookmark), on desktop too, rather than the global ones. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.ts3client.android
|
package com.ts3client.android
|
||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import com.ts3client.config.Bookmark
|
||||||
import com.ts3client.contacts.ContactType
|
import com.ts3client.contacts.ContactType
|
||||||
import com.ts3client.net.ChannelNode
|
import com.ts3client.net.ChannelNode
|
||||||
import com.ts3client.net.ConnectionStats
|
import com.ts3client.net.ConnectionStats
|
||||||
@@ -112,6 +113,9 @@ class ServerController internal constructor(
|
|||||||
refresh()
|
refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A bookmark leading back to this server, joining [channelId]; not yet saved. */
|
||||||
|
fun bookmark(channelId: Int): Bookmark? = session.toBookmark(conn.model.channelPath(channelId))
|
||||||
|
|
||||||
fun disconnect() {
|
fun disconnect() {
|
||||||
left = true
|
left = true
|
||||||
network.leaving()
|
network.leaving()
|
||||||
|
|||||||
@@ -261,24 +261,32 @@ class SessionController(private val context: Context) {
|
|||||||
|
|
||||||
// ---- bookmarks ----
|
// ---- bookmarks ----
|
||||||
|
|
||||||
fun addBookmark(label: String, address: String, nickname: String, password: String, identityId: String) {
|
/** A bookmark to [address] as typed into the connect form, not yet saved. */
|
||||||
|
fun newBookmark(address: String, nickname: String, password: String, identityId: String): Bookmark {
|
||||||
val (host, port) = parseAddress(address)
|
val (host, port) = parseAddress(address)
|
||||||
// Only a nickname other than the identity's is the server's own.
|
// Only a nickname other than the identity's is the server's own.
|
||||||
val own = nickname.takeIf { it != nicknameFor(identityId) }.orEmpty()
|
val own = nickname.takeIf { it != nicknameFor(identityId) }.orEmpty()
|
||||||
bookmarkStore.add(Bookmark(label.ifBlank { address }, host, port, own, password).also {
|
return Bookmark(host, host, port, own, password).also { it.identityId = identityId }
|
||||||
it.identityId = identityId
|
}
|
||||||
})
|
|
||||||
|
/** Puts [edited] in place of the bookmark at [index], or adds it when [index] is -1. */
|
||||||
|
fun saveBookmark(index: Int, edited: Bookmark) {
|
||||||
|
val all = bookmarkStore.all()
|
||||||
|
if (index !in all.indices) {
|
||||||
|
bookmarkStore.add(edited)
|
||||||
|
} else {
|
||||||
|
// The icon may have been learnt meanwhile, and belongs to the server, not to the bookmark.
|
||||||
|
edited.iconId = all[index].takeIf { it.pointsAt(edited.address, edited.port) }?.iconId ?: 0
|
||||||
|
all[index] = edited
|
||||||
|
}
|
||||||
saveBookmarks()
|
saveBookmarks()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Connects the bookmark with another identity; empty for the default one. */
|
/** The channels of a server we are on at [host]:[port], to pick one to join. */
|
||||||
fun setBookmarkIdentity(bookmark: Bookmark, identityId: String) {
|
fun channelPathsAt(host: String, port: Int): List<String> =
|
||||||
val index = bookmarkStore.all().indexOf(bookmark)
|
_servers.value.firstOrNull {
|
||||||
if (index < 0) return
|
it.isConnected && it.session.port() == port && it.session.address().equals(host.trim(), ignoreCase = true)
|
||||||
// A new entry, so the list the UI holds changes along with it.
|
}?.session?.channelPaths().orEmpty()
|
||||||
bookmarkStore.all()[index] = bookmark.copy().also { it.identityId = identityId }
|
|
||||||
saveBookmarks()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun removeBookmark(bookmark: Bookmark) {
|
fun removeBookmark(bookmark: Bookmark) {
|
||||||
val index = bookmarkStore.all().indexOf(bookmark)
|
val index = bookmarkStore.all().indexOf(bookmark)
|
||||||
@@ -538,10 +546,11 @@ class SessionController(private val context: Context) {
|
|||||||
server(serverId)?.reply(clientId, text) ?: notifier.clear(serverId, clientId)
|
server(serverId)?.reply(clientId, text) ?: notifier.clear(serverId, clientId)
|
||||||
}
|
}
|
||||||
|
|
||||||
private companion object {
|
companion object {
|
||||||
const val DEFAULT_PORT = 9987
|
const val DEFAULT_PORT = 9987
|
||||||
const val OVERLAY_ENABLED = "enabled"
|
private const val OVERLAY_ENABLED = "enabled"
|
||||||
|
|
||||||
|
/** `host[:port]` as typed, the port defaulting to TeamSpeak's. */
|
||||||
fun parseAddress(address: String): Pair<String, Int> {
|
fun parseAddress(address: String): Pair<String, Int> {
|
||||||
val host = address.substringBefore(':').trim()
|
val host = address.substringBefore(':').trim()
|
||||||
val port = address.substringAfter(':', "").trim().toIntOrNull() ?: DEFAULT_PORT
|
val port = address.substringAfter(':', "").trim().toIntOrNull() ?: DEFAULT_PORT
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ fun App(vm: SessionController) {
|
|||||||
var editingContact by rememberSaveable { mutableStateOf<String?>(null) }
|
var editingContact by rememberSaveable { mutableStateOf<String?>(null) }
|
||||||
// Set when a contact's page was opened from a client, so leaving it goes back there.
|
// Set when a contact's page was opened from a client, so leaving it goes back there.
|
||||||
var contactDirect by rememberSaveable { mutableStateOf(false) }
|
var contactDirect by rememberSaveable { mutableStateOf(false) }
|
||||||
|
var editingBookmark by rememberSaveable(stateSaver = BookmarkEditSaver) { mutableStateOf<BookmarkEdit?>(null) }
|
||||||
var poke by remember { mutableStateOf<SessionEvent.Poke?>(null) }
|
var poke by remember { mutableStateOf<SessionEvent.Poke?>(null) }
|
||||||
|
|
||||||
LaunchedEffect(vm) {
|
LaunchedEffect(vm) {
|
||||||
@@ -72,7 +73,9 @@ fun App(vm: SessionController) {
|
|||||||
|
|
||||||
CompositionLocalProvider(LocalIconTheme provides vm.icons, LocalWebPictures provides vm.pictures) {
|
CompositionLocalProvider(LocalIconTheme provides vm.icons, LocalWebPictures provides vm.pictures) {
|
||||||
val server = current
|
val server = current
|
||||||
|
val bookmark = editingBookmark
|
||||||
when {
|
when {
|
||||||
|
bookmark != null -> BookmarkScreen(vm, bookmark, onDone = { editingBookmark = null })
|
||||||
contactsOpen -> ContactsScreen(vm, editingContact, onEdit = { uniqueId ->
|
contactsOpen -> ContactsScreen(vm, editingContact, onEdit = { uniqueId ->
|
||||||
if (uniqueId == null && contactDirect) contactsOpen = false
|
if (uniqueId == null && contactDirect) contactsOpen = false
|
||||||
contactDirect = false
|
contactDirect = false
|
||||||
@@ -84,12 +87,13 @@ fun App(vm: SessionController) {
|
|||||||
CompositionLocalProvider(LocalServerImages provides server.images) {
|
CompositionLocalProvider(LocalServerImages provides server.images) {
|
||||||
PictureViewerHost(server) {
|
PictureViewerHost(server) {
|
||||||
ServerScreen(vm, server, snackbar, { settingsOpen = true }, openContacts, enableMicrophone,
|
ServerScreen(vm, server, snackbar, { settingsOpen = true }, openContacts, enableMicrophone,
|
||||||
onConnectOther = { connectOpen = true })
|
onConnectOther = { connectOpen = true }, onEditBookmark = { editingBookmark = it })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> ConnectScreen(vm, snackbar, { settingsOpen = true }, connectAsking,
|
else -> ConnectScreen(vm, snackbar, { settingsOpen = true }, connectAsking,
|
||||||
|
onEditBookmark = { editingBookmark = it },
|
||||||
onBack = if (current != null) ({ connectOpen = false }) else null)
|
onBack = if (current != null) ({ connectOpen = false }) else null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
package com.ts3client.android.ui
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.imePadding
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.ExposedDropdownMenuAnchorType
|
||||||
|
import androidx.compose.material3.ExposedDropdownMenuBox
|
||||||
|
import androidx.compose.material3.ExposedDropdownMenuDefaults
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.saveable.listSaver
|
||||||
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
|
import com.ts3client.android.SessionController
|
||||||
|
import com.ts3client.config.Bookmark
|
||||||
|
|
||||||
|
/** A bookmark on the edit page: [index] among the saved ones, -1 for a new one. */
|
||||||
|
class BookmarkEdit(val index: Int, val bookmark: Bookmark)
|
||||||
|
|
||||||
|
val BookmarkEditSaver = listSaver<BookmarkEdit?, Any>(
|
||||||
|
save = { edit ->
|
||||||
|
val b = edit?.bookmark ?: return@listSaver emptyList()
|
||||||
|
listOf(edit.index, b.label.orEmpty(), b.address.orEmpty(), b.port, b.nickname.orEmpty(), b.password,
|
||||||
|
b.identityId, b.channel, b.channelPassword, b.connectOnStartup, b.iconId)
|
||||||
|
},
|
||||||
|
restore = { saved ->
|
||||||
|
if (saved.isEmpty()) null
|
||||||
|
else BookmarkEdit(saved[0] as Int, Bookmark(saved[1] as String, saved[2] as String, saved[3] as Int,
|
||||||
|
saved[4] as String, saved[5] as String).apply {
|
||||||
|
identityId = saved[6] as String
|
||||||
|
channel = saved[7] as String
|
||||||
|
channelPassword = saved[8] as String
|
||||||
|
connectOnStartup = saved[9] as Boolean
|
||||||
|
iconId = saved[10] as Long
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
/** Every setting of one bookmark, saved only on Save. */
|
||||||
|
@Composable
|
||||||
|
fun BookmarkScreen(vm: SessionController, edit: BookmarkEdit, onDone: () -> Unit) {
|
||||||
|
val b = edit.bookmark
|
||||||
|
val identities by vm.identities.all.collectAsStateWithLifecycle()
|
||||||
|
var label by rememberSaveable { mutableStateOf(b.label.orEmpty()) }
|
||||||
|
var address by rememberSaveable {
|
||||||
|
mutableStateOf(if (b.port == SessionController.DEFAULT_PORT) b.address.orEmpty() else "${b.address}:${b.port}")
|
||||||
|
}
|
||||||
|
var nickname by rememberSaveable { mutableStateOf(b.nickname.orEmpty()) }
|
||||||
|
var password by rememberSaveable { mutableStateOf(b.password.orEmpty()) }
|
||||||
|
var identityId by rememberSaveable { mutableStateOf(b.identityId.orEmpty()) }
|
||||||
|
var channel by rememberSaveable { mutableStateOf(b.channel.orEmpty()) }
|
||||||
|
var channelPassword by rememberSaveable { mutableStateOf(b.channelPassword.orEmpty()) }
|
||||||
|
|
||||||
|
val save = {
|
||||||
|
val (host, port) = SessionController.parseAddress(address)
|
||||||
|
vm.saveBookmark(edit.index, b.copy().also {
|
||||||
|
it.label = label.trim().ifEmpty { host }
|
||||||
|
it.address = host
|
||||||
|
it.port = port
|
||||||
|
it.nickname = nickname.trim()
|
||||||
|
it.password = password
|
||||||
|
it.identityId = identityId
|
||||||
|
it.channel = channel.trim()
|
||||||
|
it.channelPassword = channelPassword
|
||||||
|
})
|
||||||
|
onDone()
|
||||||
|
}
|
||||||
|
|
||||||
|
SubScreen(if (edit.index < 0) "New bookmark" else "Edit bookmark", onBack = onDone, actions = {
|
||||||
|
TextButton(onClick = save, enabled = address.isNotBlank()) { Text("Save") }
|
||||||
|
}) { padding ->
|
||||||
|
Column(
|
||||||
|
Modifier.padding(padding).imePadding().verticalScroll(rememberScrollState()).padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
) {
|
||||||
|
OutlinedTextField(label, { label = it }, Modifier.fillMaxWidth(), label = { Text("Name") }, singleLine = true)
|
||||||
|
OutlinedTextField(address, { address = it }, Modifier.fillMaxWidth(), label = { Text("Server address") },
|
||||||
|
singleLine = true, keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Uri))
|
||||||
|
OutlinedTextField(password, { password = it }, Modifier.fillMaxWidth(),
|
||||||
|
label = { Text("Server password") }, singleLine = true,
|
||||||
|
visualTransformation = PasswordVisualTransformation(),
|
||||||
|
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password))
|
||||||
|
IdentityField(identities, identityId) { identityId = it }
|
||||||
|
OutlinedTextField(nickname, { nickname = it }, Modifier.fillMaxWidth(), label = { Text("Nickname") },
|
||||||
|
placeholder = { Text(vm.nicknameFor(identityId)) }, singleLine = true)
|
||||||
|
val paths = remember(address) {
|
||||||
|
SessionController.parseAddress(address).let { (host, port) -> vm.channelPathsAt(host, port) }
|
||||||
|
}
|
||||||
|
ChannelField(channel, paths) { channel = it }
|
||||||
|
OutlinedTextField(channelPassword, { channelPassword = it }, Modifier.fillMaxWidth(),
|
||||||
|
label = { Text("Channel password") }, singleLine = true,
|
||||||
|
visualTransformation = PasswordVisualTransformation(),
|
||||||
|
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The channel to join, typed or picked among [paths] of the server when we are on it. */
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
private fun ChannelField(channel: String, paths: List<String>, onChange: (String) -> Unit) {
|
||||||
|
var open by remember { mutableStateOf(false) }
|
||||||
|
// A channel already picked lists them all, for picking another.
|
||||||
|
val matches = if (channel in paths) paths else paths.filter { it.contains(channel.trim(), ignoreCase = true) }
|
||||||
|
val expanded = open && matches.isNotEmpty()
|
||||||
|
ExposedDropdownMenuBox(expanded, { open = it }) {
|
||||||
|
OutlinedTextField(
|
||||||
|
channel, { onChange(it); open = true }, singleLine = true,
|
||||||
|
label = { Text("Channel") },
|
||||||
|
placeholder = { Text("Default") },
|
||||||
|
trailingIcon = if (paths.isEmpty()) null else ({ ExposedDropdownMenuDefaults.TrailingIcon(expanded) }),
|
||||||
|
modifier = Modifier.fillMaxWidth().menuAnchor(ExposedDropdownMenuAnchorType.PrimaryEditable),
|
||||||
|
)
|
||||||
|
ExposedDropdownMenu(expanded, { open = false }) {
|
||||||
|
for (path in matches) {
|
||||||
|
DropdownMenuItem({ Text(path) }, onClick = {
|
||||||
|
open = false
|
||||||
|
onChange(path)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,15 +13,12 @@ import androidx.compose.foundation.layout.imePadding
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.rememberScrollState
|
|
||||||
import androidx.compose.foundation.verticalScroll
|
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
import androidx.compose.material.icons.filled.MoreVert
|
import androidx.compose.material.icons.filled.MoreVert
|
||||||
import androidx.compose.material3.AlertDialog
|
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.DropdownMenu
|
import androidx.compose.material3.DropdownMenu
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
@@ -65,6 +62,7 @@ fun ConnectScreen(
|
|||||||
snackbar: SnackbarHostState,
|
snackbar: SnackbarHostState,
|
||||||
onSettings: () -> Unit,
|
onSettings: () -> Unit,
|
||||||
onConnect: (() -> Unit) -> Unit,
|
onConnect: (() -> Unit) -> Unit,
|
||||||
|
onEditBookmark: (BookmarkEdit) -> Unit,
|
||||||
/** Back to the servers already connected; null when there are none. */
|
/** Back to the servers already connected; null when there are none. */
|
||||||
onBack: (() -> Unit)?,
|
onBack: (() -> Unit)?,
|
||||||
) {
|
) {
|
||||||
@@ -75,8 +73,6 @@ fun ConnectScreen(
|
|||||||
var identityId by rememberSaveable { mutableStateOf("") }
|
var identityId by rememberSaveable { mutableStateOf("") }
|
||||||
var nickname by rememberSaveable { mutableStateOf(vm.nicknameFor("")) }
|
var nickname by rememberSaveable { mutableStateOf(vm.nicknameFor("")) }
|
||||||
var password by rememberSaveable { mutableStateOf("") }
|
var password by rememberSaveable { mutableStateOf("") }
|
||||||
var naming by rememberSaveable { mutableStateOf(false) }
|
|
||||||
var choosingFor by remember { mutableStateOf<Bookmark?>(null) }
|
|
||||||
|
|
||||||
if (onBack != null) BackHandler(onBack = onBack)
|
if (onBack != null) BackHandler(onBack = onBack)
|
||||||
|
|
||||||
@@ -121,7 +117,9 @@ fun ConnectScreen(
|
|||||||
onClick = { onConnect { vm.connect(address.trim(), nickname.trim(), password, identityId) } },
|
onClick = { onConnect { vm.connect(address.trim(), nickname.trim(), password, identityId) } },
|
||||||
enabled = address.isNotBlank() && nickname.isNotBlank(),
|
enabled = address.isNotBlank() && nickname.isNotBlank(),
|
||||||
) { Text("Connect") }
|
) { Text("Connect") }
|
||||||
TextButton(onClick = { naming = true }, enabled = address.isNotBlank()) { Text("Add bookmark") }
|
TextButton(onClick = {
|
||||||
|
onEditBookmark(BookmarkEdit(-1, vm.newBookmark(address.trim(), nickname.trim(), password, identityId)))
|
||||||
|
}, enabled = address.isNotBlank()) { Text("Add bookmark") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,32 +129,12 @@ fun ConnectScreen(
|
|||||||
color = MaterialTheme.colorScheme.primary)
|
color = MaterialTheme.colorScheme.primary)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
items(bookmarks) { bookmark ->
|
itemsIndexed(bookmarks) { index, bookmark ->
|
||||||
BookmarkRow(bookmark, identities, { onConnect { vm.connect(bookmark) } },
|
BookmarkRow(bookmark, identities, { onConnect { vm.connect(bookmark) } },
|
||||||
onChooseIdentity = { choosingFor = bookmark }, onRemove = { vm.removeBookmark(bookmark) })
|
onEdit = { onEditBookmark(BookmarkEdit(index, bookmark)) }, onRemove = { vm.removeBookmark(bookmark) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (naming) {
|
|
||||||
TextPrompt(
|
|
||||||
title = "Add bookmark",
|
|
||||||
label = "Name",
|
|
||||||
confirm = "Add",
|
|
||||||
initial = address,
|
|
||||||
onDismiss = { naming = false },
|
|
||||||
onConfirm = {
|
|
||||||
naming = false
|
|
||||||
vm.addBookmark(it, address.trim(), nickname.trim(), password, identityId)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
choosingFor?.let { bookmark ->
|
|
||||||
IdentityDialog(identities, bookmark.identityId, onDismiss = { choosingFor = null }) {
|
|
||||||
choosingFor = null
|
|
||||||
vm.setBookmarkIdentity(bookmark, it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The identities to connect with, the default one first as an empty id. */
|
/** The identities to connect with, the default one first as an empty id. */
|
||||||
@@ -170,7 +148,7 @@ private fun shownId(identities: List<IdentityInfo>, id: String) = id.takeIf { i
|
|||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
private fun IdentityField(identities: List<IdentityInfo>, selected: String, onSelect: (String) -> Unit) {
|
internal fun IdentityField(identities: List<IdentityInfo>, selected: String, onSelect: (String) -> Unit) {
|
||||||
val choices = identityChoices(identities)
|
val choices = identityChoices(identities)
|
||||||
val shown = shownId(identities, selected)
|
val shown = shownId(identities, selected)
|
||||||
var open by remember { mutableStateOf(false) }
|
var open by remember { mutableStateOf(false) }
|
||||||
@@ -192,22 +170,6 @@ private fun IdentityField(identities: List<IdentityInfo>, selected: String, onSe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun IdentityDialog(identities: List<IdentityInfo>, selected: String, onDismiss: () -> Unit, onSelect: (String) -> Unit) {
|
|
||||||
val shown = shownId(identities, selected)
|
|
||||||
AlertDialog(
|
|
||||||
onDismissRequest = onDismiss,
|
|
||||||
title = { Text("Connect with") },
|
|
||||||
text = {
|
|
||||||
Column(Modifier.verticalScroll(rememberScrollState())) {
|
|
||||||
for ((id, name) in identityChoices(identities)) Choice(name, id == shown) { onSelect(id) }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
confirmButton = {},
|
|
||||||
dismissButton = { TextButton(onClick = onDismiss) { Text("Cancel") } },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The server's icon as last seen there, else the pack's bookmark icon. */
|
/** The server's icon as last seen there, else the pack's bookmark icon. */
|
||||||
@Composable
|
@Composable
|
||||||
private fun BookmarkIcon(iconId: Long) {
|
private fun BookmarkIcon(iconId: Long) {
|
||||||
@@ -223,7 +185,7 @@ private fun BookmarkRow(
|
|||||||
bookmark: Bookmark,
|
bookmark: Bookmark,
|
||||||
identities: List<IdentityInfo>,
|
identities: List<IdentityInfo>,
|
||||||
onConnect: () -> Unit,
|
onConnect: () -> Unit,
|
||||||
onChooseIdentity: () -> Unit,
|
onEdit: () -> Unit,
|
||||||
onRemove: () -> Unit,
|
onRemove: () -> Unit,
|
||||||
) {
|
) {
|
||||||
val identity = identities.firstOrNull { it.id == bookmark.identityId }
|
val identity = identities.firstOrNull { it.id == bookmark.identityId }
|
||||||
@@ -231,14 +193,15 @@ private fun BookmarkRow(
|
|||||||
ListItem(
|
ListItem(
|
||||||
headlineContent = { Text(bookmark.displayName()) },
|
headlineContent = { Text(bookmark.displayName()) },
|
||||||
supportingContent = {
|
supportingContent = {
|
||||||
Text("${bookmark.address}:${bookmark.port}" + (identity?.let { " · ${it.name}" } ?: ""))
|
Text(listOfNotNull("${bookmark.address}:${bookmark.port}", bookmark.channel.ifBlank { null }, identity?.name)
|
||||||
|
.joinToString(" · "))
|
||||||
},
|
},
|
||||||
leadingContent = { BookmarkIcon(bookmark.iconId) },
|
leadingContent = { BookmarkIcon(bookmark.iconId) },
|
||||||
trailingContent = {
|
trailingContent = {
|
||||||
Box {
|
Box {
|
||||||
IconButton(onClick = { menu = true }) { Icon(Icons.Default.MoreVert, "Bookmark options") }
|
IconButton(onClick = { menu = true }) { Icon(Icons.Default.MoreVert, "Bookmark options") }
|
||||||
DropdownMenu(menu, { menu = false }) {
|
DropdownMenu(menu, { menu = false }) {
|
||||||
DropdownMenuItem({ Text("Identity") }, onClick = { menu = false; onChooseIdentity() })
|
DropdownMenuItem({ Text("Edit") }, onClick = { menu = false; onEdit() })
|
||||||
DropdownMenuItem({ Text("Remove") }, onClick = { menu = false; onRemove() })
|
DropdownMenuItem({ Text("Remove") }, onClick = { menu = false; onRemove() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ fun ServerScreen(
|
|||||||
onEditContact: (String) -> Unit,
|
onEditContact: (String) -> Unit,
|
||||||
onEnableMicrophone: () -> Unit,
|
onEnableMicrophone: () -> Unit,
|
||||||
onConnectOther: () -> Unit,
|
onConnectOther: () -> Unit,
|
||||||
|
onEditBookmark: (BookmarkEdit) -> Unit,
|
||||||
) {
|
) {
|
||||||
val state by server.state.collectAsStateWithLifecycle()
|
val state by server.state.collectAsStateWithLifecycle()
|
||||||
val tree by server.tree.collectAsStateWithLifecycle()
|
val tree by server.tree.collectAsStateWithLifecycle()
|
||||||
@@ -131,6 +132,7 @@ fun ServerScreen(
|
|||||||
if (channel.locked) joinLocked = channel.id else server.joinChannel(channel.id)
|
if (channel.locked) joinLocked = channel.id else server.joinChannel(channel.id)
|
||||||
}
|
}
|
||||||
var serverSheet by remember { mutableStateOf(false) }
|
var serverSheet by remember { mutableStateOf(false) }
|
||||||
|
val bookmarkHere = { channelId: Int -> server.bookmark(channelId)?.let { onEditBookmark(BookmarkEdit(-1, it)) } }
|
||||||
var banList by rememberSaveable { mutableStateOf(false) }
|
var banList by rememberSaveable { mutableStateOf(false) }
|
||||||
var connectionInfo by rememberSaveable { mutableStateOf<Int?>(null) }
|
var connectionInfo by rememberSaveable { mutableStateOf<Int?>(null) }
|
||||||
/** The client to move, while a channel for them is being picked. */
|
/** The client to move, while a channel for them is being picked. */
|
||||||
@@ -378,6 +380,7 @@ fun ServerScreen(
|
|||||||
onDismiss = { channelSheet = null },
|
onDismiss = { channelSheet = null },
|
||||||
onJoin = { join(channel); channelSheet = null },
|
onJoin = { join(channel); channelSheet = null },
|
||||||
onSubscribe = { server.setSubscribed(id, it); channelSheet = null },
|
onSubscribe = { server.setSubscribed(id, it); channelSheet = null },
|
||||||
|
onBookmark = { channelSheet = null; bookmarkHere(id) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -394,6 +397,7 @@ fun ServerScreen(
|
|||||||
if (serverSheet) {
|
if (serverSheet) {
|
||||||
remember(tree, infoUpdates) { server.serverDetails() }?.let {
|
remember(tree, infoUpdates) { server.serverDetails() }?.let {
|
||||||
ServerSheet(it, onLink, onDismiss = { serverSheet = false },
|
ServerSheet(it, onLink, onDismiss = { serverSheet = false },
|
||||||
|
onBookmark = { serverSheet = false; bookmarkHere(state.channelId) },
|
||||||
onBanList = if (server.canViewBanList) ({ serverSheet = false; banList = true }) else null)
|
onBanList = if (server.canViewBanList) ({ serverSheet = false; banList = true }) else null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ fun ChannelSheet(
|
|||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
onJoin: () -> Unit,
|
onJoin: () -> Unit,
|
||||||
onSubscribe: (Boolean) -> Unit,
|
onSubscribe: (Boolean) -> Unit,
|
||||||
|
onBookmark: () -> Unit,
|
||||||
) {
|
) {
|
||||||
ModalBottomSheet(onDismissRequest = onDismiss) {
|
ModalBottomSheet(onDismissRequest = onDismiss) {
|
||||||
Column(Modifier.verticalScroll(rememberScrollState()).navigationBarsPadding().padding(bottom = 16.dp)) {
|
Column(Modifier.verticalScroll(rememberScrollState()).navigationBarsPadding().padding(bottom = 16.dp)) {
|
||||||
@@ -154,6 +155,7 @@ fun ChannelSheet(
|
|||||||
} else {
|
} else {
|
||||||
Action("SUBSCRIBE_TO_CHANNEL", "Subscribe") { onSubscribe(true) }
|
Action("SUBSCRIBE_TO_CHANNEL", "Subscribe") { onSubscribe(true) }
|
||||||
}
|
}
|
||||||
|
Action("BOOKMARK_ADD", "Add to bookmarks", onClick = onBookmark)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,7 +163,13 @@ fun ChannelSheet(
|
|||||||
/** The server's details: its version, who is on it, its welcome message. */
|
/** The server's details: its version, who is on it, its welcome message. */
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ServerSheet(details: Details, onLink: (String) -> Unit, onDismiss: () -> Unit, onBanList: (() -> Unit)?) {
|
fun ServerSheet(
|
||||||
|
details: Details,
|
||||||
|
onLink: (String) -> Unit,
|
||||||
|
onDismiss: () -> Unit,
|
||||||
|
onBookmark: () -> Unit,
|
||||||
|
onBanList: (() -> Unit)?,
|
||||||
|
) {
|
||||||
ModalBottomSheet(onDismissRequest = onDismiss) {
|
ModalBottomSheet(onDismissRequest = onDismiss) {
|
||||||
Column(Modifier.verticalScroll(rememberScrollState()).navigationBarsPadding().padding(bottom = 16.dp)) {
|
Column(Modifier.verticalScroll(rememberScrollState()).navigationBarsPadding().padding(bottom = 16.dp)) {
|
||||||
Row(Modifier.padding(horizontal = 24.dp, vertical = 8.dp), verticalAlignment = Alignment.CenterVertically,
|
Row(Modifier.padding(horizontal = 24.dp, vertical = 8.dp), verticalAlignment = Alignment.CenterVertically,
|
||||||
@@ -170,6 +178,7 @@ fun ServerSheet(details: Details, onLink: (String) -> Unit, onDismiss: () -> Uni
|
|||||||
Text(details.title(), style = MaterialTheme.typography.titleLarge)
|
Text(details.title(), style = MaterialTheme.typography.titleLarge)
|
||||||
}
|
}
|
||||||
DetailsSection(details, onLink)
|
DetailsSection(details, onLink)
|
||||||
|
Action("BOOKMARK_ADD", "Add to bookmarks", onClick = onBookmark)
|
||||||
onBanList?.let { Action("BAN_LIST", "Ban list", onClick = it) }
|
onBanList?.let { Action("BAN_LIST", "Ban list", onClick = it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.ts3client.session;
|
package com.ts3client.session;
|
||||||
|
|
||||||
import com.ts3client.audio.AudioBackend;
|
import com.ts3client.audio.AudioBackend;
|
||||||
|
import com.ts3client.config.Bookmark;
|
||||||
import com.ts3client.config.IdentityEntry;
|
import com.ts3client.config.IdentityEntry;
|
||||||
import com.ts3client.config.IdentityStore;
|
import com.ts3client.config.IdentityStore;
|
||||||
import com.ts3client.config.Settings;
|
import com.ts3client.config.Settings;
|
||||||
@@ -135,6 +136,19 @@ public final class ServerSession {
|
|||||||
return identityId;
|
return identityId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A bookmark leading back here: this server under its name, with the nickname, password and
|
||||||
|
* identity of the last connect, joining {@code channel}. Null before a first connect.
|
||||||
|
*/
|
||||||
|
public Bookmark toBookmark(String channel) {
|
||||||
|
Target target = lastTarget;
|
||||||
|
if (target == null) return null;
|
||||||
|
Bookmark b = new Bookmark(title, target.address(), target.port(), target.nickname(), target.password());
|
||||||
|
b.identityId = identityId;
|
||||||
|
b.channel = channel == null ? "" : channel;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
// ---- connection lifecycle ----
|
// ---- connection lifecycle ----
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -826,8 +826,6 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
|||||||
"Add bookmark", JOptionPane.INFORMATION_MESSAGE);
|
"Add bookmark", JOptionPane.INFORMATION_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String addr = selected.session().address();
|
|
||||||
int port = selected.session().port();
|
|
||||||
String channelPath = selected.session().currentChannelPath();
|
String channelPath = selected.session().currentChannelPath();
|
||||||
|
|
||||||
JTextField labelField = new JTextField(selected.session().title());
|
JTextField labelField = new JTextField(selected.session().title());
|
||||||
@@ -840,10 +838,8 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
|||||||
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) != JOptionPane.OK_OPTION) {
|
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) != JOptionPane.OK_OPTION) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bookmark bookmark = new Bookmark(labelField.getText().trim(), addr, port,
|
Bookmark bookmark = selected.session().toBookmark(joinChannel.isSelected() ? channelPath : "");
|
||||||
settings.nickname, settings.serverPassword);
|
bookmark.label = labelField.getText().trim();
|
||||||
bookmark.identityId = selected.session().identityId();
|
|
||||||
if (joinChannel.isSelected()) bookmark.channel = channelPath;
|
|
||||||
bookmarks.add(bookmark);
|
bookmarks.add(bookmark);
|
||||||
bookmarks.save();
|
bookmarks.save();
|
||||||
menuBar.rebuildBookmarks();
|
menuBar.rebuildBookmarks();
|
||||||
|
|||||||
Reference in New Issue
Block a user