Skip to content

Commit 4d237b3

Browse files
committed
v0.0.10
1 parent f9cf865 commit 4d237b3

File tree

7 files changed

+52
-27
lines changed

7 files changed

+52
-27
lines changed

README.md

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<p align="center"><img width="10%" vspace="20" src="https://github.com/rotorlab/database-kotlin/raw/develop/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png"></p>
1+
<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>
22

33
# Rotor Core for Android
44

@@ -11,7 +11,21 @@ Check out [rotor-server repo](https://github.com/rotorlab/server-node) for more
1111

1212
### Usage
1313
- Import library:
14-
14+
```groovy
15+
buildscript {
16+
17+
ext.kotlin_version = '1.2.30'
18+
ext.rotor_version = '0.0.10'
19+
20+
repositories {
21+
jcenter()
22+
}
23+
24+
dependencies {
25+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
26+
}
27+
}
28+
```
1529
```groovy
1630
android {
1731
defaultConfig {
@@ -20,7 +34,9 @@ android {
2034
}
2135
2236
dependencies {
23-
implementation 'com.rotor:core:0.0.5'
37+
implementation "com.rotor:core:$rotor_version"
38+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
39+
implementation 'com.google.code.gson:gson:2.8.2'
2440
}
2541
```
2642
Initialize Rotor Core on your app. `connected()` method is fired only when initialized method is called and core is connected to Redis server. `reconnecting()` will be called when core is trying to connect to redis.

app/build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
apply plugin: 'com.android.application'
2-
32
apply plugin: 'kotlin-android'
4-
53
apply plugin: 'kotlin-android-extensions'
64

75
android {
86
compileSdkVersion 26
7+
98
defaultConfig {
109
applicationId "com.efraespada.chappykotlin"
1110
minSdkVersion 14
1211
targetSdkVersion 26
1312
versionCode 1
14-
versionName "1.0"
13+
versionName rotor_version
1514
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1615
}
16+
1717
buildTypes {
1818
release {
1919
minifyEnabled false
@@ -30,5 +30,5 @@ dependencies {
3030
testImplementation 'junit:junit:4.12'
3131
androidTestImplementation 'com.android.support.test:runner:1.0.1'
3232
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
33-
implementation 'com.rotor:core:0.0.5'
33+
implementation 'com.rotor:core:0.0.10'
3434
}

build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
buildscript {
44
ext.kotlin_version = '1.2.30'
5+
ext.rotor_version = '0.0.10'
56
repositories {
67
google()
78
jcenter()

core/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
33
apply plugin: 'com.github.dcendents.android-maven'
44
apply plugin: 'com.jfrog.bintray'
55

6-
version = "0.0.9"
6+
version = rotor_version
77

88
android {
99
compileSdkVersion 26
@@ -50,7 +50,7 @@ install {
5050
pom {
5151
project {
5252
packaging 'aar'
53-
name 'Kotlin core for Rotor client'
53+
name 'Core module for Rotor client (kotlin)'
5454
url siteUrl
5555
// Set your license
5656
licenses {

core/src/main/java/com/rotor/core/Rotor.kt

+14-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import android.util.Log
1111
import com.rotor.core.interfaces.InternalServiceListener
1212
import com.rotor.core.interfaces.StatusListener
1313
import com.google.gson.Gson
14+
import com.rotor.core.RotorService.Companion.PREF_CONFIG
15+
import com.rotor.core.RotorService.Companion.PREF_ID
1416
import com.rotor.core.interfaces.BuilderFace
1517
import org.json.JSONObject
1618

@@ -35,10 +37,10 @@ class Rotor {
3537

3638
var gson: Gson? = null
3739
var debug: Boolean? = null
38-
var initialized: Boolean? = null
40+
var initializing: Boolean? = null
3941
var builders: HashMap<Builder, BuilderFace> ? = null
4042

41-
val serviceConnection: ServiceConnection = object : ServiceConnection {
43+
@JvmStatic val serviceConnection: ServiceConnection = object : ServiceConnection {
4244

4345
override fun onServiceConnected(className: ComponentName, service: IBinder) {
4446
if (service is RotorService.FBinder) {
@@ -47,8 +49,8 @@ class Rotor {
4749
rotorService?.listener = object : InternalServiceListener {
4850

4951
override fun connected() {
50-
if (initialized!!) {
51-
initialized = false
52+
if (initializing!!) {
53+
initializing = false
5254
statusListener.connected()
5355
}
5456
}
@@ -57,6 +59,9 @@ class Rotor {
5759
statusListener.reconnecting()
5860
}
5961
}
62+
if (initializing!!) {
63+
rotorService?.startService()
64+
}
6065
if (debug!!) Log.e(TAG, "instanced service")
6166
}
6267
}
@@ -80,21 +85,21 @@ class Rotor {
8085
}
8186
Companion.debug = false
8287
Companion.gson = Gson()
83-
val shared = context.getSharedPreferences("flamebase_config", MODE_PRIVATE)
84-
Companion.id = shared.getString("flamebase_id", null)
88+
val shared = context.getSharedPreferences(PREF_CONFIG, MODE_PRIVATE)
89+
Companion.id = shared.getString(PREF_ID, null)
8590
if (Companion.id == null) {
8691
Companion.id = generateNewId()
8792
}
8893

89-
Companion.initialized = true
94+
Companion.initializing = true
9095

9196
start()
9297
}
9398

9499
private fun generateNewId(): String {
95100
val id = Settings.Secure.getString(context!!.getContentResolver(), Settings.Secure.ANDROID_ID)
96-
val shared = context!!.getSharedPreferences("flamebase_config", MODE_PRIVATE).edit()
97-
shared.putString("flamebase_id", id)
101+
val shared = context!!.getSharedPreferences(PREF_CONFIG, MODE_PRIVATE).edit()
102+
shared.putString(PREF_ID, id)
98103
shared.apply()
99104
return id
100105
}

core/src/main/java/com/rotor/core/RotorService.kt

+12-9
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,21 @@ import java.util.*
2222
*/
2323
class RotorService: Service() {
2424

25+
companion object {
26+
internal val PREF_ID = "rotor_id"
27+
internal val PREF_URL = "rotor_url"
28+
internal val PREF_CONFIG = "rotor_config"
29+
}
2530
private val TAG = RotorService::class.java.simpleName
26-
private val PREF_KEY = "rotor_url"
27-
private val PREF_CONFIG_KEY = "rotor_config"
2831
private val EXCEPTION_NO_SERVER_URL = "No URL was defined for Rotor Server"
29-
internal var binder: FBinder ? = null
32+
internal var binder: FBinder = FBinder()
3033
internal var initialized: Boolean = false
3134
internal var client: RedisClient ? = null
3235
internal var moment: Long = 0
3336
internal var connection: RedisPubSubConnection<String, String> ? = null
3437
internal var sc: ServiceConnection ? = null
35-
internal var listener: InternalServiceListener? = null
3638
internal var connectedToRedis: Boolean = false
39+
var listener: InternalServiceListener? = null
3740

3841
private val redisPubSubListener = object : RedisPubSubListener<String, String> {
3942
override fun message(s: String, s2: String) {
@@ -90,11 +93,11 @@ class RotorService: Service() {
9093
if (client == null) {
9194
var url = Rotor.urlRedis
9295
if (url?.length == 0) {
93-
val shared = applicationContext.getSharedPreferences(PREF_CONFIG_KEY, Context.MODE_PRIVATE)
94-
url = shared.getString(PREF_KEY, null)
96+
val shared = applicationContext.getSharedPreferences(PREF_CONFIG, Context.MODE_PRIVATE)
97+
url = shared.getString(PREF_URL, null)
9598
} else {
96-
val shared = applicationContext.getSharedPreferences(PREF_CONFIG_KEY, Context.MODE_PRIVATE).edit()
97-
shared.putString(PREF_KEY, url)
99+
val shared = applicationContext.getSharedPreferences(PREF_CONFIG, Context.MODE_PRIVATE).edit()
100+
shared.putString(PREF_URL, url)
98101
shared.apply()
99102
}
100103

@@ -164,7 +167,7 @@ class RotorService: Service() {
164167
fun setListener(listener: InternalServiceListener) {
165168
[email protected] = listener
166169
167-
if (initialized) {
170+
if (initializing) {
168171
169172
}
170173
}*/

sample1.png

640 KB
Loading

0 commit comments

Comments
 (0)