Skip to content

Commit 3a3ce17

Browse files
authored
Merge pull request #19 from reduxkotlin/task/store-interface
refactor Store from data class to interface
2 parents c571bb6 + 58e330f commit 3a3ce17

File tree

43 files changed

+875
-30
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+875
-30
lines changed

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
key: v1-dependencies-{{ checksum "build.gradle" }}
6565

6666
# run tests!
67-
- run: ./gradlew lib:jvmTest
67+
- run: ./gradlew jvmTest
6868

6969
workflows:
7070
build_test:
@@ -74,6 +74,7 @@ workflows:
7474
branches:
7575
only:
7676
- /^feature.*/
77+
- /^task.*/
7778
- /^bugfix.*/
7879

7980
publish_release_artifacts:

buildSrc/src/main/kotlin/Libs.kt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ object Libs {
1212
*/
1313
const val appcompat: String = "androidx.appcompat:appcompat:" + Versions.appcompat
1414

15+
/**
16+
* https://developer.android.com/reference/android/support/constraint/ConstraintLayout
17+
*/
18+
const val constraintLayout = "androidx.constraintlayout:constraintlayout:" + Versions.constraint_layout
19+
20+
/**
21+
* https://developer.android.com/guide/topics/ui/layout/recyclerview
22+
*/
23+
const val recyclerView = "androidx.recyclerview:recyclerview:" + Versions.recycler_view
24+
1525
/**
1626
* https://developer.android.com/testing
1727
*/
@@ -26,13 +36,13 @@ object Libs {
2636
* https://github.com/robstoll/atrium
2737
*/
2838
const val atrium_cc_en_gb_robstoll_common: String =
29-
"ch.tutteli.atrium:atrium-cc-en_GB-robstoll-common:" + Versions.ch_tutteli_atrium
39+
"ch.tutteli.atrium:atrium-cc-en_GB-robstoll-common:" + Versions.atrium
3040

3141
/**
3242
* https://github.com/robstoll/atrium
3343
*/
3444
const val atrium_cc_en_gb_robstoll: String = "ch.tutteli.atrium:atrium-cc-en_GB-robstoll:" +
35-
Versions.ch_tutteli_atrium
45+
Versions.atrium
3646

3747
/**
3848
* https://developer.android.com/studio
@@ -57,12 +67,12 @@ object Libs {
5767
/**
5868
* http://mockk.io
5969
*/
60-
const val mockk_common: String = "io.mockk:mockk-common:" + Versions.io_mockk
70+
const val mockk_common: String = "io.mockk:mockk-common:" + Versions.mockk
6171

6272
/**
6373
* http://mockk.io
6474
*/
65-
const val mockk: String = "io.mockk:mockk:" + Versions.io_mockk
75+
const val mockk: String = "io.mockk:mockk:" + Versions.mockk
6676

6777
/**
6878
* http://junit.org
@@ -163,11 +173,11 @@ object Libs {
163173
Versions.org_jetbrains_kotlin
164174

165175
const val spek_dsl_jvm: String = "org.spekframework.spek2:spek-dsl-jvm:" +
166-
Versions.org_spekframework_spek2
176+
Versions.spek
167177

168178
const val spek_dsl_metadata: String = "org.spekframework.spek2:spek-dsl-metadata:" +
169-
Versions.org_spekframework_spek2
179+
Versions.spek
170180

171181
const val spek_runner_junit5: String = "org.spekframework.spek2:spek-runner-junit5:" +
172-
Versions.org_spekframework_spek2
182+
Versions.spek
173183
}

buildSrc/src/main/kotlin/Versions.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ object Versions {
1818

1919
const val androidx_test_runner: String = "1.2.0"
2020

21-
const val ch_tutteli_atrium: String = "0.8.0"
21+
const val atrium: String = "0.8.0"
2222

2323
const val aapt2: String = "3.5.0-5435860"
2424

@@ -28,17 +28,22 @@ object Versions {
2828

2929
const val de_fayard_buildsrcversions_gradle_plugin: String = "0.4.2"
3030

31-
const val io_mockk: String = "1.9.3"
31+
const val mockk: String = "1.9.3"
3232

3333
const val junit: String = "4.12"
3434

3535
const val dokka_gradle_plugin: String = "0.9.17" // available: "0.9.18"
3636

3737
const val org_jetbrains_kotlin: String = "1.3.50"
3838

39-
const val org_spekframework_spek2: String = "2.1.0-alpha.0.11+d97ef33"
39+
const val spek: String = "2.1.0-alpha.0.11+d97ef33"
4040
// available: "2.1.0-alpha.0.24+0fdeb6e"
4141

42+
const val constraint_layout = "1.1.3"
43+
44+
const val recycler_view = "1.0.0"
45+
46+
4247
/**
4348
*
4449
* See issue 19: How to update Gradle itself?
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GROUP=org.reduxkotlin.examples.counter.android

examples/counter/common/build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ kotlin {
4040
dependencies {
4141
implementation kotlin("test-common")
4242
implementation kotlin("test-annotations-common")
43-
implementation "org.spekframework.spek2:spek-dsl-metadata:$project.versions.spek"
44-
implementation "ch.tutteli.atrium:atrium-cc-en_GB-robstoll-common:$project.versions.atrium"
45-
implementation "io.mockk:mockk-common:1.9.3"
43+
implementation "org.spekframework.spek2:spek-dsl-metadata:$Versions.spek"
44+
implementation "ch.tutteli.atrium:atrium-cc-en_GB-robstoll-common:$Versions.atrium"
45+
implementation "io.mockk:mockk-common:$Versions.mockk"
4646
}
4747
}
4848

@@ -56,11 +56,11 @@ kotlin {
5656
dependencies {
5757
implementation kotlin("test")
5858
implementation kotlin("test-junit")
59-
implementation "org.spekframework.spek2:spek-dsl-jvm:$project.versions.spek"
60-
implementation "ch.tutteli.atrium:atrium-cc-en_GB-robstoll:$project.versions.atrium"
61-
implementation "io.mockk:mockk:1.9.3"
59+
implementation "org.spekframework.spek2:spek-dsl-jvm:$Versions.spek"
60+
implementation "ch.tutteli.atrium:atrium-cc-en_GB-robstoll:$Versions.atrium"
61+
implementation "io.mockk:mockk:$Versions.mockk"
6262

63-
runtimeOnly "org.spekframework.spek2:spek-runner-junit5:$project.versions.spek"
63+
runtimeOnly "org.spekframework.spek2:spek-runner-junit5:$Versions.spek"
6464
runtimeOnly 'org.jetbrains.kotlin:kotlin-reflect'
6565
}
6666
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GROUP=org.reduxkotlin.examples.counter.common
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
plugins {
2+
id("com.android.application")
3+
kotlin("android")
4+
kotlin("android.extensions")
5+
kotlin("kapt")
6+
}
7+
8+
android {
9+
compileSdkVersion(29)
10+
defaultConfig {
11+
applicationId = "org.reduxkotlin.example.todos"
12+
minSdkVersion(26)
13+
targetSdkVersion(29)
14+
versionCode = 1
15+
versionName = "1.0"
16+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
17+
}
18+
compileOptions {
19+
sourceCompatibility = JavaVersion.VERSION_1_8
20+
targetCompatibility = JavaVersion.VERSION_1_8
21+
}
22+
buildTypes {
23+
getByName("release") {
24+
isMinifyEnabled = false
25+
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
26+
}
27+
getByName("debug") {
28+
// MPP libraries don't currently get this resolution automatically
29+
matchingFallbacks = listOf("release")
30+
isDebuggable = true
31+
}
32+
}
33+
packagingOptions {
34+
exclude("META-INF/*.kotlin_module")
35+
}
36+
}
37+
38+
39+
dependencies {
40+
implementation(Libs.kotlin_stdlib_jdk8)
41+
implementation(Libs.appcompat)
42+
implementation(Libs.constraintLayout)
43+
implementation(Libs.recyclerView)
44+
45+
implementation(project(":examples:todos:common"))
46+
implementation(project(":lib"))
47+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GROUP=org.reduxkotlin.examples.todos.android
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="org.reduxkotlin.example.todos">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/TodoAppTheme">
12+
<activity
13+
android:name=".MainActivity"
14+
android:label="@string/app_name"
15+
android:theme="@style/TodoAppTheme">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
24+
</manifest>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.reduxkotlin.example.todos
2+
3+
import android.os.Bundle
4+
import androidx.appcompat.app.AppCompatActivity
5+
import kotlinx.android.synthetic.main.activity_main.*
6+
import org.reduxkotlin.StoreSubscription
7+
import org.reduxkotlin.createStore
8+
import org.reduxkotlin.examples.todos.*
9+
10+
/**
11+
* This is a sample of basic redux behavior.
12+
* This is NOT best practice for structuring a multiplatform App.
13+
*/
14+
15+
16+
val store = createStore(::rootReducer, AppState())
17+
18+
class MainActivity: AppCompatActivity() {
19+
private lateinit var storeSubscription: StoreSubscription
20+
private var adapter = TodoAdapter()
21+
22+
override fun onCreate(savedInstanceState: Bundle?) {
23+
super.onCreate(savedInstanceState)
24+
setContentView(R.layout.activity_main)
25+
storeSubscription = store.subscribe { render(store.state) }
26+
btnAddTodo.setOnClickListener {
27+
val todoText = etTodo.text.toString()
28+
etTodo.text.clear()
29+
store.dispatch(AddTodo(todoText))
30+
}
31+
btnSelectAll.setOnClickListener { store.dispatch(SetVisibilityFilter(VisibilityFilter.SHOW_ALL)) }
32+
btnActive.setOnClickListener { store.dispatch(SetVisibilityFilter(VisibilityFilter.SHOW_ACTIVE)) }
33+
btnCompleted.setOnClickListener { store.dispatch(SetVisibilityFilter(VisibilityFilter.SHOW_COMPLETED)) }
34+
35+
recyclerView.adapter = adapter
36+
37+
render(store.state)
38+
}
39+
40+
private fun render(state: AppState) {
41+
adapter.submitList(state.visibleTodos)
42+
setFilterButtons(state.visibilityFilter)
43+
}
44+
45+
private fun setFilterButtons(visibilityFilter: VisibilityFilter) =
46+
when (visibilityFilter) {
47+
VisibilityFilter.SHOW_ALL -> {
48+
btnSelectAll.isSelected = true
49+
btnActive.isSelected = false
50+
btnCompleted.isSelected = false
51+
}
52+
VisibilityFilter.SHOW_ACTIVE -> {
53+
btnActive.isSelected = true
54+
btnSelectAll.isSelected = false
55+
btnCompleted.isSelected = false
56+
}
57+
VisibilityFilter.SHOW_COMPLETED -> {
58+
btnCompleted.isSelected = true
59+
btnSelectAll.isSelected = false
60+
btnActive.isSelected = false
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)