-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
caodd
committed
Aug 21, 2018
1 parent
3275456
commit 248a7c2
Showing
2 changed files
with
29 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,26 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
|
||
android { | ||
compileSdkVersion 27 | ||
|
||
|
||
|
||
defaultConfig { | ||
minSdkVersion 21 | ||
targetSdkVersion 27 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
|
||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
|
||
implementation 'com.android.support:appcompat-v7:27.1.1' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
|
||
// rxjava | ||
implementation 'io.reactivex.rxjava2:rxjava:2.1.9' | ||
} |
24 changes: 24 additions & 0 deletions
24
rxlifecycle/src/main/java/com/github/caoddx/rxlifecycle/DisposableExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.github.caoddx.rxlifecycle | ||
|
||
import android.arch.lifecycle.GenericLifecycleObserver | ||
import android.arch.lifecycle.Lifecycle | ||
import android.arch.lifecycle.LifecycleOwner | ||
import io.reactivex.disposables.Disposable | ||
|
||
fun Disposable.bindTo(owner: LifecycleOwner): Disposable { | ||
|
||
owner.lifecycle.addObserver(object : GenericLifecycleObserver { | ||
override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) { | ||
|
||
if (event == Lifecycle.Event.ON_DESTROY) { | ||
dispose() | ||
} | ||
|
||
if (isDisposed) { | ||
source.lifecycle.removeObserver(this) | ||
} | ||
} | ||
}) | ||
|
||
return this | ||
} |