Skip to content

Commit e2fda53

Browse files
author
Andrii Khrystian
committed
Initial
0 parents  commit e2fda53

38 files changed

+787
-0
lines changed

.gitignore

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

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
Trembita
2+
========
3+
4+
This tiny library base on annotation processing and ```kotlin-poet``` can help you to write Kotlin-style interfaces and make your
5+
code more readable. So lets check which problem it solves:
6+
7+
I'm sure you such interfaces in your code:
8+
9+
```kotlin
10+
interface Callback {
11+
fun success(response: String, code: Int)
12+
fun error(errorCode: Int)
13+
}
14+
```
15+
Then if you need to use it, probably you have something like this:
16+
```kotlin
17+
someClass.setCallback(object : Callback {
18+
override fun success(response: String, code: Int) {
19+
}
20+
override fun error(errorCode: Int) {
21+
}
22+
})
23+
```
24+
With `@Trembita` you could write more attractive interfaces. Here is an example:
25+
First that you need, just add `@Trembita` annotation to your interface
26+
```kotlin
27+
@Trembita
28+
interface Callback {
29+
fun success(response: String, code: Int)
30+
fun error(errorCode: Int)
31+
}
32+
```
33+
Then rebuild a project, and add method for interface initialization to class where you are going to use
34+
interface instance:
35+
```kotlin
36+
class SomeClass {
37+
38+
lateinit var callBack: Callback
39+
40+
fun setListener(init: TrembitaCallback.() -> Unit) {
41+
callBack = TrembitaCallback().apply(init)
42+
}
43+
44+
fun responseReceived() {
45+
callBack.success("response", 200)
46+
}
47+
}
48+
```
49+
So now your interface implementation will look like this:
50+
```kotlin
51+
someClass.setListener {
52+
success { response, code -> processResponse(response, code) }
53+
error { _ -> }
54+
}
55+
```
56+
Now you can use lambdas and the whole Kotlin power. One more important thing
57+
is that all methods are optional
58+
59+
**Problems that would be fixed in following releases**
60+
61+
- You should rebuild the project after adding `@Trembita` annotation
62+
- Library supports only methods that return `Unit`
63+
- Library does not support properties in interfaces
64+

build.gradle

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
buildscript {
2+
ext.kotlin_version = '1.2.30'
3+
repositories {
4+
jcenter()
5+
maven {
6+
url 'https://maven.google.com/'
7+
name 'Google'
8+
}
9+
}
10+
dependencies {
11+
classpath 'com.android.tools.build:gradle:2.3.2'
12+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13+
// NOTE: Do not place your application dependencies here; they belong
14+
// in the individual module build.gradle files
15+
}
16+
}
17+
18+
allprojects {
19+
repositories {
20+
jcenter()
21+
maven {
22+
url 'https://maven.google.com/'
23+
name 'Google'
24+
}
25+
}
26+
}
27+
28+
task clean(type: Delete) {
29+
delete rootProject.buildDir
30+
}

gradle.properties

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Project-wide Gradle settings.
2+
3+
# IDE (e.g. Android Studio) users:
4+
# Gradle settings configured through the IDE *will override*
5+
# any settings specified in this file.
6+
7+
# For more details on how to configure your build environment visit
8+
# http://www.gradle.org/docs/current/userguide/build_environment.html
9+
10+
# Specifies the JVM arguments used for the daemon process.
11+
# The setting is particularly useful for tweaking memory settings.
12+
org.gradle.jvmargs=-Xmx1536m
13+
14+
# When configured, Gradle will run in incubating parallel mode.
15+
# This option should only be used with decoupled projects. More details, visit
16+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17+
# org.gradle.parallel=true

gradle/wrapper/gradle-wrapper.jar

52.4 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Thu Jun 08 09:20:04 EET 2017
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

gradlew

Lines changed: 160 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 90 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ':trembita-sample', ':trembita-processor', ':trembita-annotations'

0 commit comments

Comments
 (0)