Skip to content

Commit d2f0290

Browse files
author
Adrián García
authored
Split packages (#1)
* Update dependencies. Calculate version with Gradle plug-in * Make the sample work * Test publish mini-rx and mini-rx-android * Add StateMerger and Activity extensions in rx package. Add Rx ViewModels in rx-android package * Move mini-rx packages to mini-rx2 to be more explicit about library version. Adjust depdendencies * Add mini-kodein and mini-kodein-android packages. Fix comments and remove unneeded lines in Gradle files * Fix jitpack compilation
1 parent 3ba5cf4 commit d2f0290

File tree

40 files changed

+612
-103
lines changed

40 files changed

+612
-103
lines changed

.floo

Lines changed: 0 additions & 3 deletions
This file was deleted.

.flooignore

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/build.gradle

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ buildscript {
88
leak_canary_version = "1.5"
99
butterkinfe_version = "8.4.0"
1010
support_version = "27.0.0"
11-
target_sdk_version = 28
1211
}
1312
}
1413

@@ -24,25 +23,18 @@ apply plugin: 'kotlin-android'
2423
apply plugin: 'kotlin-kapt'
2524
apply plugin: 'kotlin-android-extensions'
2625

27-
//Kotlin
28-
kotlin {
29-
experimental {
30-
coroutines "enable"
31-
}
32-
}
33-
3426
//Android
3527
android {
36-
compileSdkVersion target_sdk_version
37-
buildToolsVersion '28.0.3'
28+
compileSdkVersion android_target_sdk
29+
buildToolsVersion android_build_tools_version
3830

3931
defaultConfig {
4032
applicationId "com.bq.mini"
4133
minSdkVersion 21
42-
targetSdkVersion target_sdk_version
43-
versionCode 1
34+
targetSdkVersion android_target_sdk
35+
versionCode android_version_code
36+
versionName android_version_name
4437
multiDexEnabled true
45-
versionName "1.0"
4638
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
4739
}
4840

@@ -76,29 +68,30 @@ dependencies {
7668
implementation fileTree(dir: 'libs', include: ['*.jar'])
7769

7870
implementation project(":mini-android")
71+
implementation project(':mini-rx2')
72+
implementation project(':mini-rx2-android')
73+
7974
kapt project(":mini-processor")
8075

8176
//Misc
8277
implementation 'com.github.minikorp:grove:1.0.3'
8378

8479
//Reactive
85-
def coroutines = "1.3.0-RC"
86-
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines"
87-
def rx = "2.2.6"
88-
implementation "io.reactivex.rxjava2:rxjava:$rx"
80+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
81+
implementation "io.reactivex.rxjava2:rxjava:$rx_version"
8982

9083
//Support
91-
implementation "androidx.core:core:1.0.1"
92-
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
84+
implementation "androidx.core:core:1.1.0"
85+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
9386

9487
//Kotlin
9588
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
9689
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
9790

9891
testImplementation 'junit:junit:4.12'
99-
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
100-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
101-
androidTestImplementation 'com.agoda.kakao:kakao:1.4.0'
92+
androidTestImplementation 'androidx.test:runner:1.3.0-alpha02'
93+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02'
94+
androidTestImplementation 'com.agoda.kakao:kakao:2.1.0'
10295
}
10396

10497

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
<activity
1515
android:name=".SampleActivity"
1616
android:screenOrientation="portrait">
17+
</activity>
18+
19+
<activity
20+
android:name=".SampleRxActivity"
21+
android:screenOrientation="portrait">
1722
<intent-filter>
1823
<action android:name="android.intent.action.MAIN" />
1924
<category android:name="android.intent.category.LAUNCHER" />

app/src/main/java/org/sample/SampleActivity.kt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import com.mini.android.FluxActivity
55
import com.minikorp.grove.ConsoleLogTree
66
import com.minikorp.grove.Grove
77
import kotlinx.android.synthetic.main.home_activity.*
8-
import mini.Action
98
import mini.LoggerInterceptor
109
import mini.MiniGen
11-
import mini.Store
1210

1311
class SampleActivity : FluxActivity() {
1412

@@ -35,14 +33,3 @@ class SampleActivity : FluxActivity() {
3533
dispatcher.dispatch(ActionTwo("2"))
3634
}
3735
}
38-
39-
@Action
40-
interface ActionInterface {
41-
val text: String
42-
}
43-
44-
@Action
45-
class ActionTwo(override val text: String) : ActionInterface
46-
47-
data class DummyState(val text: String = "dummy")
48-
class DummyStore : Store<DummyState>()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.sample
2+
3+
import mini.Action
4+
import mini.Reducer
5+
import mini.Store
6+
7+
@Action
8+
interface ActionInterface {
9+
val text: String
10+
}
11+
12+
@Action
13+
class ActionTwo(override val text: String) : ActionInterface
14+
15+
data class DummyState(val text: String = "dummy")
16+
class DummyStore : Store<DummyState>() {
17+
@Reducer
18+
fun onActionTwo(action: ActionTwo) {
19+
newState = state.copy(text = action.text)
20+
}
21+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.sample
2+
3+
import android.os.Bundle
4+
import com.minikorp.grove.ConsoleLogTree
5+
import com.minikorp.grove.Grove
6+
import kotlinx.android.synthetic.main.home_activity.*
7+
import mini.LoggerInterceptor
8+
import mini.MiniGen
9+
import mini.rx.android.activities.FluxRxActivity
10+
import mini.rx.flowable
11+
12+
class SampleRxActivity : FluxRxActivity() {
13+
14+
private val dispatcher = MiniGen.newDispatcher()
15+
private val dummyStore = DummyStore()
16+
17+
override fun onCreate(savedInstanceState: Bundle?) {
18+
super.onCreate(savedInstanceState)
19+
setContentView(R.layout.home_activity)
20+
21+
val stores = listOf(dummyStore)
22+
MiniGen.subscribe(dispatcher, stores)
23+
stores.forEach { it.initialize() }
24+
25+
dummyStore.flowable()
26+
.subscribe {
27+
demo_text.text = it.text
28+
}
29+
.track()
30+
31+
Grove.plant(ConsoleLogTree())
32+
dispatcher.addInterceptor(LoggerInterceptor(stores, { tag, msg ->
33+
Grove.tag(tag).d { msg }
34+
}))
35+
36+
dispatcher.dispatch(ActionTwo("2"))
37+
}
38+
}

build.gradle

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,53 @@
1+
apply plugin: "com.github.ben-manes.versions"
2+
apply plugin: 'com.gladed.androidgitversion'
3+
14
buildscript {
25
ext {
36
kotlin_version = "1.3.50"
4-
mini_version = "4.0.5"
7+
8+
android_compile_sdk = 29
9+
android_target_sdk = 29
10+
android_build_tools_version = "29.0.1"
11+
12+
lifecycle_version = "2.1.0"
13+
rx_version = "2.2.6"
14+
coroutines_version = "1.3.2"
515
}
616

717
repositories {
818
jcenter()
919
mavenCentral()
1020
google()
21+
maven { url "https://plugins.gradle.org/m2/" }
1122
}
1223

1324
dependencies {
1425
classpath "com.android.tools.build:gradle:3.5.0"
1526
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1627
classpath "org.junit.platform:junit-platform-gradle-plugin:1.0.0"
1728
classpath "com.github.dcendents:android-maven-gradle-plugin:2.1"
29+
classpath "com.gladed.androidgitversion:gradle-android-git-version:0.4.10"
30+
classpath "com.github.ben-manes:gradle-versions-plugin:0.21.0"
1831
}
1932
}
2033

34+
androidGitVersion {
35+
codeFormat "MNNPP"
36+
baseCode 1
37+
tagPattern(/^v[0-9]+.*/) // Tag names should follow the pattern vM.NN.PP
38+
}
39+
2140
allprojects {
41+
ext {
42+
mini_version = androidGitVersion.name()
43+
android_version_name = androidGitVersion.name()
44+
// The Android version is multiplied by a big number so it is placed in the leftmost part
45+
// of the version code because we can't add it in androidGitVersion's codeFormat parameter
46+
android_version_code = (android_compile_sdk * 100000) + androidGitVersion.code()
47+
}
48+
2249
version = mini_version
23-
group = "com.mini"
50+
group = "com.bq.mini"
2451

2552
repositories {
2653
jcenter()

mini-android/build.gradle

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ apply plugin: "kotlin-android"
33
apply plugin: "com.github.dcendents.android-maven"
44

55
android {
6-
compileSdkVersion 29
7-
buildToolsVersion "29.0.0"
6+
compileSdkVersion android_compile_sdk
7+
buildToolsVersion android_build_tools_version
88

99
defaultConfig {
1010
minSdkVersion 14
11-
targetSdkVersion 29
12-
versionCode 1
13-
versionName "1.0"
11+
targetSdkVersion android_target_sdk
12+
versionCode android_version_code
13+
versionName android_version_name
1414
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1515
}
1616
buildTypes {
@@ -22,12 +22,11 @@ android {
2222
}
2323

2424
dependencies {
25-
implementation fileTree(dir: "libs", include: ["*.jar"])
2625
api project(":mini-common")
2726

28-
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.1"
29-
api "androidx.appcompat:appcompat:1.0.2"
30-
api "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0-alpha02"
27+
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
28+
api "androidx.appcompat:appcompat:1.1.0"
29+
api "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0-alpha05"
3130

3231
testImplementation "junit:junit:4.12"
3332
androidTestImplementation "androidx.test:runner:1.2.0"

mini-android/src/androidTest/java/com/mini/ExampleInstrumentedTest.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

mini-common/build.gradle

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,17 @@ apply plugin: 'kotlin'
22
apply from: "../jitpack.gradle"
33

44
dependencies {
5-
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
6-
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
5+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
6+
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
77

88
//Optional Rx and Android bindings, one day these should be modules,
99
//for now we compile against them but let user package library
1010
compileOnly "com.google.android:android:4.1.1.4"
1111

12-
def coroutines = "1.3.0-RC"
13-
compileOnly "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines"
14-
testCompile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines"
12+
compileOnly "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
13+
testCompileOnly "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
1514

16-
def rx = "2.2.6"
17-
compileOnly "io.reactivex.rxjava2:rxjava:$rx"
18-
testCompile "io.reactivex.rxjava2:rxjava:$rx"
19-
20-
testCompile 'junit:junit:4.12'
15+
testCompileOnly 'junit:junit:4.12'
2116
testImplementation "org.amshove.kluent:kluent:1.44"
2217
}
2318

mini-common/src/main/java/mini/Resource.kt

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,42 @@ inline fun <T, R> Resource<T>.map(crossinline transform: (data: T) -> R): Resour
110110
return Resource(value)
111111
}
112112

113-
/** All tasks succeeded. */
113+
/** All resources succeeded. */
114114
fun <T> Iterable<Resource<T>>.allSuccesful(): Boolean {
115115
return this.all { it.isSuccess }
116116
}
117117

118-
/** Any tasks failed. */
118+
/** Any resources failed. */
119119
fun <T> Iterable<Resource<T>>.anyFailure(): Boolean {
120120
return this.any { it.isFailure }
121121
}
122122

123-
/** Any task is running. */
123+
/** Any resource is loading. */
124124
fun <T> Iterable<Resource<T>>.anyLoading(): Boolean {
125125
return this.any { it.isLoading }
126-
}
126+
}
127+
128+
/** Any resource empty */
129+
fun <T> Iterable<Resource<T>>.anyEmpty(): Boolean = this.any { it.isEmpty }
130+
131+
fun <T> Iterable<Resource<T>>.onAllSuccessful(fn: () -> Unit): Iterable<Resource<T>> {
132+
if (this.allSuccesful()) fn()
133+
return this
134+
}
135+
136+
fun <T> Iterable<Resource<T>>.onAnyFailure(fn: () -> Unit): Iterable<Resource<T>> {
137+
if (this.anyFailure()) fn()
138+
return this
139+
}
140+
141+
fun <T> Iterable<Resource<T>>.onAnyLoading(fn: () -> Unit): Iterable<Resource<T>> {
142+
if (this.anyLoading()) fn()
143+
return this
144+
}
145+
146+
fun <T> Iterable<Resource<T>>.onAnyEmpty(fn: () -> Unit): Iterable<Resource<T>> {
147+
if (this.anyEmpty()) fn()
148+
return this
149+
}
150+
151+
fun Iterable<Task>.onAnyIdle(fn: () -> Unit): Iterable<Task> = onAnyEmpty(fn).map { it as Task }

mini-kodein-android/.gitignore

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

0 commit comments

Comments
 (0)