-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
1,056 additions
and
1,941 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../nav/systts/list/ShadowReorderableItem.kt → ..._android/compose/ShadowReorderableItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/github/jing332/tts_server_android/compose/codeeditor/CodeEditor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} |
76 changes: 76 additions & 0 deletions
76
...rc/main/java/com/github/jing332/tts_server_android/compose/codeeditor/CodeEditorHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
|
||
} |
129 changes: 129 additions & 0 deletions
129
...rc/main/java/com/github/jing332/tts_server_android/compose/codeeditor/CodeEditorScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...c/main/java/com/github/jing332/tts_server_android/compose/codeeditor/LoggerBottomSheet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...main/java/com/github/jing332/tts_server_android/compose/codeeditor/ThemeSettingsDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.