From 533f65543370350775b41e8a5638ea7cee3f4e26 Mon Sep 17 00:00:00 2001 From: Dan Lew Date: Mon, 7 Nov 2016 14:39:52 -0600 Subject: [PATCH] Filled out Kotlin extensions --- .../trello/rxlifecycle2/kotlin/rxlifecycle.kt | 95 ++++++++++++++++--- 1 file changed, 83 insertions(+), 12 deletions(-) diff --git a/rxlifecycle-kotlin/src/main/java/com/trello/rxlifecycle2/kotlin/rxlifecycle.kt b/rxlifecycle-kotlin/src/main/java/com/trello/rxlifecycle2/kotlin/rxlifecycle.kt index 12bedea..eef5509 100644 --- a/rxlifecycle-kotlin/src/main/java/com/trello/rxlifecycle2/kotlin/rxlifecycle.kt +++ b/rxlifecycle-kotlin/src/main/java/com/trello/rxlifecycle2/kotlin/rxlifecycle.kt @@ -16,34 +16,105 @@ package com.trello.rxlifecycle2.kotlin import android.view.View import com.trello.rxlifecycle2.LifecycleProvider +import com.trello.rxlifecycle2.RxLifecycle import com.trello.rxlifecycle2.android.RxLifecycleAndroid import io.reactivex.Completable +import io.reactivex.Flowable +import io.reactivex.Maybe import io.reactivex.Observable import io.reactivex.Single +import io.reactivex.functions.Function + +// RxLifecycle extensions + +fun Observable.bind(lifecycle: Observable): Observable + = this.compose(RxLifecycle.bind(lifecycle)) + +fun Observable.bindUntilEvent(lifecycle: Observable, event: E): Observable + = this.compose(RxLifecycle.bindUntilEvent(lifecycle, event)) + +fun Observable.bind(lifecycle: Observable, correspondingEvents: Function): Observable + = this.compose(RxLifecycle.bind(lifecycle, correspondingEvents)) + +fun Flowable.bind(lifecycle: Observable): Flowable + = this.compose(RxLifecycle.bind(lifecycle)) + +fun Flowable.bindUntilEvent(lifecycle: Observable, event: E): Flowable + = this.compose(RxLifecycle.bindUntilEvent(lifecycle, event)) + +fun Flowable.bind(lifecycle: Observable, correspondingEvents: Function): Flowable + = this.compose(RxLifecycle.bind(lifecycle, correspondingEvents)) + +fun Single.bind(lifecycle: Observable): Single + = this.compose(RxLifecycle.bind(lifecycle)) + +fun Single.bindUntilEvent(lifecycle: Observable, event: E): Single + = this.compose(RxLifecycle.bindUntilEvent(lifecycle, event)) + +fun Single.bind(lifecycle: Observable, correspondingEvents: Function): Single + = this.compose(RxLifecycle.bind(lifecycle, correspondingEvents)) + +fun Maybe.bind(lifecycle: Observable): Maybe + = this.compose(RxLifecycle.bind(lifecycle)) + +fun Maybe.bindUntilEvent(lifecycle: Observable, event: E): Maybe + = this.compose(RxLifecycle.bindUntilEvent(lifecycle, event)) + +fun Maybe.bind(lifecycle: Observable, correspondingEvents: Function): Maybe + = this.compose(RxLifecycle.bind(lifecycle, correspondingEvents)) + +fun Completable.bind(lifecycle: Observable): Completable + = this.compose(RxLifecycle.bind(lifecycle)) + +fun Completable.bindUntilEvent(lifecycle: Observable, event: E): Completable + = this.compose(RxLifecycle.bindUntilEvent(lifecycle, event)) + +fun Completable.bind(lifecycle: Observable, correspondingEvents: Function): Completable + = this.compose(RxLifecycle.bind(lifecycle, correspondingEvents)) + +// RxLifecycleAndroid extensions fun Observable.bindToLifecycle(provider: LifecycleProvider): Observable - = this.compose(provider.bindToLifecycle()) + = this.compose(provider.bindToLifecycle()) fun Observable.bindUntilEvent(provider: LifecycleProvider, event: E): Observable - = this.compose(provider.bindUntilEvent(event)) + = this.compose(provider.bindUntilEvent(event)) fun Observable.bindToLifecycle(view: View): Observable - = this.compose(RxLifecycleAndroid.bindView(view)) + = this.compose(RxLifecycleAndroid.bindView(view)) -fun Completable.bindToLifecycle(provider: LifecycleProvider): Completable - = this.compose(provider.bindToLifecycle()) +fun Flowable.bindToLifecycle(provider: LifecycleProvider): Flowable + = this.compose(provider.bindToLifecycle()) -fun Completable.bindUntilEvent(provider: LifecycleProvider, event: E): Completable - = this.compose(provider.bindUntilEvent(event)) +fun Flowable.bindUntilEvent(provider: LifecycleProvider, event: E): Flowable + = this.compose(provider.bindUntilEvent(event)) -fun Completable.bindToLifecycle(view: View): Completable - = this.compose(RxLifecycleAndroid.bindView(view)) +fun Flowable.bindToLifecycle(view: View): Flowable + = this.compose(RxLifecycleAndroid.bindView(view)) fun Single.bindToLifecycle(provider: LifecycleProvider): Single - = this.compose(provider.bindToLifecycle()) + = this.compose(provider.bindToLifecycle()) fun Single.bindUntilEvent(provider: LifecycleProvider, event: E): Single - = this.compose(provider.bindUntilEvent(event)) + = this.compose(provider.bindUntilEvent(event)) fun Single.bindToLifecycle(view: View): Single - = this.compose(RxLifecycleAndroid.bindView(view)) \ No newline at end of file + = this.compose(RxLifecycleAndroid.bindView(view)) + +fun Maybe.bindToLifecycle(provider: LifecycleProvider): Maybe + = this.compose(provider.bindToLifecycle()) + +fun Maybe.bindUntilEvent(provider: LifecycleProvider, event: E): Maybe + = this.compose(provider.bindUntilEvent(event)) + +fun Maybe.bindToLifecycle(view: View): Maybe + = this.compose(RxLifecycleAndroid.bindView(view)) + +fun Completable.bindToLifecycle(provider: LifecycleProvider): Completable + = this.compose(provider.bindToLifecycle()) + +fun Completable.bindUntilEvent(provider: LifecycleProvider, event: E): Completable + = this.compose(provider.bindUntilEvent(event)) + +fun Completable.bindToLifecycle(view: View): Completable + = this.compose(RxLifecycleAndroid.bindView(view)) \ No newline at end of file