Skip to content

Commit 55ca46a

Browse files
committed
change the lifecycle manager to com.trello.rxlifecycle2 and clean a little bit
1 parent 61ecd73 commit 55ca46a

File tree

8 files changed

+29
-91
lines changed

8 files changed

+29
-91
lines changed

liverelay/build.gradle

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@ apply plugin: 'com.github.dcendents.android-maven'
55
group = 'com.github.futuremind'
66

77
android {
8-
compileSdkVersion 26
8+
compileSdkVersion 27
99
buildToolsVersion "26.0.2"
1010

11-
1211
defaultConfig {
1312
minSdkVersion 16
14-
targetSdkVersion 26
13+
targetSdkVersion 27
1514
versionCode 1
16-
versionName "0.1.0"
17-
15+
versionName "0.1.2"
1816
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
19-
2017
}
2118

2219
buildTypes {
@@ -30,10 +27,10 @@ android {
3027

3128
dependencies {
3229
testImplementation 'junit:junit:4.12'
33-
implementation 'com.android.support:appcompat-v7:26.1.0'
34-
implementation 'com.github.florent37:rxlifecycle:2.0.4'
30+
implementation 'com.android.support:appcompat-v7:27.0.1'
31+
implementation 'com.trello.rxlifecycle2:rxlifecycle-android-lifecycle-kotlin:2.2.1'
3532
implementation 'com.jakewharton.rxrelay2:rxrelay:2.0.0'
36-
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
33+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
3734

3835
}
3936
repositories {

liverelay/src/main/java/com/futuremind/liverelay/LiveRelay.kt

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,23 @@ package com.futuremind.liverelay
22

33
import android.arch.lifecycle.LifecycleOwner
44
import com.jakewharton.rxrelay2.BehaviorRelay
5-
import florent37.github.com.rxlifecycle.RxLifecycle
5+
import com.trello.rxlifecycle2.android.lifecycle.kotlin.bindToLifecycle
66
import io.reactivex.BackpressureStrategy.LATEST
77
import io.reactivex.Flowable
8-
import io.reactivex.ObservableTransformer
98

109
/**
1110
* LiveRelay can be used to process states between ViewModel and LifecycleOwner.
1211
*
13-
* Subscribers don't need to worry about unexpected onComplete or onError, it only passes
14-
* onNext events.
12+
* Subscribers don't need to worry about unexpected onComplete or onError, it only passes onNext events.
1513
* Also, once observe is passed a valid [LifecycleOwner], subscribers don't need to worry about unsubscribing.
1614
*/
17-
class LiveRelay<T>(private val lifecycleEvent: LifecycleEvent = LifecycleEvent.PAUSE) {
15+
class LiveRelay<T> {
1816

1917
private val relay = BehaviorRelay.create<T>().toSerialized()
2018

2119
fun observe(lifecycleOwner: LifecycleOwner): Flowable<T> =
22-
relay.compose(lifecycleTransformer(lifecycleEvent, lifecycleOwner)).toFlowable(LATEST)
20+
relay.bindToLifecycle(lifecycleOwner).toFlowable(LATEST)
2321

2422
fun nextState(state: T) = relay.accept(state)
2523

26-
private fun lifecycleTransformer(lifecycleEvent: LifecycleEvent, lifecycleOwner: LifecycleOwner): ObservableTransformer<T, T> =
27-
when (lifecycleEvent) {
28-
LiveRelay.LifecycleEvent.PAUSE -> RxLifecycle.with(lifecycleOwner).disposeOnPause()
29-
LiveRelay.LifecycleEvent.STOP -> RxLifecycle.with(lifecycleOwner).disposeOnStop()
30-
LiveRelay.LifecycleEvent.DESTROY -> RxLifecycle.with(lifecycleOwner).disposeOnDestroy()
31-
}
32-
33-
enum class LifecycleEvent {
34-
PAUSE,
35-
STOP,
36-
DESTROY
37-
}
38-
3924
}

sample/build.gradle

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
44

55
android {
6-
compileSdkVersion 26
6+
compileSdkVersion 27
77
buildToolsVersion "26.0.2"
88
defaultConfig {
9-
applicationId "com.futuremind.liverelay"
9+
applicationId "com.futuremind.liverelay.sample"
1010
minSdkVersion 16
11-
targetSdkVersion 26
11+
targetSdkVersion 27
1212
versionCode 1
1313
versionName "1.0"
1414
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -21,14 +21,16 @@ android {
2121
}
2222
}
2323

24+
configurations.all {
25+
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
26+
if (details.requested.group == 'android.arch.lifecycle') {
27+
details.useVersion '1.0.0'
28+
}
29+
}
30+
}
31+
2432
dependencies {
25-
implementation fileTree(dir: 'libs', include: ['*.jar'])
26-
implementation 'com.android.support:appcompat-v7:26.1.0'
27-
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
28-
testImplementation 'junit:junit:4.12'
29-
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
30-
exclude group: 'com.android.support', module: 'support-annotations'
31-
})
33+
implementation 'com.android.support:appcompat-v7:27.0.1'
3234
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
3335
implementation project(':liverelay')
3436
}

sample/src/androidTest/java/com/futuremind/liverelay/ExampleInstrumentedTest.kt

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

sample/src/main/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.futuremind.liverelay">
3+
package="com.futuremind.liverelay.sample">
44

55
<application
66
android:allowBackup="true"
@@ -12,7 +12,6 @@
1212
<activity android:name=".MainActivity">
1313
<intent-filter>
1414
<action android:name="android.intent.action.MAIN" />
15-
1615
<category android:name="android.intent.category.LAUNCHER" />
1716
</intent-filter>
1817
</activity>

sample/src/main/java/com/futuremind/liverelay/MainActivity.kt renamed to sample/src/main/java/com/futuremind/liverelay/sample/MainActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package com.futuremind.liverelay
1+
package com.futuremind.liverelay.sample
22

3-
import android.support.v7.app.AppCompatActivity
43
import android.os.Bundle
4+
import android.support.v7.app.AppCompatActivity
55

66
class MainActivity : AppCompatActivity() {
77

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<android.support.constraint.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"
7-
tools:context="com.futuremind.liverelay.MainActivity">
7+
tools:context=".MainActivity">
88

99
<TextView
1010
android:layout_width="wrap_content"
1111
android:layout_height="wrap_content"
12-
android:text="Hello World!"
13-
app:layout_constraintBottom_toBottomOf="parent"
14-
app:layout_constraintLeft_toLeftOf="parent"
15-
app:layout_constraintRight_toRightOf="parent"
16-
app:layout_constraintTop_toTopOf="parent" />
12+
android:text="Hello World!" />
1713

18-
</android.support.constraint.ConstraintLayout>
14+
</FrameLayout>

sample/src/test/java/com/futuremind/liverelay/ExampleUnitTest.kt

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

0 commit comments

Comments
 (0)