Skip to content

Commit

Permalink
fix: bgm & pluginTTS
Browse files Browse the repository at this point in the history
  • Loading branch information
jing332 committed Aug 25, 2023
1 parent 087dbca commit 3125392
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 399 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,15 @@ private fun NavHostScreen() {
val navController = rememberNavController()
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
val snackbarState = remember { SnackbarHostState() }
val gesturesEnabled = !drawerState.isClosed

CompositionLocalProvider(
LocalNavController provides navController,
LocalDrawerState provides drawerState,
) {
ModalNavigationDrawer(
drawerState = drawerState,
gesturesEnabled = NavRoutes.routes.find { it.id == navController.currentDestination?.route } != null,
gesturesEnabled = gesturesEnabled,
drawerContent = {
NavDrawerContent(
navController,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.github.jing332.tts_server_android.compose.nav

import androidx.annotation.StringRes
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.github.jing332.tts_server_android.R

sealed class NavRoutes(
Expand All @@ -25,12 +28,12 @@ sealed class NavRoutes(
}

data object SystemTTS : NavRoutes("system_tts", R.string.system_tts, icon = {
Icon(painter = painterResource(id = R.drawable.ic_tts), null)
Icon(modifier = Modifier.size(32.dp), painter = painterResource(id = R.drawable.ic_tts), contentDescription = null)
})

data object SystemTtsForwarder :
NavRoutes("system_tts_forwarder", R.string.forwarder_systts, icon = {
Icon(painter = painterResource(id = R.drawable.ic_tts), null)
Icon(modifier = Modifier.size(32.dp), painter = painterResource(id = R.drawable.ic_tts), contentDescription = null)
})

data object MsTtsForwarder : NavRoutes("ms_tts_forwarder", R.string.forwarder_ms, icon = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.lifecycle.viewmodel.compose.viewModel
import com.github.jing332.tts_server_android.R
import com.github.jing332.tts_server_android.compose.nav.LogScreen
import com.github.jing332.tts_server_android.compose.nav.NavTopAppBar
Expand All @@ -26,22 +27,20 @@ import com.github.jing332.tts_server_android.ui.AppLog
@Suppress("DEPRECATION")
@OptIn(ExperimentalMaterial3Api::class)
@Composable
internal fun TtsLogScreen() {
val list = remember { mutableStateListOf<AppLog>() }

internal fun TtsLogScreen(vm:TtsLogViewModel = viewModel()) {
LocalBroadcastReceiver(intentFilter = IntentFilter(SystemTtsService.ACTION_ON_LOG)) {
if (it?.action == SystemTtsService.ACTION_ON_LOG) {
it.getParcelableExtra<AppLog>(KeyConst.KEY_DATA)?.let { log ->
println("ACTION_ON_LOG ${log.msg}")
list.add(log)
vm.logs.add(log)
}
}
}

Scaffold(
topBar = {
NavTopAppBar(title = { Text(stringResource(id = R.string.log)) }, actions = {
IconButton(onClick = { /*TODO*/ }) {
IconButton(onClick = { vm.logs.clear() }) {
Icon(Icons.Default.DeleteOutline, stringResource(id = R.string.clear_log))
}
})
Expand All @@ -50,7 +49,7 @@ internal fun TtsLogScreen() {
LogScreen(
modifier = Modifier
.fillMaxSize()
.padding(top = paddingValues.calculateTopPadding()), list = list
.padding(top = paddingValues.calculateTopPadding()), list = vm.logs
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.github.jing332.tts_server_android.compose.nav.systts

import androidx.compose.runtime.mutableStateListOf
import androidx.lifecycle.ViewModel
import com.github.jing332.tts_server_android.ui.AppLog

class TtsLogViewModel : ViewModel() {
val logs = mutableStateListOf<AppLog>()
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.VerticalDivider
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
Expand All @@ -33,6 +34,8 @@ import com.github.jing332.tts_server_android.R
import com.github.jing332.tts_server_android.compose.nav.systts.edit.BasicInfoEditScreen
import com.github.jing332.tts_server_android.compose.nav.systts.edit.IntSlider
import com.github.jing332.tts_server_android.compose.nav.systts.edit.ui.base.TtsTopAppBar
import com.github.jing332.tts_server_android.constant.SpeechTarget
import com.github.jing332.tts_server_android.data.entities.systts.SpeechRuleInfo
import com.github.jing332.tts_server_android.data.entities.systts.SystemTts
import com.github.jing332.tts_server_android.model.speech.tts.BgmTTS
import com.github.jing332.tts_server_android.ui.AppActivityResultContracts
Expand All @@ -49,6 +52,10 @@ class BgmUI : TtsUI() {
onSysttsChange: (SystemTts) -> Unit
) {
val tts = systts.tts as BgmTTS
LaunchedEffect(Unit) {
onSysttsChange(systts.copy(speechRule = SpeechRuleInfo(target = SpeechTarget.BGM)))
}

val volStr = stringResource(id = R.string.label_speech_volume, tts.volume.toString())
IntSlider(label = volStr, value = tts.volume.toFloat(), onValueChange = {
onSysttsChange(systts.copy(tts = tts.copy(volume = it.toInt())))
Expand Down Expand Up @@ -100,7 +107,8 @@ class BgmUI : TtsUI() {
BasicInfoEditScreen(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 8.dp), systts = systts,
.padding(horizontal = 8.dp),
systts = systts,
saveEvent = saveSignal, onSysttsChange = onSysttsChange,
showSpeechTarget = false,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ class PluginTtsUI : TtsUI() {
tts = tts.copy(voice = key as String)
)
)
vm.onVoiceChanged(tts.locale, key)
runCatching {
vm.onVoiceChanged(tts.locale, key)
}.onFailure {
context.displayErrorDialog(it)
}

voiceName(name)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class PluginTtsViewModel : BaseViewModel() {
}

fun onVoiceChanged(locale: String, voice: String) {
engine.onVoiceChanged(locale, voice)
try {
engine.onVoiceChanged(locale, voice)
} catch (_: NoSuchMethodException) {
}
}
}
Loading

0 comments on commit 3125392

Please sign in to comment.