Skip to content

Commit

Permalink
fix: 分组下拉框无效
Browse files Browse the repository at this point in the history
  • Loading branch information
jing332 committed Aug 27, 2023
1 parent ea2431d commit e120cff
Show file tree
Hide file tree
Showing 34 changed files with 1,056 additions and 1,941 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
<data android:pathPattern=".*\\.ZIP" />
</intent-filter>
</activity>

<activity android:name=".compose.plugin.PluginManagerActivity" android:exported="true" />

<activity
android:name=".ui.FilePickerActivity"
android:theme="@style/TranslucentTheme" />
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/assets/defaultData/plugin-azure.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let region = ttsrv.userVars['region'] || 'eastus'

let format = "audio-24khz-48kbitrate-mono-mp3"
let sampleRate = 24000 // 对应24khz. 格式后带有opus的实际采样率是其2倍
let isNeedDecode = false // 是否需要解码,如 format 为 raw 请设为 true
let isNeedDecode = true // 是否需要解码,如 format 为 raw 请设为 false

let PluginJS = {
"name": "Azure",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jing332.tts_server_android.compose.nav.systts.list
package com.github.jing332.tts_server_android.compose

import android.view.HapticFeedbackConstants
import androidx.compose.animation.core.animateDpAsState
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.jing332.tts_server_android.compose.codeeditor

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.viewinterop.AndroidView
import com.github.jing332.text_searcher.ui.plugin.CodeEditorHelper
import com.github.jing332.tts_server_android.conf.CodeEditorConfig
import io.github.rosemoe.sora.widget.CodeEditor

@Composable
fun CodeEditor(modifier: Modifier, onUpdate: (CodeEditor) -> Unit) {
val context = LocalContext.current

AndroidView(modifier = modifier, factory = {
CodeEditor(it).apply {
val helper = CodeEditorHelper(context, this)
helper.initEditor()
tag = helper
}
}, update = {
val helper = (it.tag as CodeEditorHelper)
helper.setTheme(CodeEditorConfig.theme.value)
onUpdate(it)
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.github.jing332.text_searcher.ui.plugin

import android.content.Context
import android.content.res.Configuration
import com.github.jing332.tts_server_android.constant.CodeEditorTheme
import io.github.rosemoe.sora.langs.textmate.TextMateColorScheme
import io.github.rosemoe.sora.langs.textmate.TextMateLanguage
import io.github.rosemoe.sora.langs.textmate.registry.FileProviderRegistry
import io.github.rosemoe.sora.langs.textmate.registry.GrammarRegistry
import io.github.rosemoe.sora.langs.textmate.registry.ThemeRegistry
import io.github.rosemoe.sora.langs.textmate.registry.dsl.languages
import io.github.rosemoe.sora.langs.textmate.registry.model.ThemeModel
import io.github.rosemoe.sora.langs.textmate.registry.provider.AssetsFileResolver
import io.github.rosemoe.sora.widget.CodeEditor
import org.eclipse.tm4e.core.registry.IThemeSource


class CodeEditorHelper(val context: Context, val editor: CodeEditor) {
fun initEditor() {
FileProviderRegistry.getInstance().addFileProvider(AssetsFileResolver(context.assets))

val themes = arrayOf(
"textmate/quietlight.json",
"textmate/solarized_drak.json",
"textmate/darcula.json",
"textmate/abyss.json"
)
val themeRegistry = ThemeRegistry.getInstance()
for (theme in themes) {
themeRegistry.loadTheme(
ThemeModel(
IThemeSource.fromInputStream(
FileProviderRegistry.getInstance().tryGetInputStream(theme), theme, null
)
)
)
}

GrammarRegistry.getInstance().loadGrammars(languages {
language("js") {
grammar = "textmate/javascript/syntaxes/JavaScript.tmLanguage.json"
defaultScopeName()
languageConfiguration = "textmate/javascript/language-configuration.json"
}
})
editor.setEditorLanguage(TextMateLanguage.create("source.js", true))

}

fun setTheme(theme: CodeEditorTheme) {
val themeRegistry = ThemeRegistry.getInstance()
when (theme) {
CodeEditorTheme.AUTO -> {
val isNight =
(context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
setTheme(if (isNight) CodeEditorTheme.DARCULA else CodeEditorTheme.QUIET_LIGHT)
return
}

else-> {
themeRegistry.setTheme(theme.id)
ensureTextmateTheme()
return
}
}
}

private fun ensureTextmateTheme() {
var editorColorScheme = editor.colorScheme
if (editorColorScheme !is TextMateColorScheme) {
editorColorScheme = TextMateColorScheme.create(ThemeRegistry.getInstance())
editor.colorScheme = editorColorScheme
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package com.github.jing332.tts_server_android.compose.codeeditor

import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.BugReport
import androidx.compose.material.icons.filled.ColorLens
import androidx.compose.material.icons.filled.InsertDriveFile
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.filled.Save
import androidx.compose.material.icons.filled.SettingsRemote
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
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.res.stringResource
import com.github.jing332.tts_server_android.R
import com.github.jing332.tts_server_android.compose.widgets.CheckedMenuItem
import com.github.jing332.tts_server_android.conf.CodeEditorConfig
import io.github.rosemoe.sora.widget.CodeEditor

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CodeEditorScreen(
title: @Composable () -> Unit,
onBack: () -> Unit,
onDebug: () -> Unit,
onSave: () -> Unit,
onUpdate: (CodeEditor) -> Unit,

actions: @Composable ColumnScope.(dismiss: () -> Unit) -> Unit,
) {
Scaffold(
topBar = {
TopAppBar(title = title, navigationIcon = {
IconButton(onClick = onBack) {
Icon(
Icons.Filled.ArrowBack,
contentDescription = stringResource(id = R.string.nav_back)
)
}
},
actions = {
IconButton(onClick = onDebug) {
Icon(
Icons.Filled.BugReport,
contentDescription = stringResource(id = R.string.nav_back)
)
}
IconButton(onClick = onSave) {
Icon(
Icons.Filled.Save,
contentDescription = stringResource(id = R.string.nav_back)
)
}

var showOptions by remember { mutableStateOf(false) }

IconButton(onClick = { showOptions = true }) {
Icon(Icons.Default.MoreVert, stringResource(id = R.string.more_options))

DropdownMenu(
expanded = showOptions,
onDismissRequest = { showOptions = false }) {
DropdownMenuItem(
text = { Text(stringResource(id = R.string.save_as_file)) },
onClick = { /*TODO*/ },
leadingIcon = { Icon(Icons.Default.InsertDriveFile, null) }
)

var syncEnabled by remember { CodeEditorConfig.isRemoteSyncEnabled }
CheckedMenuItem(
text = { /*TODO*/ },
checked = syncEnabled,
onClick = {},
onClickCheckBox = { syncEnabled = it },
leadingIcon = {
Icon(Icons.Default.SettingsRemote, null)
}
)

HorizontalDivider()

DropdownMenuItem(
text = { Text(stringResource(id = R.string.theme)) },
onClick = {

},
leadingIcon = { Icon(Icons.Default.ColorLens, null) }
)

var wordWrap by remember { CodeEditorConfig.isWordWrapEnabled }
CheckedMenuItem(
text = { Text(stringResource(id = R.string.word_wrap)) },
checked = wordWrap,
onClick = { wordWrap = it },
leadingIcon = {
Icon(Icons.Default.ColorLens, null)
}
)

actions { showOptions = false }
}

}
}
)
}
) { paddingValues ->
CodeEditor(
modifier = Modifier
.fillMaxWidth()
.padding(paddingValues), onUpdate = onUpdate
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.github.jing332.text_searcher.ui.plugin

import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Text
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.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import com.github.jing332.tts_server_android.constant.LogLevel
import com.github.jing332.tts_server_android.model.rhino.core.Logger

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LoggerBottomSheet(
logger: Logger,
onDismissRequest: () -> Unit,
onLaunched: () -> Unit
) {
var logText by remember { mutableStateOf(AnnotatedString("")) }

val listener = remember {
Logger.LogListener { text, level ->
logText = buildAnnotatedString {
append(logText)
val color = LogLevel.toColor(level)
withStyle(SpanStyle(color = Color(color))) {
appendLine(text)
}
}
}
}

LaunchedEffect(logger) {
logger.addListener(listener)
onLaunched()
}

DisposableEffect(logger) {
onDispose {
logger.removeListener(listener)
}
}

ModalBottomSheet(onDismissRequest = onDismissRequest) {
SelectionContainer(modifier = Modifier.verticalScroll(rememberScrollState())) {
Text(
logText, modifier = Modifier
.fillMaxHeight()
.padding(horizontal = 8.dp)
.padding(bottom = 8.dp)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.github.jing332.tts_server_android.compose.codeeditor

import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import com.github.jing332.tts_server_android.R
import com.github.jing332.tts_server_android.compose.widgets.AppDialog

@Composable
fun EditorThemeSettingsDialog(onDismissRequest: () -> Unit) {
AppDialog(title = { Text(stringResource(id = R.string.theme)) },
content = {

}, buttons = {
TextButton(onClick = {
onDismissRequest()
}) {
Text(stringResource(id = R.string.close))
}
}) {
onDismissRequest()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccessTime
import androidx.compose.material.icons.filled.ArrowCircleUp
import androidx.compose.material.icons.filled.Audiotrack
import androidx.compose.material.icons.filled.ColorLens
import androidx.compose.material.icons.filled.FileOpen
import androidx.compose.material.icons.filled.Groups
import androidx.compose.material.icons.filled.Headset
Expand Down Expand Up @@ -108,7 +109,7 @@ fun SettingsScreen(drawerState: DrawerState) {
)

BasePreferenceWidget(
icon = { Icon(Icons.Default.Style, null) },
icon = { Icon(Icons.Default.ColorLens, null) },
onClick = { showThemeDialog = true },
title = { Text(stringResource(id = R.string.theme)) },
subTitle = { Text(stringResource(id = getAppTheme().stringResId)) },
Expand Down
Loading

0 comments on commit e120cff

Please sign in to comment.