Add Giant PTT: a full-screen talk button on Android and a resizable window on desktop
Holding it forces transmission in any input mode, past the voice-activation gate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -384,6 +384,9 @@ class SessionController(private val context: Context) {
|
||||
/** Opens the microphone of the server holding it while push-to-talk is held. */
|
||||
fun setPushToTalk(pressed: Boolean) = sessions.setPushToTalk(pressed)
|
||||
|
||||
/** Transmits on the server holding the microphone while held, past the voice-activation gate too. */
|
||||
fun setForceTransmit(pressed: Boolean) = sessions.setForceTransmit(pressed)
|
||||
|
||||
private fun microphoneMoved() {
|
||||
val owner = sessions.microphoneOwner()
|
||||
for (server in _servers.value) {
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.ts3client.android.ui
|
||||
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.ts3client.android.ServerController
|
||||
import com.ts3client.android.ServerTree
|
||||
import com.ts3client.android.SessionController
|
||||
import com.ts3client.android.SessionState
|
||||
import com.ts3client.net.ClientStatus
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
||||
/** What push-to-talk would talk on: the server holding the microphone, which need not be the one on screen. */
|
||||
internal class PttTarget(val owner: ServerController?, val state: SessionState, val talking: Boolean)
|
||||
|
||||
@Composable
|
||||
internal fun rememberPttTarget(vm: SessionController): PttTarget {
|
||||
val owner by vm.micOwner.collectAsStateWithLifecycle()
|
||||
val state by remember(owner) { owner?.state ?: MutableStateFlow(SessionState()) }.collectAsStateWithLifecycle()
|
||||
val tree by remember(owner) { owner?.tree ?: MutableStateFlow(ServerTree()) }.collectAsStateWithLifecycle()
|
||||
val self = tree.client(state.selfClientId)
|
||||
val talking = self?.status == ClientStatus.TALKING || self?.status == ClientStatus.COMMANDER_TALKING
|
||||
return PttTarget(owner, state, talking)
|
||||
}
|
||||
|
||||
/** Talks while held. */
|
||||
@Composable
|
||||
internal fun PushToTalk(
|
||||
talking: Boolean,
|
||||
onPressed: (Boolean) -> Unit,
|
||||
modifier: Modifier,
|
||||
shape: Shape = RoundedCornerShape(24.dp),
|
||||
textStyle: TextStyle = MaterialTheme.typography.titleMedium,
|
||||
) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
Surface(
|
||||
modifier.pointerInput(Unit) {
|
||||
detectTapGestures(onPress = {
|
||||
onPressed(true)
|
||||
try {
|
||||
awaitRelease()
|
||||
} finally {
|
||||
onPressed(false)
|
||||
}
|
||||
})
|
||||
},
|
||||
shape = shape,
|
||||
color = if (talking) StatusColors.talking else colors.primaryContainer,
|
||||
contentColor = if (talking) Color.White else colors.onPrimaryContainer,
|
||||
) {
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
Text(if (talking) "Talking…" else "Hold to talk", style = textStyle)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Nothing but a push-to-talk button, as big as the screen; it talks in any input mode. */
|
||||
@Composable
|
||||
fun GiantPttScreen(vm: SessionController, onBack: () -> Unit) {
|
||||
val target = rememberPttTarget(vm)
|
||||
SubScreen("Giant PTT", onBack) { padding ->
|
||||
val fill = Modifier.padding(padding).fillMaxSize().padding(16.dp)
|
||||
if (target.owner != null && target.state.connected) {
|
||||
PushToTalk(target.talking, vm::setForceTransmit, fill, RoundedCornerShape(32.dp),
|
||||
MaterialTheme.typography.displaySmall)
|
||||
} else {
|
||||
Box(fill, contentAlignment = Alignment.Center) {
|
||||
Text("Not connected",
|
||||
style = MaterialTheme.typography.titleMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@@ -20,7 +19,6 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowDropDown
|
||||
import androidx.compose.material3.Badge
|
||||
@@ -56,14 +54,12 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.key.Key
|
||||
import androidx.compose.ui.input.key.KeyEventType
|
||||
import androidx.compose.ui.input.key.isCtrlPressed
|
||||
import androidx.compose.ui.input.key.key
|
||||
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||
import androidx.compose.ui.input.key.type
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalUriHandler
|
||||
import androidx.compose.ui.semantics.Role
|
||||
@@ -74,15 +70,12 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.ts3client.android.ChatKey
|
||||
import com.ts3client.android.ChatMatch
|
||||
import com.ts3client.android.ServerController
|
||||
import com.ts3client.android.ServerTree
|
||||
import com.ts3client.android.SessionController
|
||||
import com.ts3client.android.SessionState
|
||||
import com.ts3client.android.TreeFind
|
||||
import com.ts3client.android.findIn
|
||||
import com.ts3client.config.Settings
|
||||
import com.ts3client.net.ClientStatus
|
||||
import com.ts3client.text.TsLink
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
||||
private val ChatKeySaver = Saver<ChatKey, String>(
|
||||
save = { key ->
|
||||
@@ -245,15 +238,8 @@ fun ServerScreen(
|
||||
}
|
||||
},
|
||||
bottomBar = {
|
||||
// Push-to-talk talks on whichever server holds the microphone, which need not be this one.
|
||||
val owner by vm.micOwner.collectAsStateWithLifecycle()
|
||||
val ownerState by remember(owner) { owner?.state ?: MutableStateFlow(SessionState()) }
|
||||
.collectAsStateWithLifecycle()
|
||||
val ownerTree by remember(owner) { owner?.tree ?: MutableStateFlow(ServerTree()) }
|
||||
.collectAsStateWithLifecycle()
|
||||
val self = ownerTree.client(ownerState.selfClientId)
|
||||
val talking = self?.status == ClientStatus.TALKING || self?.status == ClientStatus.COMMANDER_TALKING
|
||||
VoiceBar(state, owner != null, talking, vm, server, onEnableMicrophone, showChat, chats.anyUnread) {
|
||||
val ptt = rememberPttTarget(vm)
|
||||
VoiceBar(state, ptt.owner != null, ptt.talking, vm, server, onEnableMicrophone, showChat, chats.anyUnread) {
|
||||
showChat = !showChat
|
||||
}
|
||||
},
|
||||
@@ -444,7 +430,7 @@ private fun VoiceBar(
|
||||
}
|
||||
val middle = @Composable {
|
||||
when {
|
||||
ptt -> PushToTalk(talking, vm::setPushToTalk, Modifier.fillMaxWidth())
|
||||
ptt -> PushToTalk(talking, vm::setPushToTalk, Modifier.fillMaxWidth().height(48.dp))
|
||||
!state.micPermission -> FilledTonalButton(onClick = onEnableMicrophone) {
|
||||
PackIcon("CAPTURE", null)
|
||||
Text("Use microphone", Modifier.padding(start = 8.dp), maxLines = 1)
|
||||
@@ -503,32 +489,6 @@ private fun BarButton(onClick: () -> Unit, onLongClick: () -> Unit, enabled: Boo
|
||||
) { content() }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PushToTalk(talking: Boolean, onPressed: (Boolean) -> Unit, modifier: Modifier) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
Surface(
|
||||
modifier
|
||||
.height(48.dp)
|
||||
.pointerInput(Unit) {
|
||||
detectTapGestures(onPress = {
|
||||
onPressed(true)
|
||||
try {
|
||||
awaitRelease()
|
||||
} finally {
|
||||
onPressed(false)
|
||||
}
|
||||
})
|
||||
},
|
||||
shape = RoundedCornerShape(24.dp),
|
||||
color = if (talking) StatusColors.talking else colors.primaryContainer,
|
||||
contentColor = if (talking) Color.White else colors.onPrimaryContainer,
|
||||
) {
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
Text(if (talking) "Talking…" else "Hold to talk", style = MaterialTheme.typography.titleMedium)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The server's own icon, else the pack's server icon. */
|
||||
@Composable
|
||||
private fun ServerLogo(server: ServerController, modifier: Modifier = Modifier) {
|
||||
|
||||
@@ -21,7 +21,7 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
private enum class SettingsPage { SOUND, NETWORK, DESIGN, IDENTITIES, MY_TEAMSPEAK }
|
||||
private enum class SettingsPage { SOUND, NETWORK, GIANT_PTT, DESIGN, IDENTITIES, MY_TEAMSPEAK }
|
||||
|
||||
/**
|
||||
* The settings, by category. Every change is saved and put into effect at once,
|
||||
@@ -33,6 +33,7 @@ fun SettingsScreen(vm: SessionController, onContacts: () -> Unit, onBack: () ->
|
||||
when (page) {
|
||||
SettingsPage.SOUND -> return SoundSettingsScreen(vm, onBack = { page = null })
|
||||
SettingsPage.NETWORK -> return NetworkSettingsScreen(vm, onBack = { page = null })
|
||||
SettingsPage.GIANT_PTT -> return GiantPttScreen(vm, onBack = { page = null })
|
||||
SettingsPage.DESIGN -> return DesignScreen(vm, onBack = { page = null })
|
||||
SettingsPage.IDENTITIES -> return IdentitiesScreen(vm.identities, onBack = { page = null })
|
||||
SettingsPage.MY_TEAMSPEAK -> return MyTeamSpeakScreen(vm, onBack = { page = null })
|
||||
@@ -48,6 +49,9 @@ fun SettingsScreen(vm: SessionController, onContacts: () -> Unit, onBack: () ->
|
||||
LinkRow("Network", "Bitrate, error correction, redundancy, buffering", "PING_4") {
|
||||
page = SettingsPage.NETWORK
|
||||
}
|
||||
LinkRow("Giant PTT", "A push-to-talk button filling the screen", "CAPTURE") {
|
||||
page = SettingsPage.GIANT_PTT
|
||||
}
|
||||
LinkRow("Design", "Icon pack, country flags, description pictures", "GUISETUP") {
|
||||
page = SettingsPage.DESIGN
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user