Skip to content

Commit 73e4716

Browse files
author
Pablo Orgaz
committed
Add Rx and Flow
1 parent b03bce2 commit 73e4716

34 files changed

+565
-389
lines changed

app/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ dependencies {
8181
//Misc
8282
implementation 'com.github.minikorp:grove:1.0.3'
8383

84+
//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"
89+
8490
//Support
8591
implementation "androidx.core:core:1.0.1"
8692
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
@@ -89,12 +95,6 @@ dependencies {
8995
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
9096
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
9197

92-
//Dagger
93-
implementation "com.google.dagger:dagger-android:$dagger_version"
94-
implementation "com.google.dagger:dagger-android-support:$dagger_version"
95-
kapt "com.google.dagger:dagger-compiler:$dagger_version"
96-
kapt "com.google.dagger:dagger-android-processor:$dagger_version"
97-
9898
testImplementation 'junit:junit:4.12'
9999
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
100100
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package org.sample
22

33
import android.os.Bundle
4+
import com.mini.android.FluxActivity
45
import com.minikorp.grove.ConsoleLogTree
56
import com.minikorp.grove.Grove
6-
import com.mini.android.FluxActivity
7+
import kotlinx.android.synthetic.main.home_activity.*
78
import mini.*
89

910
class SampleActivity : FluxActivity() {
@@ -14,27 +15,23 @@ class SampleActivity : FluxActivity() {
1415
override fun onCreate(savedInstanceState: Bundle?) {
1516
super.onCreate(savedInstanceState)
1617
setContentView(R.layout.home_activity)
17-
Grove.plant(ConsoleLogTree())
18+
1819
val stores = listOf(dummyStore)
20+
MiniGen.subscribe(dispatcher, stores).track()
21+
stores.forEach { it.initialize() }
1922

20-
MiniGen.register(dispatcher, stores)
23+
dummyStore.subscribe {
24+
demo_text.text = it.text
25+
}
2126

27+
Grove.plant(ConsoleLogTree())
2228
dispatcher.addInterceptor(LoggerInterceptor(stores, { tag, msg ->
2329
Grove.tag(tag).d { msg }
2430
}))
2531

26-
dummyStore.flow()
27-
.collectOnUi {
28-
it.text
29-
}
30-
31-
dispatcher.dispatch(ActionOne("1"))
32+
dispatcher.dispatch(ActionOne(""))
3233
dispatcher.dispatch(ActionTwo("2"))
3334
}
34-
35-
override fun onDestroy() {
36-
super.onDestroy()
37-
}
3835
}
3936

4037
interface ActionInterface {
@@ -50,9 +47,7 @@ data class ActionOne(override val text: String) : ActionInterface, SampleAbstrac
5047
data class DummyState(val text: String = "dummy")
5148
class DummyStore : Store<DummyState>() {
5249

53-
@Reducer
54-
fun onInterfaceAction(a: ActionInterface) {
55-
50+
@Reducer fun onInterfaceAction(a: ActionInterface) {
5651
}
5752

5853
@Reducer fun onSampleAction(a: ActionOne) {
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<vector
3-
xmlns:android="http://schemas.android.com/apk/res/android"
4-
android:height="108dp"
5-
android:width="108dp"
6-
android:viewportHeight="108"
7-
android:viewportWidth="108">
8-
<path android:fillColor="#000000"
9-
android:pathData="M0,0h108v108h-108z"/>
2+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:width="108dp"
4+
android:height="108dp"
5+
android:viewportHeight="108"
6+
android:viewportWidth="108">
7+
<path
8+
android:fillColor="#000000"
9+
android:pathData="M0,0h108v108h-108z" />
1010
</vector>
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2-
android:width="108dp"
3-
android:height="108dp"
4-
android:viewportWidth="2000"
5-
android:viewportHeight="2000">
6-
<group android:translateX="460"
7-
android:translateY="460">
8-
<path
9-
android:pathData="M146,745c-116,-41 -175,-191 -118,-301 56,-109 171,-151 283,-103 52,23 57,32 34,64 -15,19 -16,19 -47,0 -96,-56 -228,20 -228,132 0,24 7,57 15,73 31,60 112,98 173,80 24,-6 169,-102 221,-147 3,-2 -4,-10 -15,-17 -61,-43 -67,-52 -55,-74 16,-30 25,-28 82,14l49,36 92,-68c50,-38 111,-79 136,-91 140,-71 305,36 305,197 0,123 -97,220 -221,220 -40,0 -132,-38 -132,-54 0,-6 7,-20 15,-31 15,-19 16,-19 47,0 96,56 228,-20 228,-132 0,-24 -7,-57 -15,-73 -31,-60 -112,-98 -173,-80 -24,6 -169,102 -221,147 -3,2 4,10 15,17 61,43 67,52 55,74 -16,30 -25,28 -82,-14l-49,-36 -92,68c-152,114 -209,132 -302,99z"
10-
android:fillColor="#44b74a"
11-
android:strokeColor="#00000000"/>
2+
android:width="108dp"
3+
android:height="108dp"
4+
android:viewportHeight="2000"
5+
android:viewportWidth="2000">
6+
<group
7+
android:translateX="460"
8+
android:translateY="460">
9+
<path
10+
android:fillColor="#44b74a"
11+
android:pathData="M146,745c-116,-41 -175,-191 -118,-301 56,-109 171,-151 283,-103 52,23 57,32 34,64 -15,19 -16,19 -47,0 -96,-56 -228,20 -228,132 0,24 7,57 15,73 31,60 112,98 173,80 24,-6 169,-102 221,-147 3,-2 -4,-10 -15,-17 -61,-43 -67,-52 -55,-74 16,-30 25,-28 82,14l49,36 92,-68c50,-38 111,-79 136,-91 140,-71 305,36 305,197 0,123 -97,220 -221,220 -40,0 -132,-38 -132,-54 0,-6 7,-20 15,-31 15,-19 16,-19 47,0 96,56 228,-20 228,-132 0,-24 -7,-57 -15,-73 -31,-60 -112,-98 -173,-80 -24,6 -169,102 -221,147 -3,2 4,10 15,17 61,43 67,52 55,74 -16,30 -25,28 -82,-14l-49,-36 -92,68c-152,114 -209,132 -302,99z"
12+
android:strokeColor="#00000000" />
1213
</group>
1314
</vector>
Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,25 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
77
tools:layout_editor_absoluteY="25dp">
88

9-
<TextView
10-
android:id="@+id/welcome"
11-
style="@style/AppTheme.Text"
12-
android:layout_width="wrap_content"
13-
android:layout_height="wrap_content"
14-
android:layout_marginEnd="8dp"
15-
android:layout_marginStart="8dp"
16-
android:layout_marginTop="200dp"
17-
android:text="Welcome! You have been successfully logged"
18-
app:layout_constraintEnd_toEndOf="parent"
19-
app:layout_constraintStart_toStartOf="parent"
20-
app:layout_constraintTop_toTopOf="parent" />
9+
<ScrollView
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content">
2112

22-
<TextView
23-
android:id="@+id/email"
24-
style="@style/AppTheme.Text"
25-
android:layout_width="wrap_content"
26-
android:layout_height="wrap_content"
27-
android:layout_marginEnd="8dp"
28-
android:layout_marginStart="8dp"
29-
android:layout_marginTop="24dp"
30-
android:padding="32dp"
31-
app:layout_constraintEnd_toEndOf="parent"
32-
app:layout_constraintStart_toStartOf="parent"
33-
app:layout_constraintTop_toBottomOf="@+id/welcome"
34-
tools:text="Email : some@gmail.com" />
13+
<TextView
14+
android:id="@+id/demo_text"
15+
style="@style/AppTheme.Text"
16+
android:layout_width="wrap_content"
17+
android:layout_height="wrap_content"
18+
app:layout_constraintEnd_toEndOf="parent"
19+
app:layout_constraintStart_toStartOf="parent"
20+
app:layout_constraintTop_toTopOf="parent"
21+
tools:text="Demo Text" />
3522

36-
<TextView
37-
android:id="@+id/signOut"
38-
style="@style/AppTheme.Text.AppButton"
39-
android:layout_width="match_parent"
40-
android:text="Sign Out"
41-
android:textAllCaps="false"
42-
app:layout_constraintBottom_toBottomOf="parent" />
43-
</androidx.constraintlayout.widget.ConstraintLayout>
23+
</ScrollView>
24+
25+
</FrameLayout>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
3-
<background android:drawable="@color/ic_launcher_background"/>
4-
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
3+
<background android:drawable="@color/ic_launcher_background" />
4+
<foreground android:drawable="@drawable/ic_launcher_foreground" />
55
</adaptive-icon>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
3-
<background android:drawable="@drawable/ic_launcher_background"/>
4-
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
3+
<background android:drawable="@drawable/ic_launcher_background" />
4+
<foreground android:drawable="@drawable/ic_launcher_foreground" />
55
</adaptive-icon>

gradle.properties

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
# Project-wide Gradle settings.
2-
32
# IDE (e.g. Android Studio) users:
43
# Gradle settings configured through the IDE *will take*
54
# any settings specified in this file.
6-
75
# For more details on how to fn your build environment visit
86
# http://www.gradle.org/docs/current/userguide/build_environment.html
9-
107
# Specifies the JVM arguments used for the daemon process.
118
# The setting is particularly useful for tweaking memory settings.
12-
139
org.gradle.jvmargs=-Xmx1536m
1410
kotlin.coroutines=enable
1511
android.useAndroidX=true
1612
android.enableJetifier=true
17-
1813
# When configured, Gradle will run in incubating parallel mode.
1914
# This option should only be used with decoupled projects. More details, visit
2015
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects

mini-android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ android {
2424
dependencies {
2525
implementation fileTree(dir: "libs", include: ["*.jar"])
2626
api project(":mini-common")
27-
27+
2828
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.1"
2929
api "androidx.appcompat:appcompat:1.0.2"
3030
api "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0-alpha02"
31-
31+
3232
testImplementation "junit:junit:4.12"
3333
androidTestImplementation "androidx.test:runner:1.2.0"
3434
androidTestImplementation "androidx.test.espresso:espresso-core:3.2.0"

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import android.content.Context;
44

5-
import androidx.test.InstrumentationRegistry;
6-
import androidx.test.runner.AndroidJUnit4;
7-
85
import org.junit.Test;
96
import org.junit.runner.RunWith;
107

11-
import static org.junit.Assert.*;
8+
import androidx.test.InstrumentationRegistry;
9+
import androidx.test.runner.AndroidJUnit4;
10+
11+
import static org.junit.Assert.assertEquals;
1212

1313
/**
1414
* Instrumented test, which will execute on an Android device.

0 commit comments

Comments
 (0)