Skip to content

Commit

Permalink
feat: Implement dynamic colors in editor and improve treeview perform…
Browse files Browse the repository at this point in the history
…ance

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]>
  • Loading branch information
PranavPurwar committed Sep 9, 2024
1 parent fcdbe69 commit 7886eb0
Show file tree
Hide file tree
Showing 18 changed files with 300 additions and 264 deletions.
16 changes: 8 additions & 8 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -185,22 +185,22 @@ dependencies {
//noinspection GradleDependency
implementation("com.github.Cosmic-Ide:DependencyResolver:868996895a")
implementation("com.google.android.material:material:1.12.0")
implementation("com.google.code.gson:gson:2.10.1")
implementation("com.google.code.gson:gson:2.11.0")

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

implementation("androidx.appcompat:appcompat:1.7.0")
implementation("androidx.constraintlayout:constraintlayout:2.2.0-alpha14")
implementation("androidx.constraintlayout:constraintlayout:2.2.0-beta01")
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.core:core-splashscreen:1.1.0-rc01")
implementation("androidx.documentfile:documentfile:1.1.0-alpha01")
implementation("androidx.fragment:fragment-ktx:1.8.2")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.4")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.4")
implementation("androidx.fragment:fragment-ktx:1.8.3")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.5")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.5")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01")
implementation("androidx.viewpager2:viewpager2:1.1.0")
implementation("androidx.activity:activity-ktx:1.9.1")
implementation("androidx.startup:startup-runtime:1.2.0-alpha02")
implementation("androidx.activity:activity-ktx:1.9.2")
implementation("androidx.startup:startup-runtime:1.2.0-rc01")

val editorVersion = "0.23.4-96c0abc-SNAPSHOT"
//noinspection GradleDependency
Expand Down Expand Up @@ -255,7 +255,7 @@ dependencies {
implementation(projects.feature.treeView)

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

testImplementation("junit:junit:4.13.2")
}
Expand Down
19 changes: 9 additions & 10 deletions app/src/main/assets/textmate/QuietLight.tmTheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"name": "Keywords",
"scope": "keyword, storage",
"settings": {
"foreground": "#4B83CD"
"foreground": "#4B8ECD"
}
},
{
Expand Down Expand Up @@ -120,7 +120,7 @@
"name": "Numbers, Characters",
"scope": "constant.numeric, constant.character, constant",
"settings": {
"foreground": "#AB6526"
"foreground": "#888888"
}
},
{
Expand Down Expand Up @@ -171,14 +171,14 @@
},
{
"name": "HTML: Doctype Declaration",
"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 ",
"scope": "meta.tag.sgml.doctype, meta.tag.sgml.doctype string, meta.tag.sgml.doctype entity.name.tag, meta.tag.sgml punctuation.definition.tag.html",
"settings": {
"foreground": "#AAAAAA"
}
},
{
"name": "HTML: Tags",
"scope": "meta.tag, punctuation.definition.tag.html,\n punctuation.definition.tag.begin.html, punctuation.definition.tag.end.html\n ",
"scope": "meta.tag, punctuation.definition.tag.html, punctuation.definition.tag.begin.html, punctuation.definition.tag.end.html",
"settings": {
"foreground": "#91B3E0"
}
Expand Down Expand Up @@ -216,7 +216,7 @@
},
{
"name": "HTML: Attribute Names",
"scope": "meta.tag entity.other.attribute-name, entity.other.attribute-name.html\n ",
"scope": "meta.tag entity.other.attribute-name, entity.other.attribute-name.html",
"settings": {
"foreground": "#91B3E0"
}
Expand All @@ -234,7 +234,7 @@
},
{
"name": "CSS: Selectors",
"scope": "meta.selector, meta.selector entity, meta.selector entity punctuation,\n entity.name.tag.css\n ",
"scope": "meta.selector, meta.selector entity, meta.selector entity punctuation, entity.name.tag.css",
"settings": {
"foreground": "#7A3E9D"
}
Expand All @@ -248,7 +248,7 @@
},
{
"name": "CSS: Property Values",
"scope": "meta.property-value, meta.property-value constant.other,\n support.constant.property-value\n ",
"scope": "meta.property-value, meta.property-value constant.other, support.constant.property-value",
"settings": {
"foreground": "#448C27"
}
Expand Down Expand Up @@ -409,6 +409,5 @@
"foreground": "#434343"
}
}
],
"uuid": "231D6A91-5FD1-4CBE-BD2A-0F36C08693F1"
}
]
}
17 changes: 0 additions & 17 deletions app/src/main/kotlin/org/cosmicide/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import de.robv.android.xposed.XC_MethodHook
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.model.ThemeModel
import io.github.rosemoe.sora.langs.textmate.registry.provider.AssetsFileResolver
import org.cosmicide.common.Analytics
import org.cosmicide.common.Prefs
Expand All @@ -35,7 +34,6 @@ import org.cosmicide.rewrite.plugin.api.HookManager
import org.cosmicide.rewrite.plugin.api.PluginLoader
import org.cosmicide.rewrite.util.FileUtil
import org.cosmicide.util.CommonUtils
import org.eclipse.tm4e.core.registry.IThemeSource
import org.lsposed.hiddenapibypass.HiddenApiBypass
import rikka.sui.Sui
import java.io.File
Expand Down Expand Up @@ -67,7 +65,6 @@ class App : Application() {

if (FileUtil.isInitialized.not()) return

Log.d("Analytics", "Initializing")
Analytics.init(this@App)
Log.d("Analytics", "Sending event")

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

GrammarRegistry.getInstance().loadGrammars("textmate/languages.json")

val themeRegistry = ThemeRegistry.getInstance()
themeRegistry.loadTheme(loadTheme("darcula.json", "darcula"))
themeRegistry.loadTheme(loadTheme("QuietLight.tmTheme.json", "QuietLight"))

applyThemeBasedOnConfiguration()
}

private fun setupHooks() {
Expand Down Expand Up @@ -334,12 +325,4 @@ class App : Application() {
PluginLoader.loadPlugin(dir, plugin)
}
}

fun loadTheme(fileName: String, themeName: String): ThemeModel {
val inputStream =
FileProviderRegistry.getInstance().tryGetInputStream("textmate/$fileName")
?: throw FileNotFoundException("Theme file not found: $fileName")
val source = IThemeSource.fromInputStream(inputStream, fileName, null)
return ThemeModel(source, themeName)
}
}
23 changes: 22 additions & 1 deletion app/src/main/kotlin/org/cosmicide/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.commit
import androidx.lifecycle.lifecycleScope
import com.google.android.material.color.DynamicColors
import io.github.rosemoe.sora.langs.textmate.registry.ThemeRegistry
import io.github.rosemoe.sora.langs.textmate.registry.model.ThemeModel
import kotlinx.coroutines.launch
import org.cosmicide.common.Prefs
import org.cosmicide.databinding.ActivityMainBinding
import org.cosmicide.fragment.InstallResourcesFragment
import org.cosmicide.fragment.ProjectFragment
import org.cosmicide.util.CommonUtils
import org.cosmicide.util.MaterialEditorTheme
import org.cosmicide.util.ResourceUtil
import org.cosmicide.util.awaitBinderReceived
import org.cosmicide.util.isShizukuInstalled
import org.eclipse.tm4e.core.registry.IThemeSource
import rikka.shizuku.Shizuku
import rikka.shizuku.Shizuku.OnRequestPermissionResultListener
import rikka.shizuku.ShizukuProvider
Expand Down Expand Up @@ -64,6 +68,7 @@ class MainActivity : AppCompatActivity() {
binding = ActivityMainBinding.inflate(layoutInflater)

enableEdgeToEdge()
loadEditorThemes()

ViewCompat.setOnApplyWindowInsetsListener(binding.root) { view, windowInsets ->
val imeInset =
Expand Down Expand Up @@ -119,14 +124,30 @@ class MainActivity : AppCompatActivity() {
}
}

fun requestPermission() {
private fun requestPermission() {
if (Shizuku.isPreV11()) {
requestPermissions(arrayOf(ShizukuProvider.PERMISSION), shizukuPermissionCode)
} else {
Shizuku.requestPermission(shizukuPermissionCode)
}
}

private fun loadEditorThemes() {
val themeRegistry = ThemeRegistry.getInstance()
themeRegistry.loadTheme(loadTheme("darcula.json", "darcula"))
themeRegistry.loadTheme(loadTheme("QuietLight.tmTheme.json", "QuietLight"))

App.instance.get()!!.applyThemeBasedOnConfiguration()
}


private fun loadTheme(fileName: String, themeName: String): ThemeModel {
val inputStream =
MaterialEditorTheme.resolveTheme(this, fileName)
val source = IThemeSource.fromInputStream(inputStream, fileName, null)
return ThemeModel(source, themeName)
}

override fun onDestroy() {
super.onDestroy()
Shizuku.removeRequestPermissionResultListener(listener)
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/kotlin/org/cosmicide/editor/IdeEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import android.content.Context
import android.content.res.Configuration
import android.util.AttributeSet
import android.view.inputmethod.EditorInfo
import com.google.android.material.color.MaterialColors
import com.google.common.collect.ImmutableSet
import io.github.rosemoe.sora.langs.textmate.TextMateColorScheme
import io.github.rosemoe.sora.langs.textmate.registry.ThemeRegistry
import io.github.rosemoe.sora.widget.CodeEditor
import io.github.rosemoe.sora.widget.component.EditorDiagnosticTooltipWindow
import io.github.rosemoe.sora.widget.schemes.EditorColorScheme
import org.cosmicide.common.Prefs
import org.cosmicide.editor.language.TsLanguageJava
import org.cosmicide.extension.setCompletionLayout
Expand Down Expand Up @@ -102,7 +102,13 @@ class IdeEditor @JvmOverloads constructor(
private fun setTooltipImprovements() {
getComponent(EditorDiagnosticTooltipWindow::class.java).apply {
setSize(500, 100)
parentView.setBackgroundColor(colorScheme.getColor(EditorColorScheme.WHOLE_BACKGROUND))
parentView.setBackgroundColor(
MaterialColors.getColor(
context,
com.google.android.material.R.attr.colorErrorContainer,
null
)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import io.github.rosemoe.sora.editor.ts.predicate.builtin.MatchPredicate
import io.github.rosemoe.sora.lang.styling.TextStyle
import io.github.rosemoe.sora.widget.schemes.EditorColorScheme

object Util {
object TreeSitterUtil {
fun applyTheme(desc: TsThemeBuilder) {
desc.apply {
TextStyle.makeStyle(
Expand Down Expand Up @@ -95,4 +95,4 @@ object Util {
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ class TsLanguageJava(
project: Project,
file: File
) = TsLanguageJava(
Util.createLanguageSpec(
TreeSitterUtil.createLanguageSpec(
TS_LANGUAGE_JAVA,
editor.context.assets,
"java"
),
{ Util.applyTheme(it) },
{ TreeSitterUtil.applyTheme(it) },
editor,
project,
file
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/kotlin/org/cosmicide/extension/context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import android.content.ClipboardManager
import android.content.Context
import android.util.TypedValue
import androidx.core.content.ContextCompat
import com.google.android.material.color.MaterialColors
import okhttp3.internal.toHexString


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

fun Context.getDip(input: Float): Float {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, input, resources.displayMetrics)
}
}

fun Context.getDynamicColor(colorId: Int): String {
return "#" + MaterialColors.getColor(this, colorId, null).toHexString()
}
Loading

1 comment on commit 7886eb0

@HanzoDev1375
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😒

Please sign in to comment.