Skip to content

Commit

Permalink
feat: 插件 语言框可自定义显示名称
Browse files Browse the repository at this point in the history
  • Loading branch information
jing332 committed Jan 30, 2024
1 parent 1eed7d5 commit 9607173
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package com.github.jing332.tts_server_android.compose.codeeditor

import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
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.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.github.jing332.tts_server_android.R
Expand All @@ -17,21 +23,41 @@ import com.github.jing332.tts_server_android.conf.CodeEditorConfig

@Composable
internal fun RemoteSyncSettings(onDismissRequest: () -> Unit) {
AppDialog(title = { Text(stringResource(id = R.string.remote_sync_service)) }, content = {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(
stringResource(id = R.string.remote_sync_service_description),
modifier = Modifier.padding(8.dp)
)
AppDialog(
title = { Text(stringResource(id = R.string.remote_sync_service)) },
content = {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(
stringResource(id = R.string.remote_sync_service_description),
modifier = Modifier.padding(8.dp)
)

var port by remember { CodeEditorConfig.remoteSyncPort }
DenseOutlinedField(value = port.toString(), onValueChange = {
try {
port = it.toInt()
} catch (_: NumberFormatException) {
}
})
var port by remember { CodeEditorConfig.remoteSyncPort }
DenseOutlinedField(value = port.toString(), onValueChange = {
try {
port = it.toInt()
} catch (_: NumberFormatException) {
}
})

}
},
onDismissRequest = onDismissRequest,
buttons = {
val context = LocalContext.current
Row {
TextButton(onClick = {
context.startActivity(Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse("https://github.com/jing332/tts-server-psc")
})
}) {
Text(stringResource(id = R.string.learn_more))
}
Spacer(modifier = Modifier.weight(1f))
TextButton(onClick = onDismissRequest) {
Text(stringResource(id = R.string.close))
}
}
}
}, onDismissRequest = onDismissRequest)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.HelpOutline
import androidx.compose.material.icons.filled.Clear
import androidx.compose.material.icons.filled.SmartDisplay
import androidx.compose.material.icons.filled.Speed
import androidx.compose.material3.Checkbox
Expand Down Expand Up @@ -397,6 +398,14 @@ fun BasicInfoEditScreen(
.padding(top = 8.dp),
value = systts.displayName ?: "", onValueChange = {
onSysttsChange(systts.copy(displayName = it))
},
trailingIcon = {
if (systts.displayName?.isNotEmpty() == true)
IconButton(onClick = {
onSysttsChange(systts.copy(displayName = ""))
}) {
Icon(Icons.Default.Clear, stringResource(id = R.string.clear_text_content))
}
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -40,7 +39,6 @@ import com.github.jing332.tts_server_android.model.speech.tts.BaseAudioFormat
import com.github.jing332.tts_server_android.model.speech.tts.PluginTTS
import com.github.jing332.tts_server_android.ui.view.AppDialogs.displayErrorDialog
import kotlinx.coroutines.launch
import java.util.Locale

class PluginTtsUI : TtsUI() {
companion object {
Expand Down Expand Up @@ -239,8 +237,8 @@ class PluginTtsUI : TtsUI() {
.padding(top = 4.dp),
label = { Text(stringResource(id = R.string.language)) },
value = tts.locale,
values = vm.locales,
entries = vm.locales.map { Locale.forLanguageTag(it).displayName },
values = vm.locales.map { it.first },
entries = vm.locales.map { it.second },
onSelectedChange = { locale, _ ->
Log.d("PluginTtsUI", "locale onSelectedChange: $locale")
if (locale.toString().isBlank()) return@AppSpinner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.widget.LinearLayout
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.drake.net.utils.withIO
Expand All @@ -23,7 +24,7 @@ class PluginTtsViewModel : BaseViewModel() {

var isLoading by mutableStateOf(true)

val locales = mutableStateListOf<String>()
val locales = mutableStateListOf<Pair<String, String>>()
val voices = mutableStateListOf<Pair<String, String>>()

suspend fun load(context: Context, tts: PluginTTS, linearLayout: LinearLayout) {
Expand All @@ -45,7 +46,7 @@ class PluginTtsViewModel : BaseViewModel() {

private fun updateLocales() {
locales.clear()
locales.addAll(engine.getLocales())
locales.addAll(engine.getLocales().toList())
}

fun updateVoices(locale: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import android.widget.LinearLayout
import com.github.jing332.tts_server_android.constant.AppConst
import com.github.jing332.tts_server_android.model.speech.tts.PluginTTS
import com.github.jing332.tts_server_android.utils.dp
import org.mozilla.javascript.NativeMap
import org.mozilla.javascript.NativeObject
import java.util.Locale

class TtsPluginUiEngine(
private val pluginTts: PluginTTS,
Expand Down Expand Up @@ -72,11 +72,23 @@ class TtsPluginUiEngine(
}
}

@Suppress("UNCHECKED_CAST")
fun getLocales(): List<String> {
fun getLocales(): Map<String, String> {
return rhino.invokeMethod(editUiJsObject, FUNC_LOCALES).run {
if (this == null) emptyList()
else this as List<String>
when (this) {
is List<*> -> this.associate {
it.toString() to Locale.forLanguageTag(it.toString()).run {
this.getDisplayName(this)
}
}

is Map<*, *> -> {
this.map { (key, value) ->
key.toString() to value.toString()
}.toMap()
}

else -> emptyMap()
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@
<string name="tag_data">Tag data</string>
<string name="grant_permission_audio_file">Grant [Read Audio File Permission] </string>
<string name="grant_permission_storage_file">Grant [Read Storage File Permission] </string>
<string name="write_plugin_log_to_file">写入插件日志到文件</string>
<string name="write_plugin_log_to_file">Write plugin log to file</string>
<string name="add_shortcut_if_fail_tips">If that fails, grant the Add Shortcut permission</string>
<string name="clear_text_content">Clear the text</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,5 @@
<string name="grant_permission_storage_file">اعطا [مجوز خواندن فایل ذخیره‌سازی]</string>
<string name="write_plugin_log_to_file">لاگ افزونه را در فایل بنویسید</string>
<string name="add_shortcut_if_fail_tips">اگر ناموفق بود، لطفاً [اضافه کردن مجوز میانبر] را بدهید</string>
<string name="clear_text_content">清空文本内容</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,5 @@
<string name="grant_permission_storage_file">授予【读取存储文件权限】</string>
<string name="write_plugin_log_to_file">写入插件日志到文件</string>
<string name="add_shortcut_if_fail_tips">如果失败,请授予【添加快捷方式权限】</string>
<string name="clear_text_content">清空文本内容</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rHK/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,5 @@
<string name="grant_permission_storage_file">授予【读取存储文件权限】</string>
<string name="write_plugin_log_to_file">写入插件日志到文件</string>
<string name="add_shortcut_if_fail_tips">如果失败,请授予【添加快捷方式权限】</string>
<string name="clear_text_content">清空文本内容</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,5 @@
<string name="grant_permission_storage_file">授予【读取存储文件权限】</string>
<string name="write_plugin_log_to_file">写入插件日志到文件</string>
<string name="add_shortcut_if_fail_tips">如果失败,请授予【添加快捷方式权限】</string>
<string name="clear_text_content">清空文本内容</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -429,4 +429,5 @@
<string name="grant_permission_storage_file">授予【读取存储文件权限】</string>
<string name="write_plugin_log_to_file">写入插件日志到文件</string>
<string name="add_shortcut_if_fail_tips">如果失败,请授予【添加快捷方式权限】</string>
<string name="clear_text_content">清空文本内容</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -463,4 +463,5 @@
<string name="grant_permission_storage_file">授予【读取存储文件权限】</string>
<string name="write_plugin_log_to_file">写入插件日志到文件</string>
<string name="add_shortcut_if_fail_tips">如果失败,请授予【添加快捷方式权限】</string>
<string name="clear_text_content">清空文本内容</string>
</resources>
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ kotlin.incremental.java=true
kotlin.incremental.js=true
kotlin.caching.enabled=true
kotlin.parallel.tasks.in.project=true
#kotlin.experimental.tryK2=true

kotlin.experimental.tryK2=true
android.lint.useK2Uast=true
#kapt.incremental.apt=true
#kapt.include.compile.classpath=false

0 comments on commit 9607173

Please sign in to comment.