Skip to content

Commit e13fe14

Browse files
author
Patrick Jackson
committed
add android presenterlifecycleobserver
1 parent f8c319b commit e13fe14

File tree

7 files changed

+189
-98
lines changed

7 files changed

+189
-98
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ buildscript {
1010
}
1111

1212
dependencies {
13+
classpath deps.plugins.android
1314
classpath deps.plugins.kotlin
1415
classpath deps.plugins.dokka
1516
}
@@ -20,6 +21,7 @@ allprojects {
2021
repositories {
2122
google()
2223
jcenter()
24+
mavenCentral()
2325
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
2426
maven { url "https://dl.bintray.com/spekframework/spek-dev" }
2527

gradle/dependencies.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ ext.versions = [
33
dokka : '0.9.17',
44
spek : '2.1.0-alpha.0.9+3d5d865',
55
atrium : '0.8.0',
6-
coroutinesVersion: '1.2.0'
6+
coroutinesVersion: '1.3.0-RC2'
77

88
]
99

1010
ext.deps = [
1111
plugins: [
1212
kotlin : "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}",
1313
dokka : "org.jetbrains.dokka:dokka-gradle-plugin:${versions.dokka}",
14+
android: "com.android.tools.build:gradle:3.5.0-rc01"
1415
]
1516
]

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

lib/build.gradle

Lines changed: 99 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,73 @@
11
repositories {
22
maven { url "https://dl.bintray.com/spekframework/spek-dev" }
33
}
4-
apply plugin: 'java'
4+
apply plugin: 'com.android.library'
55
apply plugin: 'kotlin-multiplatform'
66

77
archivesBaseName = 'presenter-middleware'
88

99
group 'org.reduxkotlin'
10-
version '0.2'
10+
version '0.2.9'
1111

1212
kotlin {
13-
jvm()
14-
js() {
15-
[compileKotlinJs, compileTestKotlinJs].each { configuration ->
16-
configuration.kotlinOptions {
17-
moduleKind = 'umd'
18-
sourceMap = true
19-
metaInfo = true
20-
}
21-
}
13+
targets {
14+
fromPreset(presets.android, 'android')
2215
}
16+
jvm()
17+
// commented targets are unsupported with current coroutine version 1.2.2
18+
// js() {
19+
// [compileKotlinJs, compileTestKotlinJs].each { configuration ->
20+
// configuration.kotlinOptions {
21+
// moduleKind = 'umd'
22+
// sourceMap = true
23+
// metaInfo = true
24+
// }
25+
// }
26+
// }
2327
//-module-name args are needed to prevent circular deps bug on native platforms
28+
2429
iosArm64("ios") {
2530
compilations.main.extraOpts.addAll(["-module-name", "presenter-middleware"])
2631
}
2732

2833
iosX64("iosSim") {
2934
compilations.main.extraOpts.addAll(["-module-name", "presenter-middleware"])
3035
}
31-
macosX64("macos") {
32-
compilations.main.extraOpts.addAll(["-module-name", "presenter-middleware"])
33-
}
34-
35-
mingwX64("win") {
36-
compilations.main.extraOpts.addAll(["-module-name", "presenter-middleware"])
37-
}
38-
39-
wasm32("wasm") {
40-
compilations.main.extraOpts.addAll(["-module-name", "presenter-middleware"])
41-
}
42-
43-
linuxArm32Hfp("linArm32") {
44-
compilations.main.extraOpts.addAll(["-module-name", "presenter-middleware"])
45-
}
46-
47-
linuxMips32("linMips32") {
48-
compilations.main.extraOpts.addAll(["-module-name", "presenter-middleware"])
49-
}
50-
51-
linuxMipsel32("linMipsel32") {
52-
compilations.main.extraOpts.addAll(["-module-name", "presenter-middleware"])
53-
}
54-
55-
linuxX64("lin64") {
56-
compilations.main.extraOpts.addAll(["-module-name", "presenter-middleware"])
57-
}
36+
// macosX64("macos") {
37+
// compilations.main.extraOpts.addAll(["-module-name", "presenter-middleware"])
38+
// }
39+
//
40+
// mingwX64("win") {
41+
// compilations.main.extraOpts.addAll(["-module-name", "presenter-middleware"])
42+
// }
43+
//
44+
// wasm32("wasm") {
45+
// compilations.main.extraOpts.addAll(["-module-name", "presenter-middleware"])
46+
// }
47+
//
48+
// linuxArm32Hfp("linArm32") {
49+
// compilations.main.extraOpts.addAll(["-module-name", "presenter-middleware"])
50+
// }
51+
//
52+
// linuxMips32("linMips32") {
53+
// compilations.main.extraOpts.addAll(["-module-name", "presenter-middleware"])
54+
// }
55+
//
56+
// linuxMipsel32("linMipsel32") {
57+
// compilations.main.extraOpts.addAll(["-module-name", "presenter-middleware"])
58+
// }
59+
//
60+
// linuxX64("lin64") {
61+
// compilations.main.extraOpts.addAll(["-module-name", "presenter-middleware"])
62+
// }
5863

5964

6065
sourceSets {
6166
commonMain {
6267
dependencies {
6368
implementation kotlin("stdlib-common")
64-
implementation "org.reduxkotlin:redux-kotlin-reselect:0.2.6"
65-
implementation "org.reduxkotlin:redux-kotlin:0.2.4"
69+
implementation "org.reduxkotlin:redux-kotlin-reselect:0.2.9"
70+
implementation "org.reduxkotlin:redux-kotlin:0.2.6"
6671
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$project.versions.coroutinesVersion"
6772
}
6873
}
@@ -77,16 +82,26 @@ kotlin {
7782
}
7883
}
7984

85+
androidMain {
86+
dependencies {
87+
api "org.jetbrains.kotlin:kotlin-stdlib:$project.versions.kotlinVersion"
88+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$project.versions.coroutinesVersion"
89+
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
90+
}
91+
}
92+
8093
jvmMain {
8194
kotlin.srcDir('src/jvmMain/kotlin')
8295
dependencies {
8396
implementation kotlin("stdlib")
97+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$project.versions.coroutinesVersion"
8498
}
8599
}
86100
jvmTest {
87101
dependencies {
88102
implementation kotlin("test")
89103
implementation kotlin("test-junit")
104+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$project.versions.coroutinesVersion"
90105
implementation "org.spekframework.spek2:spek-dsl-jvm:$project.versions.spek"
91106
implementation "ch.tutteli.atrium:atrium-cc-en_GB-robstoll:$project.versions.atrium"
92107
implementation "io.mockk:mockk:1.9.3"
@@ -95,33 +110,60 @@ kotlin {
95110
runtimeOnly 'org.jetbrains.kotlin:kotlin-reflect'
96111
}
97112
}
98-
jsMain {
99-
kotlin.srcDir('src/jsMain/kotlin')
113+
// jsMain {
114+
// kotlin.srcDir('src/jsMain/kotlin')
115+
// dependencies {
116+
// implementation kotlin("stdlib-js")
117+
// }
118+
// compileKotlinJs {
119+
// kotlinOptions.metaInfo = true
120+
// kotlinOptions.sourceMap = true
121+
// kotlinOptions.suppressWarnings = true
122+
// kotlinOptions.verbose = true
123+
// kotlinOptions.main = "call"
124+
// kotlinOptions.moduleKind = "umd"
125+
// }
126+
// }
127+
// jsTest {
128+
// dependencies {
129+
// implementation kotlin("test-js")
130+
// implementation kotlin("stdlib-js")
131+
// }
132+
// }
133+
iosMain {
100134
dependencies {
101-
implementation kotlin("stdlib-js")
102-
}
103-
compileKotlinJs {
104-
kotlinOptions.metaInfo = true
105-
kotlinOptions.sourceMap = true
106-
kotlinOptions.suppressWarnings = true
107-
kotlinOptions.verbose = true
108-
kotlinOptions.main = "call"
109-
kotlinOptions.moduleKind = "umd"
110-
}
111-
}
112-
jsTest {
113-
dependencies {
114-
implementation kotlin("test-js")
115-
implementation kotlin("stdlib-js")
135+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$project.versions.coroutinesVersion"
116136
}
117137
}
118138

119139
iosSimMain.dependsOn iosMain
120140
iosSimTest.dependsOn iosTest
141+
lin64Main.dependsOn iosMain
142+
linArm32Main.dependsOn iosMain
143+
linMips32Main.dependsOn iosMain
144+
linMipsel32Main.dependsOn iosMain
121145

122146
}
123147
}
124148

149+
android {
150+
compileSdkVersion 29
151+
defaultConfig {
152+
minSdkVersion 15
153+
}
154+
buildTypes {
155+
//This is for MultiplatformSettings
156+
debug {
157+
// MPP libraries don't currently get this resolution automatically
158+
matchingFallbacks = ['release']
159+
}
160+
release {
161+
minifyEnabled true
162+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
163+
}
164+
}
165+
}
166+
125167

126168
afterEvaluate {
127169
// Alias the task names we use elsewhere to the new task names.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.reduxkotlin
2+
3+
import androidx.lifecycle.Lifecycle
4+
import androidx.lifecycle.LifecycleObserver
5+
import androidx.lifecycle.OnLifecycleEvent
6+
7+
/**
8+
* Lifecycle observer that dispatches attach/detach/clear actions for Presenter-Middleware
9+
*/
10+
class PresenterLifecycleObserver(val view: ViewWithProvider<*>): LifecycleObserver {
11+
12+
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
13+
fun onAttach() {
14+
rootDispatch(AttachView(view))
15+
}
16+
17+
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
18+
fun onDetach() {
19+
rootDispatch(DetachView(view))
20+
}
21+
22+
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
23+
fun onClear() {
24+
rootDispatch(ClearView(view))
25+
}
26+
27+
}

0 commit comments

Comments
 (0)