update speech manager
This commit is contained in:
@@ -8,7 +8,7 @@ plugins {
|
|||||||
alias(libs.plugins.convention.serialization)
|
alias(libs.plugins.convention.serialization)
|
||||||
}
|
}
|
||||||
|
|
||||||
val appVersion = "1.0.3"
|
val appVersion = "1.0.4"
|
||||||
|
|
||||||
android {
|
android {
|
||||||
buildFeatures { buildConfig = true }
|
buildFeatures { buildConfig = true }
|
||||||
|
|||||||
+5
@@ -3,7 +3,9 @@ package ru.shadowsparky.gigawear.presentation
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.arkivanov.decompose.retainedComponent
|
import com.arkivanov.decompose.retainedComponent
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import org.koin.android.ext.android.inject
|
import org.koin.android.ext.android.inject
|
||||||
import ru.shadowsparky.gigawear.presentation.auth.AuthScreen
|
import ru.shadowsparky.gigawear.presentation.auth.AuthScreen
|
||||||
import ru.shadowsparky.gigawear.presentation.chat.ChatScreen
|
import ru.shadowsparky.gigawear.presentation.chat.ChatScreen
|
||||||
@@ -17,6 +19,9 @@ class MainActivity : ComponentActivity() {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
val root = retainedComponent { rootFactory.create(it) }
|
val root = retainedComponent { rootFactory.create(it) }
|
||||||
|
lifecycleScope.launch {
|
||||||
|
root.onFinish.collect { finishAffinity() }
|
||||||
|
}
|
||||||
setContent {
|
setContent {
|
||||||
Nav(root) { child, _ ->
|
Nav(root) { child, _ ->
|
||||||
when (child) {
|
when (child) {
|
||||||
|
|||||||
+22
-4
@@ -2,12 +2,13 @@ package ru.shadowsparky.gigawear.presentation.chat
|
|||||||
|
|
||||||
import com.arkivanov.decompose.ComponentContext
|
import com.arkivanov.decompose.ComponentContext
|
||||||
import com.arkivanov.decompose.childContext
|
import com.arkivanov.decompose.childContext
|
||||||
|
import com.arkivanov.essenty.backhandler.BackCallback
|
||||||
import com.arkivanov.essenty.lifecycle.coroutines.coroutineScope
|
import com.arkivanov.essenty.lifecycle.coroutines.coroutineScope
|
||||||
import com.arkivanov.essenty.lifecycle.doOnStart
|
import com.arkivanov.essenty.lifecycle.doOnStart
|
||||||
import com.arkivanov.essenty.lifecycle.doOnStop
|
|
||||||
import kotlinx.coroutines.CoroutineExceptionHandler
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
import kotlinx.coroutines.awaitCancellation
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
@@ -32,6 +33,7 @@ class ChatComponent(
|
|||||||
private val repository: ChatRepository,
|
private val repository: ChatRepository,
|
||||||
updateComponentFactory: UpdateComponentFactory,
|
updateComponentFactory: UpdateComponentFactory,
|
||||||
private val tokenStorage: TokenStorage,
|
private val tokenStorage: TokenStorage,
|
||||||
|
private val onBack: () -> Unit,
|
||||||
private val navigateToRouting: () -> Unit
|
private val navigateToRouting: () -> Unit
|
||||||
) : ComponentContext by context {
|
) : ComponentContext by context {
|
||||||
private val _state = MutableStateFlow(ChatUiState())
|
private val _state = MutableStateFlow(ChatUiState())
|
||||||
@@ -55,8 +57,23 @@ class ChatComponent(
|
|||||||
if (it == null) navigateToRouting()
|
if (it == null) navigateToRouting()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lifecycle.doOnStop {
|
registerBackCallback()
|
||||||
_state.update { it.copy(stopRequested = true) }
|
}
|
||||||
|
|
||||||
|
private fun registerBackCallback() {
|
||||||
|
scope.launch {
|
||||||
|
val backCallback = object : BackCallback() {
|
||||||
|
override fun onBack() {
|
||||||
|
_state.update { it.copy(stopRequested = true) }
|
||||||
|
onBack.invoke()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
backHandler.register(backCallback)
|
||||||
|
awaitCancellation()
|
||||||
|
} finally {
|
||||||
|
backHandler.unregister(backCallback)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +135,8 @@ class ChatComponentFactory(
|
|||||||
child,
|
child,
|
||||||
chatRepository,
|
chatRepository,
|
||||||
updateComponentFactory,
|
updateComponentFactory,
|
||||||
tokenStorage
|
tokenStorage,
|
||||||
|
onBack = { root.onBack() }
|
||||||
) { root.navReplace(Route.RoutingScreen()) }
|
) { root.navReplace(Route.RoutingScreen()) }
|
||||||
return Child.MainChild(component)
|
return Child.MainChild(component)
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -44,13 +44,18 @@ class SpeechManager(context: Context) {
|
|||||||
|
|
||||||
fun speak(text: String) {
|
fun speak(text: String) {
|
||||||
tts?.speak(
|
tts?.speak(
|
||||||
text,
|
filterText(text),
|
||||||
TextToSpeech.QUEUE_FLUSH,
|
TextToSpeech.QUEUE_FLUSH,
|
||||||
null,
|
null,
|
||||||
UTTERANCE_ID
|
UTTERANCE_ID
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun filterText(text: String): String =
|
||||||
|
text.replace(Regex("[^A-Za-zА-Яа-яЁё0-9\\s.,!?]"), "")
|
||||||
|
.replace(Regex("\\s+"), " ")
|
||||||
|
.trim()
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
tts?.stop()
|
tts?.stop()
|
||||||
resetSpeaking()
|
resetSpeaking()
|
||||||
|
|||||||
Reference in New Issue
Block a user