Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 923e29e

Browse files
author
Vadim Yaroschuk
authored
feat: added plugin loader (#32)
1 parent 6c5ded1 commit 923e29e

Some content is hidden

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

44 files changed

+742
-155
lines changed

‎app-core/build.gradle.kts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
2-
id("com.android.library")
3-
id("kotlin-android")
2+
id(Plugin.ANDROID_LIBRARY)
3+
id(Plugin.KOTLIN_ANDROID)
44
}
55

66
android {

‎app-core/src/main/java/com/codee/app/core/delegates/OneTimeSetDelegate.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal class OneTimeSetDelegate<T> : ReadWriteProperty<Any?, T> {
1515
}
1616

1717
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
18-
if(this.value == null)
18+
if(this.value == null)
1919
this.value = value
2020
}
2121
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.codee.app.core.exceptions
2+
3+
data class IncompatibleException(
4+
val declaredMinVersion: Int,
5+
val declaredMaxVersion: Int,
6+
val version: Int
7+
) : Exception("Impossible to run due to version incompatibility. " +
8+
"Accepted version: $declaredMinVersion - $declaredMaxVersion, current version - version")

‎app-core/src/main/java/com/codee/app/core/extensions/Colors.kt‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package com.codee.app.core.extensions
22

3-
import androidx.compose.foundation.isSystemInDarkTheme
43
import androidx.compose.material.Colors
5-
import androidx.compose.material.MaterialTheme
6-
import androidx.compose.runtime.Composable
74
import androidx.compose.runtime.mutableStateOf
8-
import androidx.compose.runtime.remember
95
import com.codee.app.resources.Color
106
import com.codee.app.resources.Hex
117
import com.codee.app.resources.RGB

‎app-core/src/main/java/com/codee/app/core/extensions/Localized.kt‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import androidx.core.os.ConfigurationCompat
44
import com.codee.app.core.ContextDI.context
55
import com.codee.app.resources.locale.Locale
66
import com.codee.app.resources.locale.Localized
7-
import com.codee.app.resources.locale.get
87

98

109
/**
@@ -18,11 +17,11 @@ fun <T> Localized<T>.localize(): T {
1817
// getLocales returns custom class, not list
1918
val locales = mutableListOf<Locale>().apply {
2019
val list = ConfigurationCompat.getLocales(context.resources.configuration)
21-
for(i in 0 until list.size())
20+
for(i in 1..list.size())
2221
add(list[i].toCodeeLocale())
2322
}
2423

25-
for(locale in locales) {
24+
for(locale in locales) {
2625
val languageCodeMatches = variants
2726
.filter { (k) -> k.languageCode == locale.languageCode }
2827
val countryCodeMatches = languageCodeMatches
@@ -32,7 +31,7 @@ fun <T> Localized<T>.localize(): T {
3231
?: languageCodeMatches.filter { (k) -> k.countryCode == null }.values.firstOrNull()
3332
?: languageCodeMatches.values.firstOrNull()
3433

35-
if(result != null)
34+
if(result != null)
3635
return result
3736
}
3837

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.codee.app.core.plugins
2+
3+
import com.codee.app.plugins.api.DependencyRepositoriesScope as IDependencyRepositoriesScope
4+
import com.codee.app.plugins.api.DependenciesScope as IDependenciesScope
5+
import com.codee.app.plugins.api.DependencyScope as IDependencyScope
6+
7+
class DependenciesScope : IDependenciesScope {
8+
9+
internal val dependencies: MutableList<Dependency> = mutableListOf()
10+
11+
override fun implementation(
12+
coordinates: String,
13+
block: IDependencyScope.() -> Unit
14+
) {
15+
val dependencyScope = DependencyScope()
16+
block(dependencyScope)
17+
dependencies.add(Dependency(coordinates, dependencyScope.repositories))
18+
}
19+
}
20+
21+
class DependencyScope : IDependencyScope {
22+
23+
internal val repositories: MutableList<String> = mutableListOf()
24+
25+
override fun repositories(block: IDependencyRepositoriesScope.() -> Unit) {
26+
repositories
27+
}
28+
29+
}
30+
31+
class DependencyRepositoriesScope(private val repositories: MutableList<String>) : IDependencyRepositoriesScope {
32+
override fun maven(coordinates: String) {
33+
repositories.add(coordinates)
34+
}
35+
}
36+
37+
class Dependency(
38+
val coordinates: String,
39+
val repositories: List<String>
40+
)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.codee.app.core.plugins
2+
3+
import com.codee.app.core.exceptions.IncompatibleException
4+
import com.codee.app.core.plugins.container.AppContainer
5+
import com.codee.app.plugins.api.CodeeCompatibilitySettingsScope
6+
import com.codee.app.plugins.api.DependenciesScope
7+
import com.codee.app.resources.locale.strings.LocalizedString
8+
import kotlin.properties.Delegates
9+
import com.codee.app.plugins.api.CodeeCompatibilitySettingsScope as ICodeeCompatibilitySettingsScope
10+
import com.codee.app.plugins.api.CodeeScope as ICodeeScope
11+
import com.codee.app.plugins.api.ManifestScope as IManifestScope
12+
13+
class ManifestScope : IManifestScope {
14+
override var name: LocalizedString by Delegates.notNull()
15+
override var author: String by Delegates.notNull()
16+
override var versionName: String by Delegates.notNull()
17+
override var versionCode: Int by Delegates.notNull()
18+
19+
private val codeeScope by lazy { CodeeScope() }
20+
private val dependenciesScope by lazy { DependenciesScope() }
21+
22+
val declaredDependencies: List<Dependency> get() = dependenciesScope.dependencies
23+
24+
override fun codee(block: ICodeeScope.() -> Unit) {
25+
block(codeeScope)
26+
}
27+
28+
override fun dependencies(block: DependenciesScope.() -> Unit) {
29+
block(dependenciesScope)
30+
}
31+
}
32+
33+
class CodeeScope : ICodeeScope {
34+
35+
private val compatibilitySettingsScope by lazy { CodeeCompatibilitySettingsScope() }
36+
37+
override fun compatibility(block: CodeeCompatibilitySettingsScope.() -> Unit) {
38+
block(compatibilitySettingsScope)
39+
val minVer = compatibilitySettingsScope.minCodeeVersion ?: AppContainer.versionCode
40+
val maxVer = compatibilitySettingsScope.maxCodeeVersion ?: AppContainer.versionCode
41+
if (minVer < AppContainer.versionCode || maxVer > AppContainer.versionCode)
42+
throw IncompatibleException(minVer, maxVer, AppContainer.versionCode)
43+
}
44+
}
45+
46+
class CodeeCompatibilitySettingsScope : ICodeeCompatibilitySettingsScope {
47+
override var minCodeeVersion: Int? = null
48+
override var maxCodeeVersion: Int? = null
49+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codee.app.core.plugins
2+
3+
class Plugin(
4+
val metadata: PluginMetadata,
5+
val scope: PluginScope
6+
)
7+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.codee.app.core.plugins
2+
3+
class PluginMetadata(
4+
val name: String,
5+
val author: String?,
6+
val versionName: String,
7+
val versionCode: Int
8+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.codee.app.core.plugins
2+
3+
class PluginOwned<T>(val owner: Plugin, val value: T)
4+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /