8000 update: added some examples · codee-team/codee-plugin-examples@dba3a10 · GitHub
[go: up one dir, main page]

Skip to content

Commit dba3a10

Browse files
committed
update: added some examples
1 parent fec8033 commit dba3a10

File tree

9 files changed

+213
-0
lines changed

9 files changed

+213
-0
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
.DS_Store
5+
/build
6+
/captures
7+
.externalNativeBuild
8+
.cxx
9+
local.properties
10+
/.idea
11+
/gradle
12+
gradlew
13+
gradlew.bat

build.gradle.kts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
buildscript {
3+
repositories {
4+
google()
5+
mavenCentral()
6+
}
7+
dependencies {
8+
classpath("com.android.tools.build:gradle:7.0.0-beta03")
9+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10")
10+
11+
// NOTE: Do not place your application dependencies here; they belong
12+
// in the individual module build.gradle.kts files
13+
}
14+
}
15+
16+
tasks.register("clean", Delete::class) {
17+
delete(rootProject.buildDir)
18+
}

examples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

examples/build.gradle.kts

Lines changed: 42 additions & 0 deletions
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+
buildToolsVersion = "30.0.3"
9+
10+
defaultConfig {
11+
minSdk = 21
12+
targetSdk = 30
13+
14+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
15+
}
16+
17+
buildTypes {
18+
release {
19+
isMinifyEnabled = false
20+
}
21+
}
22+
compileOptions {
23+
sourceCompatibility = JavaVersion.VERSION_1_8
24+
targetCompatibility = JavaVersion.VERSION_1_8
25+
}
26+
kotlinOptions {
27+
jvmTarget = "1.8"
28+
}
29+
}
30+
31+
dependencies {
32+
implementation("androidx.core:core-ktx:1.5.0")
33+
implementation("me.neon.codee:core:1.0.0")
34+
implementation(kotlin("reflect"))
35+
implementation(kotlin("script-util"))
36+
implementation(kotlin("scripting-compiler-embeddable"))
37+
implementation(
38+
group = "org.jetbrains.kotlin",
39+
name = "kotlin-scripting-dependencies",
40+
version = "1.4.32"
41+
)
42+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
@file:DependsOn("me.neon.codee:core:1.0.0")
2+
3+
import me.neon.codee.core.plugins.Plugin
4+
import me.neon.codee.core.plugins.api.registerPlugin
5+
import me.neon.codee.core.plugins.api.registerStrings
6+
import me.neon.codee.core.plugins.language.EnglishStrings
7+
import kotlin.script.experimental.dependencies.DependsOn
8+
9+
// defines plugin info
A93C 10+
object SimplePluginTest : Plugin {
11+
override val author: String = "Neon"
12+
override val dependsOn: List<String> = listOf()
13+
override val name: String = "TestLanguagePlugin"
14+
override val uuid: String = "neon-test-lang-plugin"
15+
override val version: String = "1.0"
16+
}
17+
18+
// defines our strings
19+
object MyStrings : EnglishStrings() {
20+
override val titleCreate: String = "Make"
21+
override val messageNoProjects: String = "No projects.. meh"
22+
}
23+
24+
// lets add our plugin to runtime:
25+
// registerPlugin returns Result<PluginContext>
26+
val result = registerPlugin(SimplePluginTest)
27+
// lets check it's success
28+
if(result.isSuccess) {
29+
// now it's safe to get context
30+
val context = result.getOrThrow()
31+
// lets register our translation:
32+
if(context.registerStrings("en", MyStrings))
33+
println("Successfully added!")
34+
else println("Some internal error happened")
35+
} else {
36+
println(result.exceptionOrNull())
37+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@file:DependsOn("me.neon.codee:core:1.0.0")
2+
package me.neon.codee.plugins.examples
3+
4+
import me.neon.codee.core.plugins.Plugin
5+
import me.neon.codee.core.plugins.api.registerPlugin
6+
import kotlin.script.experimental.dependencies.DependsOn
7+
8+
// defines plugin info
9+
object SimplePluginTest : Plugin {
10+
override val author: String = "Neon"
11+
override val dependsOn: List<String> = listOf()
12+
override val name: String = "TestTheme"
13+
override val uuid: String = "neon-test-simple-plugin"
14+
override val version: String = "1.0"
15+
}
16+
17+
// lets add our plugin to runtime:
18+
// registerPlugin returns Result<PluginContext>
19+
val result = registerPlugin(SimplePluginTest)
20+
// lets check it's success
21+
if(result.isSuccess) {
22+
// now it's safe to get context
23+
val context = result.getOrThrow()
24+
// TODO whatever you want
25+
} else {
26+
println(result.exceptionOrNull())
27+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@file:DependsOn("me.neon.codee:core:1.0.0")
2+
3+
import kotlinx.coroutines.runBlocking
4+
import me.neon.codee.core.plugins.Plugin
5+
import me.neon.codee.core.plugins.api.registerPlugin
6+
import me.neon.codee.core.plugins.api.registerTheme
7+
import me.neon.codee.core.plugins.api.removeTheme
8+
import me.neon.codee.core.plugins.api.themes
9+
import me.neon.codee.core.plugins.permissions.ForceThemeLanguageSetPermission
10+
import me.neon.codee.core.plugins.permissions.RemoveThemesPermission
11+
import me.neon.codee.core.plugins.theme.LightTheme
12+
import kotlin.script.experimental.dependencies.DependsOn
13+
14+
// defines plugin info
15+
object TestThemePlugin : Plugin {
16+
override val author: String = "Neon"
17+
override val dependsOn: List<String> = listOf()
18+
override val name: String = "TestTheme"
19+
override val uuid: String = "neon-test-theme-plugin"
20+
override val version: String = "1.0"
21+
}
22+
23+
// defines new theme. It is better to inherit `LightTheme` or `DarkTheme`
24+
// to avoid runtime errors when new fields will appear in `Theme`.
25+
object MyTheme : LightTheme() {
26+
override val primary: UInt = 0x000000u
27+
}
28+
29+
// registers a plugin to start working with the application
30+
val registerResult = registerPlugin(TestThemePlugin)
31+
32+
if(registerResult.isSuccess) {
33+
val context = registerResult.getOrThrow()
34+
context.registerTheme("My Theme", MyTheme)
35+
// Also, we can remove some registered theme:
36+
runBlocking {
37+
// calls user permission
38+
if(context.requestPermission(RemoveThemesPermission)) {
39+
// removes first theme in the list
40+
context.removeTheme(themes.first().name)
41+
}
42+
}
43+
} else error("Error while adding plugin")

gradle.properties

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Project-wide Gradle settings.
2+
# IDE (e.g. Android Studio) users:
3+
# Gradle settings configured through the IDE *will override*
4+
# any settings specified in this file.
5+
# For more details on how to configure your build environment visit
6+
# http://www.gradle.org/docs/current/userguide/build_environment.html
7+
# Specifies the JVM arguments used for the daemon process.
8+
# The setting is particularly useful for tweaking memory settings.
9+
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10+
# When configured, Gradle will run in incubating parallel mode.
11+
# This option should only be used with decoupled projects. More details, visit
12+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13+
# org.gradle.parallel=true
14+
# AndroidX package structure to make it clearer which packages are bundled with the
15+
# Android operating system, and which are packaged with your app"s APK
16+
# https://developer.android.com/topic/libraries/support-library/androidx-rn
17+
android.useAndroidX=true
18+
# Automatically convert third-party libraries to use AndroidX
19+
android.enableJetifier=true
20+
# Kotlin code style for this project: "official" or "obsolete":
21+
kotlin.code.style=official

settings.gradle.kts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
dependencyResolutionManagement {
2+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
3+
repositories {
4+
google()
5+
mavenCentral()
6+
maven("https://maven.kotlingang.fun")
7+
}
8+
}
9+
rootProject.name = "My Application"
10+
include(":examples")
11+

0 commit comments

Comments
 (0)
0