mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 14:26:00 +00:00
feat(wow): voice type and keyboard chat bar for World of Warcraft (#2171)
* Add voice and keyboard chat input for World of Warcraft Open a chat bar with an editable text field when a WoW client focuses a text box (reported by Proton's winex11 IME context hook through agent/wine-ime.json). First use asks for Voice type or Android keyboard with a remember toggle; the choice is also in the side menu's Keyboard group while a WoW client runs. Voice type uses the device's speech recognition service. On dual-screen devices the bar and keyboard open on the second screen. Send types the text and presses Enter; Cancel presses Escape. * Cover the Arm64 WoW client in the chat match test * Give the second-screen chat bar the session's result and back owners * Open the WoW chat bar with the game field's current text When the bar opens, select and copy the game's text field and fill the bar with it through the session clipboard bridge, then put the guest clipboard back. Send selects the field first, so the bar's text replaces what was there instead of being appended. * Keep WoW chat consistent across screen changes and failed field reads Close the bar when the game field closes even after the program name is cleared, move the bar to the top screen when the second screen drops it, and drop any pending second-screen keyboard request when the bar opens. A field read that gets no copy of its own leaves the game text unselected and Send then types without replacing it. Ctrl is only pressed and released when nothing else holds it, and a pending read ends when the clipboard bridge stops. * fix(session): Close WoW chat for other programs and keep the game cursor on cancelled reads
This commit is contained in:
1 parent
a1bc8467fd
commit
6060f2288f
45 files changed
+785
-67
No files matched your search
@@ -11,6 +11,7 @@ import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -110,7 +111,16 @@ internal class BottomScreenTextInput(private val fallback: TextInputService) : P
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun TypingPanel(request: TypingRequest, onDone: () -> Unit) {
|
||||
internal fun TypingPanel(
|
||||
request: TypingRequest,
|
||||
modifier: Modifier = Modifier.fillMaxSize(),
|
||||
title: String = stringResource(R.string.dual_typing_title),
|
||||
done: String = stringResource(R.string.dual_typing_done),
|
||||
onCancel: (() -> Unit)? = null,
|
||||
leading: (@Composable () -> Unit)? = null,
|
||||
showKeyboard: Boolean = true,
|
||||
onDone: () -> Unit,
|
||||
) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
var field by remember(request) { mutableStateOf(request.value) }
|
||||
LaunchedEffect(request.value) {
|
||||
@@ -120,19 +130,22 @@ internal fun TypingPanel(request: TypingRequest, onDone: () -> Unit) {
|
||||
val keyboard = LocalSoftwareKeyboardController.current
|
||||
LaunchedEffect(request) {
|
||||
kotlinx.coroutines.delay(120)
|
||||
if (!showKeyboard) return@LaunchedEffect
|
||||
runCatching { focus.requestFocus() }
|
||||
keyboard?.show()
|
||||
}
|
||||
val options = request.imeOptions
|
||||
val secret = options.keyboardType == KeyboardType.Password || options.keyboardType == KeyboardType.NumberPassword
|
||||
Column(
|
||||
Modifier.fillMaxSize().background(colors.background).padding(horizontal = 20.dp, vertical = 14.dp),
|
||||
modifier.background(colors.background).padding(horizontal = 20.dp, vertical = 14.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
) {
|
||||
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(stringResource(R.string.dual_typing_title), fontSize = 15.sp, fontWeight = FontWeight.SemiBold,
|
||||
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
leading?.invoke()
|
||||
Text(title, fontSize = 15.sp, fontWeight = FontWeight.SemiBold,
|
||||
color = colors.onSurfaceVariant, modifier = Modifier.weight(1f))
|
||||
Button(onClick = onDone, modifier = Modifier.testTag("dual-typing-done")) { Text(stringResource(R.string.dual_typing_done)) }
|
||||
if (onCancel != null) OutlinedButton(onClick = onCancel, modifier = Modifier.testTag("dual-typing-cancel")) { Text(stringResource(R.string.common_cancel)) }
|
||||
Button(onClick = onDone, modifier = Modifier.testTag("dual-typing-done")) { Text(done) }
|
||||
}
|
||||
OutlinedTextField(
|
||||
value = field,
|
||||
|
||||
@@ -56,6 +56,7 @@ import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.rotate
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.focus.focusProperties
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.semantics.Role
|
||||
@@ -150,6 +151,27 @@ internal fun Chip(t: String, ok: Boolean) {
|
||||
@Composable
|
||||
internal fun rememberHot(src: MutableInteractionSource): Boolean = src.collectIsFocusedAsState().value || src.collectIsHoveredAsState().value
|
||||
|
||||
@Composable
|
||||
internal fun DialogToggleRow(label: String, checked: Boolean, onChange: (Boolean) -> Unit) {
|
||||
val pal = LocalPalette.current
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src)
|
||||
val flip = { onChange(!checked) }
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp),
|
||||
modifier = Modifier.fillMaxWidth().clip(Shape12)
|
||||
.background(if (hot) pal.signal.copy(alpha = 0.12f) else Color.Transparent)
|
||||
.border(if (hot) 2.dp else 1.dp, if (hot) pal.signal else pal.line, Shape12)
|
||||
.hoverable(src)
|
||||
.clickable(interactionSource = src, indication = null, role = Role.Switch, onClick = flip)
|
||||
.controllerConfirm(onClick = flip)
|
||||
.padding(start = 14.dp, end = 4.dp),
|
||||
) {
|
||||
Text(label, fontSize = 14.sp, color = MaterialTheme.colorScheme.onBackground, modifier = Modifier.weight(1f))
|
||||
ToggleSwitch(checked, label = label, modifier = Modifier.focusProperties { canFocus = false }) { onChange(it) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun PrimaryButton(
|
||||
text: String,
|
||||
|
||||
@@ -46,6 +46,8 @@ class SecondScreenPresentation(
|
||||
private val frame = FrameLayout(context)
|
||||
private var menuView: androidx.compose.ui.platform.ComposeView? = null
|
||||
private var dashboardView: androidx.compose.ui.platform.ComposeView? = null
|
||||
private var chatView: androidx.compose.ui.platform.ComposeView? = null
|
||||
private var chatLost: (() -> Unit)? = null
|
||||
var menuShown = false
|
||||
private set
|
||||
private val root = LinearLayout(context).apply {
|
||||
@@ -78,7 +80,7 @@ class SecondScreenPresentation(
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
root.setOnApplyWindowInsetsListener { view, insets ->
|
||||
if (insets.isVisible(WindowInsets.Type.ime())) imeSeen = true
|
||||
else if (imeSeen) keyboardClosed()
|
||||
else if (imeSeen && chatView == null) keyboardClosed()
|
||||
view.onApplyWindowInsets(insets)
|
||||
}
|
||||
}
|
||||
@@ -128,6 +130,37 @@ class SecondScreenPresentation(
|
||||
if (created && isShowing && currentMode == SecondScreenMode.TERMINAL && terminalPanel?.ready != true) renderMode()
|
||||
}
|
||||
|
||||
fun showChat(onLost: () -> Unit, content: @androidx.compose.runtime.Composable () -> Unit) {
|
||||
if (!showsKeyboard || chatView != null) return
|
||||
keyboardHost?.takeIf { it.shown }?.hide()
|
||||
keyboardShown.value = false
|
||||
keyboardPending = false
|
||||
fieldKeyboard = false
|
||||
chatLost = onLost
|
||||
ownComposeViews()
|
||||
val view = androidx.compose.ui.platform.ComposeView(context).apply {
|
||||
isFocusable = true
|
||||
isFocusableInTouchMode = true
|
||||
setContent { content() }
|
||||
}
|
||||
chatView = view
|
||||
root.addView(view, 1.coerceAtMost(root.childCount), LinearLayout.LayoutParams(-1, -2))
|
||||
}
|
||||
|
||||
fun hideChat() {
|
||||
chatLost = null
|
||||
dropChat()
|
||||
}
|
||||
|
||||
private fun dropChat() {
|
||||
val view = chatView ?: return
|
||||
chatView = null
|
||||
chatLost?.let { lost -> chatLost = null; sessionActivity.runOnUiThread(lost) }
|
||||
imeSeen = false
|
||||
root.removeView(view)
|
||||
view.disposeComposition()
|
||||
}
|
||||
|
||||
val showsKeyboard: Boolean get() = isShowing && !menuShown && currentMode == SecondScreenMode.KEYBOARD_TRACKPAD
|
||||
|
||||
val showsControls: Boolean get() = isShowing && currentMode != SecondScreenMode.NONE
|
||||
@@ -178,6 +211,7 @@ class SecondScreenPresentation(
|
||||
showMenu(false)
|
||||
closeDashboard()
|
||||
closeTerminal()
|
||||
dropChat()
|
||||
keyboardHost?.hide()
|
||||
keyboardHost = null
|
||||
dismiss()
|
||||
@@ -212,6 +246,7 @@ class SecondScreenPresentation(
|
||||
}
|
||||
|
||||
private fun renderMode() {
|
||||
dropChat()
|
||||
fieldKeyboard = false
|
||||
keyboardHost?.hide()
|
||||
keyboardHost = null
|
||||
|
||||
@@ -264,6 +264,9 @@ class DrawerActions(
|
||||
val onImportLossless: () -> Unit,
|
||||
val onKeyboard: () -> Unit,
|
||||
val onHardwareKeyboard: () -> Unit,
|
||||
val wowChatShown: Boolean = false,
|
||||
val wowChat: String? = null,
|
||||
val onWowChat: (String?) -> Unit = {},
|
||||
val onSteamMenu: (() -> Unit)?,
|
||||
val onQam: (() -> Unit)?,
|
||||
val onAchievements: (() -> Unit)? = null,
|
||||
@@ -698,6 +701,15 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
host.open = null; a.onKeyboard()
|
||||
}
|
||||
}
|
||||
if (a.wowChatShown) ChoiceRow(
|
||||
host, "wow-chat", stringResource(R.string.wow_chat_title), null,
|
||||
listOf(
|
||||
null to stringResource(R.string.wow_chat_ask),
|
||||
SessionPrefs.WOW_CHAT_VOICE to stringResource(R.string.wow_chat_voice),
|
||||
SessionPrefs.WOW_CHAT_KEYBOARD to stringResource(R.string.pckb_android),
|
||||
),
|
||||
a.wowChat, chipModifier = focus.track(page, "wow-chat"), onPick = a.onWowChat,
|
||||
)
|
||||
val keyboardContext = LocalContext.current
|
||||
remember { PcKeyboardPrefs.load(keyboardContext) }
|
||||
SliderRow(
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.hoverable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Usb
|
||||
@@ -18,12 +12,7 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.focus.focusProperties
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -48,23 +37,7 @@ internal fun SlowUsbDialog(drive: UsbLink.SlowDrive, never: Boolean, onNever: (B
|
||||
stringResource(message, drive.name, UsbLink.generation(drive.mbps), speed, UsbLink.megabytesPerSecond(drive.mbps)),
|
||||
fontSize = 13.sp, lineHeight = 18.sp, color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
val pal = LocalPalette.current
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src)
|
||||
val flip = { onNever(!never) }
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp),
|
||||
modifier = Modifier.fillMaxWidth().clip(Shape12)
|
||||
.background(if (hot) pal.signal.copy(alpha = 0.12f) else Color.Transparent)
|
||||
.border(if (hot) 2.dp else 1.dp, if (hot) pal.signal else pal.line, Shape12)
|
||||
.hoverable(src)
|
||||
.clickable(interactionSource = src, indication = null, role = Role.Switch, onClick = flip)
|
||||
.controllerConfirm(onClick = flip)
|
||||
.padding(start = 14.dp, end = 4.dp),
|
||||
) {
|
||||
Text(stringResource(R.string.slow_usb_never), fontSize = 14.sp, color = MaterialTheme.colorScheme.onBackground, modifier = Modifier.weight(1f))
|
||||
ToggleSwitch(never, label = stringResource(R.string.slow_usb_never), modifier = Modifier.focusProperties { canFocus = false }) { onNever(it) }
|
||||
}
|
||||
DialogToggleRow(stringResource(R.string.slow_usb_never), never, onNever)
|
||||
Row(horizontalArrangement = Arrangement.End, modifier = Modifier.fillMaxWidth()) {
|
||||
PrimaryButton(stringResource(R.string.slow_usb_dismiss), modifier = Modifier.focusRequester(focus), onClick = close)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.speech.RecognitionListener
|
||||
import android.speech.RecognizerIntent
|
||||
import android.speech.SpeechRecognizer
|
||||
import android.widget.Toast
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Mic
|
||||
import androidx.compose.material3.FilledIconToggleButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.TextRange
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.ImeOptions
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
|
||||
class WowChat(
|
||||
private val context: Context,
|
||||
private val onSend: (String, Boolean) -> Unit,
|
||||
private val onCancel: () -> Unit,
|
||||
private val readField: ((String?) -> Unit) -> Unit = {},
|
||||
) {
|
||||
var request by mutableStateOf<TypingRequest?>(null)
|
||||
private set
|
||||
var asking by mutableStateOf(false)
|
||||
private set
|
||||
var listening by mutableStateOf(false)
|
||||
private set
|
||||
var voice by mutableStateOf(false)
|
||||
private set
|
||||
var remembered by mutableStateOf(SessionPrefs.wowChatInput(context))
|
||||
private set
|
||||
private var recognizer: SpeechRecognizer? = null
|
||||
private var spokenBase = ""
|
||||
private var fieldRead = false
|
||||
|
||||
val open: Boolean get() = request != null || asking
|
||||
|
||||
fun chatOpened() {
|
||||
if (open) return
|
||||
when (val mode = remembered) {
|
||||
null -> asking = true
|
||||
else -> start(mode)
|
||||
}
|
||||
}
|
||||
|
||||
fun chatClosed() {
|
||||
asking = false
|
||||
finish()
|
||||
}
|
||||
|
||||
fun pick(mode: String, remember: Boolean) {
|
||||
asking = false
|
||||
if (remember) choose(mode)
|
||||
start(mode)
|
||||
}
|
||||
|
||||
fun choose(mode: String?) {
|
||||
SessionPrefs.setWowChatInput(context, mode)
|
||||
remembered = SessionPrefs.wowChatInput(context)
|
||||
}
|
||||
|
||||
fun dismissChoice() {
|
||||
asking = false
|
||||
onCancel()
|
||||
}
|
||||
|
||||
fun send() {
|
||||
val text = request?.value?.text.orEmpty()
|
||||
val replace = fieldRead
|
||||
finish()
|
||||
onSend(text, replace)
|
||||
}
|
||||
|
||||
fun cancel() {
|
||||
finish()
|
||||
onCancel()
|
||||
}
|
||||
|
||||
private fun start(mode: String) {
|
||||
voice = mode == SessionPrefs.WOW_CHAT_VOICE && voiceAvailable(context)
|
||||
if (mode == SessionPrefs.WOW_CHAT_VOICE && !voice) Toast.makeText(context, R.string.wow_chat_voice_unavailable, Toast.LENGTH_SHORT).show()
|
||||
val opened = TypingRequest(TextFieldValue(""), ImeOptions(singleLine = true, imeAction = ImeAction.Send), {}, {})
|
||||
fieldRead = false
|
||||
request = opened
|
||||
readField { text ->
|
||||
if (request === opened && !text.isNullOrEmpty() && opened.value.text.isEmpty()) {
|
||||
fieldRead = true
|
||||
opened.value = TextFieldValue(text, TextRange(text.length))
|
||||
if (recognizer != null) spokenBase = "${text.trimEnd()} "
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun finish() {
|
||||
stopListening()
|
||||
request = null
|
||||
voice = false
|
||||
}
|
||||
|
||||
fun listen() {
|
||||
val active = request ?: return
|
||||
stopListening()
|
||||
val speech = runCatching { SpeechRecognizer.createSpeechRecognizer(context) }.getOrNull() ?: return
|
||||
recognizer = speech
|
||||
spokenBase = active.value.text.trimEnd().let { if (it.isEmpty()) it else "$it " }
|
||||
speech.setRecognitionListener(object : RecognitionListener {
|
||||
override fun onReadyForSpeech(params: Bundle?) { listening = true }
|
||||
override fun onBeginningOfSpeech() {}
|
||||
override fun onRmsChanged(rmsdB: Float) {}
|
||||
override fun onBufferReceived(buffer: ByteArray?) {}
|
||||
override fun onEndOfSpeech() {}
|
||||
override fun onError(error: Int) { if (recognizer === speech) stopListening() }
|
||||
override fun onResults(results: Bundle?) {
|
||||
if (recognizer !== speech) return
|
||||
heard(results)
|
||||
stopListening()
|
||||
}
|
||||
override fun onPartialResults(partialResults: Bundle?) { if (recognizer === speech) heard(partialResults) }
|
||||
override fun onEvent(eventType: Int, params: Bundle?) {}
|
||||
})
|
||||
val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
|
||||
.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
|
||||
.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true)
|
||||
.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, context.packageName)
|
||||
runCatching { speech.startListening(intent) }.onFailure { stopListening() }
|
||||
}
|
||||
|
||||
private fun heard(results: Bundle?) {
|
||||
val spoken = results?.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)?.firstOrNull()?.takeIf { it.isNotBlank() } ?: return
|
||||
val text = spokenBase + spoken
|
||||
request?.value = TextFieldValue(text, TextRange(text.length))
|
||||
}
|
||||
|
||||
fun stopListening() {
|
||||
listening = false
|
||||
val speech = recognizer ?: return
|
||||
recognizer = null
|
||||
runCatching { speech.cancel() }
|
||||
runCatching { speech.destroy() }
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val PROGRAM = Regex("wow[\\w-]*\\.exe", RegexOption.IGNORE_CASE)
|
||||
|
||||
fun isWow(program: String?): Boolean = program != null && PROGRAM.matches(program)
|
||||
|
||||
fun voiceAvailable(context: Context): Boolean = SpeechRecognizer.isRecognitionAvailable(context)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun WowChatPanel(chat: WowChat, modifier: Modifier = Modifier.fillMaxWidth()) {
|
||||
val request = chat.request ?: return
|
||||
val context = LocalContext.current
|
||||
val mic = rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) { granted ->
|
||||
if (granted) chat.listen() else Toast.makeText(context, R.string.wow_chat_mic_denied, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
val listen = {
|
||||
if (context.checkSelfPermission(Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) chat.listen()
|
||||
else mic.launch(Manifest.permission.RECORD_AUDIO)
|
||||
}
|
||||
LaunchedEffect(request) { if (chat.voice) listen() }
|
||||
DisposableEffect(request) { onDispose { chat.stopListening() } }
|
||||
BackHandler(onBack = chat::cancel)
|
||||
TypingPanel(
|
||||
request, modifier,
|
||||
title = stringResource(if (chat.listening) R.string.wow_chat_listening else R.string.wow_chat_title),
|
||||
done = stringResource(R.string.wow_chat_send),
|
||||
onCancel = chat::cancel,
|
||||
showKeyboard = !chat.voice,
|
||||
leading = if (WowChat.voiceAvailable(context)) ({
|
||||
FilledIconToggleButton(
|
||||
checked = chat.listening,
|
||||
onCheckedChange = { on -> if (on) listen() else chat.stopListening() },
|
||||
modifier = Modifier.testTag("wow-chat-mic"),
|
||||
) { Icon(Icons.Filled.Mic, stringResource(R.string.wow_chat_voice)) }
|
||||
}) else null,
|
||||
onDone = chat::send,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun WowChatChoiceDialog(chat: WowChat) {
|
||||
var remember by remember { mutableStateOf(true) }
|
||||
var picked by remember { mutableStateOf<String?>(null) }
|
||||
val shown = rememberShown {
|
||||
val mode = picked
|
||||
if (mode != null) chat.pick(mode, remember) else chat.dismissChoice()
|
||||
}
|
||||
val close = { shown.targetState = false }
|
||||
val choose = { mode: String -> picked = mode; close() }
|
||||
val focus = remember { FocusRequester() }
|
||||
LaunchedEffect(Unit) { runCatching { focus.requestFocus() } }
|
||||
AppDialog(shown, close, "wowChat", wide = false, maxWidth = 520.dp) {
|
||||
DialogTitleRow(stringResource(R.string.wow_chat_title), close)
|
||||
DialogToggleRow(stringResource(R.string.wow_chat_remember), remember) { remember = it }
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp, androidx.compose.ui.Alignment.End), modifier = Modifier.fillMaxWidth()) {
|
||||
SecondaryButton(stringResource(R.string.pckb_android), modifier = Modifier.testTag("wow-chat-keyboard")) { choose(SessionPrefs.WOW_CHAT_KEYBOARD) }
|
||||
PrimaryButton(stringResource(R.string.wow_chat_voice), icon = Icons.Filled.Mic,
|
||||
modifier = Modifier.focusRequester(focus).testTag("wow-chat-voice")) { choose(SessionPrefs.WOW_CHAT_VOICE) }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user