Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 4b3e205

Browse files
Vadim Kotlinovy9san9
Vadim Kotlinov
andauthored
Plugins implementations (#23)
* update: removed unnecessary permission * update: added new API * fix: fix error with classpath * refactor: removed unnecessary files * refactor: removed permissions due to it's unnecessary * refactor: removed permissions due to it's unnecessary * refactor: removed plugin storage * feat: added files API for plugins * feat: implementing settings and strings * refactor: strings improved; settings implementations done; * refactor: removed unnecessary files * fix: added `Dispatchers.IO` to suspend functions * update: some API rewritten * refactor&feat: `Locale` renamed into `Language` & added * fix: removed unnecessary import * refactor: MutableValue and Value removed due to unnecessary * feat: added metadata builder to setup plugin name, author and version * refactor: removed unnecessary imports & `Locale` -> `Language` * refactor: removed everything from `plugin-api`& `core` & `app` * refactor: `core` renamed into `app-resouces` * feat: added `app-resources` module with app resources * refactor: `plugin-api` renamed into `plugins-api` * chore: added .gitignore * refactor&chore: some unnecessary implementations removed & little changes * style: code style optimization * refactor: `app-resources` renamed to `resources` * upd: added `app-core` module with data for `app` * refactor&feat: added localization (on half) * refactor&feat: `com.codee.application.resouces` renamed to `com.codee.app.resources` & added interfaces to access application / plugins * refactor: removed unnecessary imports * refactor: removed old implementation in `app-core` * feat: related to #21 * update: api updated * feat: added `@SinceApi(version)` annotation * fix: invalid import * refactor: removed duplicate `LocalizedString` typealias * update: removed emojis & updated description * refactor: removed `plugins-core` module * fix: import fixed * refactor: removed some unnecessary stuff * update: `plugins-api` updated * update: api rewritten * refactor: code reformat * feat: `metadata` in dsl-way * refactor: removed unnecessary `localizations` * feat: `plugins-api` implementation * update: some ui * feat: added `Color` * update: added `MainView` Co-authored-by: Alex Sokol <[email protected]>
1 parent 20b7cb7 commit 4b3e205

File tree

70 files changed

+1471
-373
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1471
-373
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
[![Hits-of-Code](https://hitsofcode.com/github/codee-team/codee-app)](https://hitsofcode.com/github/codee-team/codee-app/view) ![Issues](https://img.shields.io/github/issues/codee-team/codee-app) ![GitHub pull requests](https://img.shields.io/github/issues-pr/codee-team/codee-app)
22
# Codee App
3-
Codee (**Code** **e**ditor) - Mobile IDE for developing Kotlin, Java and other projects. Fully written on Kotlin!
4-
## 🚀 Motivation
3+
Codee (**Code** **e**ditor) - Kotlin-first IDE for android devices written in Kotlin with plugins support.
4+
## Motivation
55
There are currently no good and flexible development environments for Android-based mobile devices, so this application will have to solve this problem.
6-
## 📐 Plugins
6+
## Plugins
77
All plugins are powered by Kotlin Script. So far we have only made a small prototype API that does almost nothing in the [plugin-api](plugin-api). Plugin examples you can see [here](https://github.com/codee-team/codee-plugin-examples) (not actual for now, there is example with old API).
8-
## 💡 TODO
8+
## TODO
99
- Convenient and flexible API for plugins
1010
- Clear and beautiful interface
1111
- Code editor without lags (as much as possible)
1212
- Default plugins for Kotlin & Java
1313
- Gradle support (as plugin)
14-
## 📖 License
14+
## License
1515
This application is absolutely free and using [MIT](https://github.com/codee-team/codee-app/blob/master/LICENSE) license.
1616

17-
## ✉️ Contacts
17+
## Contacts
1818
- <a href="https://t.me/codee_feed"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/82/Telegram_logo.svg/768px-Telegram_logo.svg.png" width=16 height=16 /> Telegram Channel</a>
1919
- <a href="https://t.me/codee_chat"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/82/Telegram_logo.svg/768px-Telegram_logo.svg.png" width=16 height=16 /> Telegram Chat</a>
2020
- <a href="https://github.com/codee-team/codee-app/issues"><img src="https://user-images.githubusercontent.com/32961194/122037088-ebf2f700-cddc-11eb-9052-78e964c680f5.png" width=16 height=16 style="background: green;"/> Github Issues</a>
File renamed without changes.

app-core/build.gradle.kts

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
plugins {
2+
id("com.android.library")
3+
id("kotlin-android")
4+
}
5+
6+
android {
7+
compileSdk = 30
8+
9+
defaultConfig {
10+
minSdk = 21
11+
targetSdk = 30
12+
13+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
14+
consumerProguardFiles("consumer-rules.pro")
15+
}
16+
17+
buildTypes {
18+
release {
19+
proguardFiles(
20+
getDefaultProguardFile("proguard-android-optimize.txt"),
21+
"proguard-rules.pro"
22+
)
23+
}
24+
}
25+
compileOptions {
26+
sourceCompatibility = JavaVersion.VERSION_1_8
27+
targetCompatibility = JavaVersion.VERSION_1_8
28+
}
29+
kotlinOptions {
30+
jvmTarget = "1.8"
31+
}
32+
}
33+
34+
dependencies {
35+
implementation(androidKtCore)
36+
implementation(appCompat)
37+
implementation(material)
38+
implementation(composeUI)
39+
implementation(composeMaterial)
40+
implementation(resources)
41+
implementation(pluginsAPI)
42+
}
File renamed without changes.

core/proguard-rules.pro renamed to app-core/proguard-rules.pro

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Add project specific ProGuard rules here.
22
# You can control the set of applied configuration files using the
3-
# proguardFiles setting in build.gradle.
3+
# proguardFiles setting in build.gradle.kts.
44
#
55
# For more details, see
66
# http://developer.android.com/guide/developing/tools/proguard.html
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest package="com.codee.core">
2+
<manifest package="com.codee.app.core">
33

44
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.codee.app.core.delegates
2+
3+
import kotlin.properties.ReadWriteProperty
4+
import kotlin.reflect.KProperty
5+
6+
internal fun <T> oneTimeSet(): OneTimeSetDelegate<T> =
7+
OneTimeSetDelegate()
8+
9+
internal class OneTimeSetDelegate<T> : ReadWriteProperty<Any?, T> {
10+
private var value: T? = null
11+
12+
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
13+
return value
14+
?: throw NullPointerException("${property.name} is not initialized yet. Initialize it before get.")
15+
}
16+
17+
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
18+
if(this.value == null)
19+
this.value = value
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.codee.app.core.extensions
2+
3+
import androidx.compose.foundation.isSystemInDarkTheme
4+
import androidx.compose.material.Colors
5+
import androidx.compose.material.MaterialTheme
6+
import androidx.compose.runtime.Composable
7+
import androidx.compose.runtime.mutableStateOf
8+
import androidx.compose.runtime.remember
9+
import com.codee.app.resources.Color
10+
import com.codee.app.resources.Hex
11+
import com.codee.app.resources.RGB
12+
import com.codee.app.resources.theme.DarkThemeColors
13+
import com.codee.app.resources.theme.LightThemeColors
14+
import com.codee.app.resources.theme.ThemeColors
15+
import android.graphics.Color as AndroidColor
16+
import androidx.compose.ui.graphics.Color as ComposeColor
17+
18+
/**
19+
* Light theme colors.
20+
*/
21+
val lightThemeColors = mutableStateOf(LightThemeColors().toComposeColors())
22+
23+
/**
24+
* Dark theme colors.
25+
*/
26+
val darkThemeColors = mutableStateOf(DarkThemeColors().toComposeColors())
27+
28+
internal fun ThemeColors.toComposeColors() = Colors(
29+
primary.toComposeColor(),
30+
primaryVariant.toComposeColor(),
31+
secondary.toComposeColor(),
32+
secondaryVariant.toComposeColor(),
33+
background.toComposeColor(),
34+
surface.toComposeColor(),
35+
error.toComposeColor(),
36+
onPrimary.toComposeColor(),
37+
onSecondary.toComposeColor(),
38+
onBackground.toComposeColor(),
39+
onSurface.toComposeColor(),
40+
onError.toComposeColor(),
41+
this is LightThemeColors
42+
)
43+
44+
internal fun Color.toComposeColor() = when (this) {
45+
is Hex -> ComposeColor(AndroidColor.parseColor(hex))
46+
is RGB -> ComposeColor(AndroidColor.rgb(red, green, blue))
47+
}
48+
49+
/**
50+
* Compose representation of codee theme.
51+
*/
52+
@Composable
53+
fun CodeeTheme(
54+
darkTheme: Boolean = isSystemInDarkTheme(),
55+
content: @Composable () -> Unit
56+
) = MaterialTheme(
57+
colors = if (darkTheme) remember { darkThemeColors.value }
58+
else remember { lightThemeColors.value },
59+
content = content
60+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.codee.app.core.plugins
2+
3+
import com.codee.app.core.delegates.oneTimeSet
4+
import com.codee.app.core.extensions.darkThemeColors
5+
import com.codee.app.core.extensions.lightThemeColors
6+
import com.codee.app.core.extensions.toComposeColors
7+
import com.codee.app.plugins.api.Plugin
8+
import com.codee.app.plugins.api.PluginApi
9+
import com.codee.app.plugins.api.PluginLocalization
10+
import com.codee.app.plugins.api.manager.AppManager
11+
import com.codee.app.plugins.api.manager.PluginApiManager
12+
import com.codee.app.plugins.api.manager.PluginLocalizationManager
13+
import com.codee.app.plugins.api.manager.ThemeManager
14+
import com.codee.app.plugins.api.objects.PluginMetadata
15+
import com.codee.app.resources.locale.Locale
16+
import com.codee.app.resources.theme.DarkThemeColors
17+
import com.codee.app.resources.theme.LightThemeColors
18+
import kotlinx.coroutines.flow.MutableSharedFlow
19+
20+
class Plugin : Plugin {
21+
override var metadata: PluginMetadata by oneTimeSet()
22+
override val app: AppManager = AppManager
23+
override val apiManager: PluginApiManager = PluginApiManager
24+
override val localizationManager: PluginLocalizationManager = PluginLocalizationManager
25+
}
26+
27+
private object PluginApiManager : PluginApiManager {
28+
override val apis: MutableSharedFlow<PluginApi> = MutableSharedFlow()
29+
30+
override fun <T : PluginApi> register(instance: T): Boolean {
31+
return if (apis.replayCache.any {
32+
it.compatibilitySettings.currentVersion ==
33+
instance.compatibilitySettings.currentVersion
34+
})
35+
true
36+
else apis.tryEmit(instance)
37+
}
38+
39+
}
40+
41+
private object PluginLocalizationManager : PluginLocalizationManager {
42+
override val localizations: MutableSharedFlow<PluginLocalization> = MutableSharedFlow()
43+
44+
override fun <T : PluginLocalization> register(instance: T): Boolean {
45+
return if (localizations.replayCache.any {
46+
it.compatibilitySettings.currentVersion ==
47+
instance.compatibilitySettings.currentVersion
48+
})
49+
true
50+
else localizations.tryEmit(instance)
51+
}
52+
}
53+
54+
private object AppManager : AppManager {
55+
override val versionName: String = "1.0"
56+
override val versionCode: Int = 1
57+
override val locale: Locale = Locale.en
58+
override val themeManager: ThemeManager = ThemeManager
59+
}
60+
61+
private object ThemeManager : ThemeManager {
62+
override var currentLightThemeColors: LightThemeColors = LightThemeColors()
63+
set(value) {
64+
lightThemeColors.value = value.toComposeColors()
65+
field = value
66+
}
67+
override var currentDarkThemeColors: DarkThemeColors = DarkThemeColors()
68+
set(value) {
69+
darkThemeColors.value = value.toComposeColors()
70+
field = value
71+
}
72+
}

app/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ dependencies {
5353
implementation(composeUITooling)
5454
implementation(androidxLifecycle)
5555
implementation(activityCompose)
56-
implementation(codeeCore)
57-
implementation(scriptingDependencies)
5856
implementation(coroutines)
57+
implementation(`app-core`)
58+
implementation(composeNav)
5959
testImplementation(jUnit)
6060
androidTestImplementation(composeJUNIT)
6161
}

app/proguard-rules.pro

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Add project specific ProGuard rules here.
22
# You can control the set of applied configuration files using the
3-
# proguardFiles setting in build.gradle.
3+
# proguardFiles setting in build.gradle.kts.kts.
44
#
55
# For more details, see
66
# http://developer.android.com/guide/developing/tools/proguard.html

app/src/main/AndroidManifest.xml

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
package="com.codee">
44

55
<application
6+
android:name=".app.App"
67
android:allowBackup="true"
8+
android:fullBackupContent="@xml/backup_descriptor"
79
android:icon="@mipmap/ic_launcher"
810
android:label="@string/app_name"
911
android:roundIcon="@mipmap/ic_launcher_round"
1012
android:supportsRtl="true"
11-
android:theme="@style/Theme.Codee"
12-
android:fullBackupContent="@xml/backup_descriptor">
13+
android:theme="@style/Theme.Codee">
1314
<activity
1415
android:name=".app.MainActivity"
1516
android:exported="true"
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.codee.app
2+
3+
import android.app.Application
4+
5+
class App : Application() {
6+
override fun onCreate() {
7+
super.onCreate()
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.codee.app
2+
3+
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.compose.setContent
6+
import androidx.navigation.compose.rememberNavController
7+
import com.codee.app.core.extensions.CodeeTheme
8+
import com.codee.app.screens.main.MainView
9+
10+
class AppActivity : ComponentActivity() {
11+
override fun onCreate(savedInstanceState: Bundle?) {
12+
super.onCreate(savedInstanceState)
13+
setContent {
14+
CodeeTheme {
15+
MainView(rememberNavController())
16+
}
17+
}
18+
}
19+
}

app/src/main/java/com/codee/app/MainActivity.kt

-28
This file was deleted.

app/src/main/java/com/codee/app/StringsComposable.kt

-26
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.codee.app.screens.main
2+
3+
import androidx.compose.foundation.layout.fillMaxSize
4+
import androidx.compose.material.Scaffold
5+
import androidx.compose.material.Surface
6+
import androidx.compose.runtime.Composable
7+
import androidx.compose.ui.Modifier
8+
import androidx.navigation.NavHostController
9+
import androidx.navigation.compose.NavHost
10+
import androidx.navigation.compose.composable
11+
12+
@Composable
13+
fun MainView(navController: NavHostController) = NavHost(
14+
navController = navController,
15+
startDestination = "projects",
16+
modifier = Modifier.fillMaxSize()
17+
) {
18+
composable("projects") {
19+
20+
}
21+
}

0 commit comments

Comments
 (0)