Skip to content
This repository was archived by the owner on Jun 14, 2025. It is now read-only.

Commit 7886eb0

Browse files
committed
feat: Implement dynamic colors in editor and improve treeview performance
This commit introduces dynamic theme colors to the editor and updates various dependencies to their latest versions. Specific changes include : - Added dynamic theme color support to the editor, applying appropriate colors for background, foreground, and caret based on the current system theme. - Updated several dependencies, including Gradle, AndroidX libraries, Material Design components, and Gson. - Refactored the TreeView component to use a more efficient data structure and improve performance. - Improved the editor's tooltip appearance by using a Material Design error container color for the background. - Added a new `TreeUtils` object to handle common tree operations. - Updated the `QuietLight` theme to use more consistent colors and remove unnecessary line breaks. - Renamed `Util.kt` to `TreeSitterUtil.kt` for better clarity. - Removed unused code and resources. - Updated the NDK version to 27.1.12297006. These changes enhance the editor's visual appeal, improve performance, and ensure compatibility with the latest libraries. Signed-off-by: Pranav Purwar <[email protected]>
1 parent fcdbe69 commit 7886eb0

File tree

18 files changed

+300
-264
lines changed

18 files changed

+300
-264
lines changed

app/build.gradle.kts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,22 +185,22 @@ dependencies {
185185
//noinspection GradleDependency
186186
implementation("com.github.Cosmic-Ide:DependencyResolver:868996895a")
187187
implementation("com.google.android.material:material:1.12.0")
188-
implementation("com.google.code.gson:gson:2.10.1")
188+
implementation("com.google.code.gson:gson:2.11.0")
189189

190190
implementation("com.github.haroldadmin:WhatTheStack:1.0.0-alpha04")
191191

192192
implementation("androidx.appcompat:appcompat:1.7.0")
193-
implementation("androidx.constraintlayout:constraintlayout:2.2.0-alpha14")
193+
implementation("androidx.constraintlayout:constraintlayout:2.2.0-beta01")
194194
implementation("androidx.core:core-ktx:1.13.1")
195195
implementation("androidx.core:core-splashscreen:1.1.0-rc01")
196196
implementation("androidx.documentfile:documentfile:1.1.0-alpha01")
197-
implementation("androidx.fragment:fragment-ktx:1.8.2")
198-
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.4")
199-
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.4")
197+
implementation("androidx.fragment:fragment-ktx:1.8.3")
198+
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.5")
199+
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.5")
200200
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01")
201201
implementation("androidx.viewpager2:viewpager2:1.1.0")
202-
implementation("androidx.activity:activity-ktx:1.9.1")
203-
implementation("androidx.startup:startup-runtime:1.2.0-alpha02")
202+
implementation("androidx.activity:activity-ktx:1.9.2")
203+
implementation("androidx.startup:startup-runtime:1.2.0-rc01")
204204

205205
val editorVersion = "0.23.4-96c0abc-SNAPSHOT"
206206
//noinspection GradleDependency
@@ -255,7 +255,7 @@ dependencies {
255255
implementation(projects.feature.treeView)
256256

257257
// jgit uses some methods like `transferTo` are only available from Android 13 onwards
258-
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
258+
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.2")
259259

260260
testImplementation("junit:junit:4.13.2")
261261
}

app/src/main/assets/textmate/QuietLight.tmTheme.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"name": "Keywords",
6363
"scope": "keyword, storage",
6464
"settings": {
65-
"foreground": "#4B83CD"
65+
"foreground": "#4B8ECD"
6666
}
6767
},
6868
{
@@ -120,7 +120,7 @@
120120
"name": "Numbers, Characters",
121121
"scope": "constant.numeric, constant.character, constant",
122122
"settings": {
123-
"foreground": "#AB6526"
123+
"foreground": "#888888"
124124
}
125125
},
126126
{
@@ -171,14 +171,14 @@
171171
},
172172
{
173173
"name": "HTML: Doctype Declaration",
174-
"scope": "meta.tag.sgml.doctype, meta.tag.sgml.doctype string, meta.tag.sgml.doctype\n entity.name.tag, meta.tag.sgml punctuation.definition.tag.html\n ",
174+
"scope": "meta.tag.sgml.doctype, meta.tag.sgml.doctype string, meta.tag.sgml.doctype entity.name.tag, meta.tag.sgml punctuation.definition.tag.html",
175175
"settings": {
176176
"foreground": "#AAAAAA"
177177
}
178178
},
179179
{
180180
"name": "HTML: Tags",
181-
"scope": "meta.tag, punctuation.definition.tag.html,\n punctuation.definition.tag.begin.html, punctuation.definition.tag.end.html\n ",
181+
"scope": "meta.tag, punctuation.definition.tag.html, punctuation.definition.tag.begin.html, punctuation.definition.tag.end.html",
182182
"settings": {
183183
"foreground": "#91B3E0"
184184
}
@@ -216,7 +216,7 @@
216216
},
217217
{
218218
"name": "HTML: Attribute Names",
219-
"scope": "meta.tag entity.other.attribute-name, entity.other.attribute-name.html\n ",
219+
"scope": "meta.tag entity.other.attribute-name, entity.other.attribute-name.html",
220220
"settings": {
221221
"foreground": "#91B3E0"
222222
}
@@ -234,7 +234,7 @@
234234
},
235235
{
236236
"name": "CSS: Selectors",
237-
"scope": "meta.selector, meta.selector entity, meta.selector entity punctuation,\n entity.name.tag.css\n ",
237+
"scope": "meta.selector, meta.selector entity, meta.selector entity punctuation, entity.name.tag.css",
238238
"settings": {
239239
"foreground": "#7A3E9D"
240240
}
@@ -248,7 +248,7 @@
248248
},
249249
{
250250
"name": "CSS: Property Values",
251-
"scope": "meta.property-value, meta.property-value constant.other,\n support.constant.property-value\n ",
251+
"scope": "meta.property-value, meta.property-value constant.other, support.constant.property-value",
252252
"settings": {
253253
"foreground": "#448C27"
254254
}
@@ -409,6 +409,5 @@
409409
"foreground": "#434343"
410410
}
411411
}
412-
],
413-
"uuid": "231D6A91-5FD1-4CBE-BD2A-0F36C08693F1"
414-
}
412+
]
413+
}

app/src/main/kotlin/org/cosmicide/App.kt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import de.robv.android.xposed.XC_MethodHook
2525
import io.github.rosemoe.sora.langs.textmate.registry.FileProviderRegistry
2626
import io.github.rosemoe.sora.langs.textmate.registry.GrammarRegistry
2727
import io.github.rosemoe.sora.langs.textmate.registry.ThemeRegistry
28-
import io.github.rosemoe.sora.langs.textmate.registry.model.ThemeModel
2928
import io.github.rosemoe.sora.langs.textmate.registry.provider.AssetsFileResolver
3029
import org.cosmicide.common.Analytics
3130
import org.cosmicide.common.Prefs
@@ -35,7 +34,6 @@ import org.cosmicide.rewrite.plugin.api.HookManager
3534
import org.cosmicide.rewrite.plugin.api.PluginLoader
3635
import org.cosmicide.rewrite.util.FileUtil
3736
import org.cosmicide.util.CommonUtils
38-
import org.eclipse.tm4e.core.registry.IThemeSource
3937
import org.lsposed.hiddenapibypass.HiddenApiBypass
4038
import rikka.sui.Sui
4139
import java.io.File
@@ -67,7 +65,6 @@ class App : Application() {
6765

6866
if (FileUtil.isInitialized.not()) return
6967

70-
Log.d("Analytics", "Initializing")
7168
Analytics.init(this@App)
7269
Log.d("Analytics", "Sending event")
7370

@@ -217,12 +214,6 @@ class App : Application() {
217214
FileProviderRegistry.getInstance().addFileProvider(fileProvider)
218215

219216
GrammarRegistry.getInstance().loadGrammars("textmate/languages.json")
220-
221-
val themeRegistry = ThemeRegistry.getInstance()
222-
themeRegistry.loadTheme(loadTheme("darcula.json", "darcula"))
223-
themeRegistry.loadTheme(loadTheme("QuietLight.tmTheme.json", "QuietLight"))
224-
225-
applyThemeBasedOnConfiguration()
226217
}
227218

228219
private fun setupHooks() {
@@ -334,12 +325,4 @@ class App : Application() {
334325
PluginLoader.loadPlugin(dir, plugin)
335326
}
336327
}
337-
338-
fun loadTheme(fileName: String, themeName: String): ThemeModel {
339-
val inputStream =
340-
FileProviderRegistry.getInstance().tryGetInputStream("textmate/$fileName")
341-
?: throw FileNotFoundException("Theme file not found: $fileName")
342-
val source = IThemeSource.fromInputStream(inputStream, fileName, null)
343-
return ThemeModel(source, themeName)
344-
}
345328
}

app/src/main/kotlin/org/cosmicide/MainActivity.kt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@ import androidx.core.view.WindowInsetsCompat
2020
import androidx.fragment.app.commit
2121
import androidx.lifecycle.lifecycleScope
2222
import com.google.android.material.color.DynamicColors
23+
import io.github.rosemoe.sora.langs.textmate.registry.ThemeRegistry
24+
import io.github.rosemoe.sora.langs.textmate.registry.model.ThemeModel
2325
import kotlinx.coroutines.launch
2426
import org.cosmicide.common.Prefs
2527
import org.cosmicide.databinding.ActivityMainBinding
2628
import org.cosmicide.fragment.InstallResourcesFragment
2729
import org.cosmicide.fragment.ProjectFragment
2830
import org.cosmicide.util.CommonUtils
31+
import org.cosmicide.util.MaterialEditorTheme
2932
import org.cosmicide.util.ResourceUtil
3033
import org.cosmicide.util.awaitBinderReceived
3134
import org.cosmicide.util.isShizukuInstalled
35+
import org.eclipse.tm4e.core.registry.IThemeSource
3236
import rikka.shizuku.Shizuku
3337
import rikka.shizuku.Shizuku.OnRequestPermissionResultListener
3438
import rikka.shizuku.ShizukuProvider
@@ -64,6 +68,7 @@ class MainActivity : AppCompatActivity() {
6468
binding = ActivityMainBinding.inflate(layoutInflater)
6569

6670
enableEdgeToEdge()
71+
loadEditorThemes()
6772

6873
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { view, windowInsets ->
6974
val imeInset =
@@ -119,14 +124,30 @@ class MainActivity : AppCompatActivity() {
119124
}
120125
}
121126

122-
fun requestPermission() {
127+
private fun requestPermission() {
123128
if (Shizuku.isPreV11()) {
124129
requestPermissions(arrayOf(ShizukuProvider.PERMISSION), shizukuPermissionCode)
125130
} else {
126131
Shizuku.requestPermission(shizukuPermissionCode)
127132
}
128133
}
129134

135+
private fun loadEditorThemes() {
136+
val themeRegistry = ThemeRegistry.getInstance()
137+
themeRegistry.loadTheme(loadTheme("darcula.json", "darcula"))
138+
themeRegistry.loadTheme(loadTheme("QuietLight.tmTheme.json", "QuietLight"))
139+
140+
App.instance.get()!!.applyThemeBasedOnConfiguration()
141+
}
142+
143+
144+
private fun loadTheme(fileName: String, themeName: String): ThemeModel {
145+
val inputStream =
146+
MaterialEditorTheme.resolveTheme(this, fileName)
147+
val source = IThemeSource.fromInputStream(inputStream, fileName, null)
148+
return ThemeModel(source, themeName)
149+
}
150+
130151
override fun onDestroy() {
131152
super.onDestroy()
132153
Shizuku.removeRequestPermissionResultListener(listener)

app/src/main/kotlin/org/cosmicide/editor/IdeEditor.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import android.content.Context
1111
import android.content.res.Configuration
1212
import android.util.AttributeSet
1313
import android.view.inputmethod.EditorInfo
14+
import com.google.android.material.color.MaterialColors
1415
import com.google.common.collect.ImmutableSet
1516
import io.github.rosemoe.sora.langs.textmate.TextMateColorScheme
1617
import io.github.rosemoe.sora.langs.textmate.registry.ThemeRegistry
1718
import io.github.rosemoe.sora.widget.CodeEditor
1819
import io.github.rosemoe.sora.widget.component.EditorDiagnosticTooltipWindow
19-
import io.github.rosemoe.sora.widget.schemes.EditorColorScheme
2020
import org.cosmicide.common.Prefs
2121
import org.cosmicide.editor.language.TsLanguageJava
2222
import org.cosmicide.extension.setCompletionLayout
@@ -102,7 +102,13 @@ class IdeEditor @JvmOverloads constructor(
102102
private fun setTooltipImprovements() {
103103
getComponent(EditorDiagnosticTooltipWindow::class.java).apply {
104104
setSize(500, 100)
105-
parentView.setBackgroundColor(colorScheme.getColor(EditorColorScheme.WHOLE_BACKGROUND))
105+
parentView.setBackgroundColor(
106+
MaterialColors.getColor(
107+
context,
108+
com.google.android.material.R.attr.colorErrorContainer,
109+
null
110+
)
111+
)
106112
}
107113
}
108114

app/src/main/kotlin/org/cosmicide/editor/language/Util.kt renamed to app/src/main/kotlin/org/cosmicide/editor/language/TreeSitterUtil.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import io.github.rosemoe.sora.editor.ts.predicate.builtin.MatchPredicate
1616
import io.github.rosemoe.sora.lang.styling.TextStyle
1717
import io.github.rosemoe.sora.widget.schemes.EditorColorScheme
1818

19-
object Util {
19+
object TreeSitterUtil {
2020
fun applyTheme(desc: TsThemeBuilder) {
2121
desc.apply {
2222
TextStyle.makeStyle(
@@ -95,4 +95,4 @@ object Util {
9595
)
9696
)
9797
}
98-
}
98+
}

app/src/main/kotlin/org/cosmicide/editor/language/TsLanguageJava.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ class TsLanguageJava(
172172
project: Project,
173173
file: File
174174
) = TsLanguageJava(
175-
Util.createLanguageSpec(
175+
TreeSitterUtil.createLanguageSpec(
176176
TS_LANGUAGE_JAVA,
177177
editor.context.assets,
178178
"java"
179179
),
180-
{ Util.applyTheme(it) },
180+
{ TreeSitterUtil.applyTheme(it) },
181181
editor,
182182
project,
183183
file

app/src/main/kotlin/org/cosmicide/extension/context.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import android.content.ClipboardManager
1212
import android.content.Context
1313
import android.util.TypedValue
1414
import androidx.core.content.ContextCompat
15+
import com.google.android.material.color.MaterialColors
16+
import okhttp3.internal.toHexString
17+
1518

1619
fun Context.copyToClipboard(text: String) {
1720
val clipboard = ContextCompat.getSystemService(this, ClipboardManager::class.java)!!
@@ -20,4 +23,8 @@ fun Context.copyToClipboard(text: String) {
2023

2124
fun Context.getDip(input: Float): Float {
2225
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, input, resources.displayMetrics)
23-
}
26+
}
27+
28+
fun Context.getDynamicColor(colorId: Int): String {
29+
return "#" + MaterialColors.getColor(this, colorId, null).toHexString()
30+
}

0 commit comments

Comments
 (0)