Skip to content

Commit d61ac03

Browse files
committed
v0.2
1 parent ae120cd commit d61ac03

File tree

16 files changed

+157
-121
lines changed

16 files changed

+157
-121
lines changed

README.md

+13-43
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[ ![Download](https://api.bintray.com/packages/efff/maven/RotorKotlinDatabase/images/download.svg) ](https://bintray.com/efff/maven/RotorKotlinDatabase/_latestVersion)
2-
<p align="center"><img width="10%" vspace="20" src="https://github.com/rotorlab/database-kotlin/raw/develop/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png"></p>
3-
2+
<p align="center"><img width="10%" vspace="20" src="https://github.com/rotorlab/database-kotlin/raw/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png"></p>
3+
4+
Before use this library, [Rotor Core](https://github.com/rotorlab/core-kotlin) must be initialized. Lastest version is always the same on all Rotor libs.
5+
46
# Rotor Database
57
Rotor Database is a complementary module for Rotor Core (kotlin). It allows to work with shared (Java) objects between many devices offering users real time changes and better mobile data consumption.
68

@@ -10,8 +12,6 @@ Forget things like swipe-to-refresh events, lots of server requests and object s
1012

1113
Rotor Core is connected to Rotor and Redis servers. The first one controls object sharing queues, devices waiting for changes and all data edition on remote database. The second (as you probably know) gives us Pub/Sub messaging pattern for data changes replication.
1214

13-
Before use this lib, check out [Rotor Core repo](https://github.com/rotorlab/core-kotlin) for its initialization.
14-
1515
## Implementation
1616
Import libraries:
1717

@@ -22,7 +22,7 @@ android {
2222
}
2323
}
2424
25-
def rotor_version = "0.1.2"
25+
def rotor_version = "0.2"
2626
2727
dependencies {
2828
implementation ("com.rotor:core:$rotor_version@aar") {
@@ -35,7 +35,7 @@ dependencies {
3535
```
3636
Initialize database module after Rotor core initialization. Should be invoked on `LoadingActivity` or `SplashActivity`. :
3737
```java
38-
Rotor.initialize(getApplicationContext(), "http://10.0.2.2:1507/", "redis://10.0.2.2", new StatusListener() {
38+
Rotor.initialize(getApplicationContext(), "http://10.0.2.2:1508/", "redis://10.0.2.2", new StatusListener() {
3939
@Override
4040
public void connected() {
4141
Database.initialize()
@@ -56,7 +56,7 @@ For that we have `Database.listen(...)` method which has a simple **object lifec
5656

5757
```kotlin
5858
// kotlin
59-
Database.listen(path: String, Reference<T>(T::class.java) {
59+
Database.listen(database: String, path: String, Reference<T>(T::class.java) {
6060

6161
fun onCreate()
6262

@@ -128,9 +128,10 @@ Database.remove("myObjects/objectA");
128128
```
129129
Samples:
130130
```java
131-
// java
132-
131+
133132
class ObjectA {
133+
@SerializedName("value")
134+
@Expose
134135
String value;
135136
public ObjectA(String value) {
136137
this.value = value;
@@ -143,10 +144,11 @@ class ObjectA {
143144
}
144145
}
145146

146-
String path = "myObjects/objectA";
147+
String database = "database";
148+
String path = "/myObjects/objectA";
147149
ObjectA objectA = null;
148150

149-
Database.listen(path, new Reference<ObjectA>(ObjectA.class) {
151+
Database.listen(database, path, new Reference<ObjectA>(ObjectA.class) {
150152
@Override
151153
public void onCreate() {
152154
objectA = new ObjectA("foo");
@@ -177,38 +179,6 @@ Database.listen(path, new Reference<ObjectA>(ObjectA.class) {
177179
});
178180
```
179181

180-
```kotlin
181-
// kotlin
182-
183-
data class ObjectA(var value: String)
184-
var path = "myObjects/objectA"
185-
var objectA: ObjectA ? = null
186-
Database.listen(path, object: Reference<ObjectA>(ObjectA::class.java) {
187-
override fun onCreate() {
188-
this@MainActivity.objectA = ObjectA("foo")
189-
Database.sync(path);
190-
}
191-
192-
override fun onUpdate(): ObjectA ? {
193-
return this@MainActivity.objectA
194-
}
195-
196-
override fun onChanged(ref: ObjectA) {
197-
this@MainActivity.objectA = ref
198-
// notify change on UI
199-
}
200-
201-
override fun onDestroy() {
202-
this@MainActivity.objectA = null;
203-
// UI changes for removed object
204-
}
205-
206-
override fun progress(value: Int) {
207-
Log.e("rotor", "loading " + path + " -> " + value + " %")
208-
}
209-
})
210-
```
211-
212182
License
213183
-------
214184
Copyright 2018 RotorLab Organization

app/build.gradle

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
44

55
android {
6-
compileSdkVersion 26
6+
compileSdkVersion 27
77
defaultConfig {
88
applicationId "com.rotor.sample"
9-
minSdkVersion 14
10-
targetSdkVersion 26
9+
minSdkVersion 21
10+
targetSdkVersion 27
1111
versionCode 1
1212
versionName rotor_version
1313
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14-
buildConfigField "String", "database_url", "\"http://10.0.2.2:1507/\""
14+
buildConfigField "String", "database_url", "\"http://10.0.2.2:1508/\""
1515
buildConfigField "String", "redis_url", "\"redis://10.0.2.2\""
1616
multiDexEnabled true
1717
}
@@ -26,7 +26,7 @@ android {
2626
dependencies {
2727
implementation fileTree(dir: 'libs', include: ['*.jar'])
2828
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
29-
implementation 'com.android.support:appcompat-v7:26.1.0'
29+
implementation 'com.android.support:appcompat-v7:27.1.1'
3030
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
3131
testImplementation 'junit:junit:4.12'
3232
androidTestImplementation 'com.android.support.test:runner:1.0.1'

app/src/main/java/com/rotor/sample/MainActivity.kt

+9-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ class MainActivity : AppCompatActivity() {
3131

3232
Database.initialize()
3333

34-
Database.listen("chat", object: Reference<Chat>(Chat::class.java) {
34+
Database.listen("database", "/chat", object: Reference<Chat>(Chat::class.java) {
35+
override fun onDestroy() {
36+
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
37+
}
3538

3639
override fun onCreate() {
3740

@@ -51,7 +54,11 @@ class MainActivity : AppCompatActivity() {
5154

5255
})
5356

54-
Database.listen("", object: Reference<ObjectA>(ObjectA::class.java) {
57+
Database.listen("database","/object", object: Reference<ObjectA>(ObjectA::class.java) {
58+
override fun onDestroy() {
59+
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
60+
}
61+
5562
override fun onCreate() {
5663
objectA = ObjectA("foo")
5764
}

build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.2.30'
5-
ext.rotor_version = '0.1.2'
4+
ext.kotlin_version = '1.2.41'
5+
ext.rotor_version = '0.2'
66

77
repositories {
88
google()
99
jcenter()
1010
}
1111

1212
dependencies {
13-
classpath 'com.android.tools.build:gradle:3.0.1'
13+
classpath 'com.android.tools.build:gradle:3.1.2'
1414
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1515
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1"
16-
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
16+
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
1717

1818
// NOTE: Do not place your application dependencies here; they belong
1919
// in the individual module build.gradle files

database/build.gradle

+18-14
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ apply plugin: 'com.jfrog.bintray'
66
version = rotor_version
77

88
android {
9-
compileSdkVersion 26
9+
compileSdkVersion 27
1010

1111
defaultConfig {
12-
minSdkVersion 14
13-
targetSdkVersion 26
12+
minSdkVersion 21
13+
targetSdkVersion 27
1414
versionCode 2
1515
versionName version
1616
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -28,25 +28,29 @@ android {
2828

2929
dependencies {
3030
implementation fileTree(dir: 'libs', include: ['*.jar'])
31-
implementation 'com.android.support:appcompat-v7:26.1.0'
31+
implementation 'com.android.support:appcompat-v7:27.1.1'
3232
testImplementation 'junit:junit:4.12'
3333
androidTestImplementation 'com.android.support.test:runner:1.0.1'
3434
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
35-
compile 'com.efraespada:jsondiff:1.1.0'
35+
implementation 'com.efraespada:jsondiff:1.1.2'
3636

37-
compile "com.squareup.retrofit2:retrofit:2.3.0"
38-
compile "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
39-
compile "com.squareup.retrofit2:converter-gson:2.3.0"
40-
compile "io.reactivex.rxjava2:rxandroid:2.0.2"
37+
implementation "com.squareup.retrofit2:retrofit:2.3.0"
38+
implementation "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
39+
implementation "com.squareup.retrofit2:converter-gson:2.3.0"
40+
implementation "io.reactivex.rxjava2:rxandroid:2.0.2"
41+
42+
implementation 'cc.duduhuo.util:digest-util:1.0.1'
43+
implementation 'org.apache.commons:commons-lang3:3.6'
4144

4245
//noinspection GradleDependency
43-
compile 'com.google.code.findbugs:jsr305:2.0.1'
46+
implementation 'com.google.code.findbugs:jsr305:2.0.1'
4447
//noinspection GradleDependency
45-
compile 'com.google.guava:guava:22.0-android'
46-
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
47-
compile "com.stringcare:library:0.7"
48+
implementation 'com.google.guava:guava:22.0-android'
49+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
50+
implementation "com.stringcare:library:0.7"
4851
implementation "com.rotor:core:$rotor_version"
49-
compile 'com.google.code.gson:gson:2.8.2'
52+
// implementation project(":core")
53+
implementation 'com.google.code.gson:gson:2.8.2'
5054
}
5155
repositories {
5256
mavenCentral()

0 commit comments

Comments
 (0)