diff --git a/lib_base/src/main/java/com/android/base/rx/RxEx.kt b/lib_base/src/main/java/com/android/base/rx/RxEx.kt index 9ede2b5..0747d3f 100644 --- a/lib_base/src/main/java/com/android/base/rx/RxEx.kt +++ b/lib_base/src/main/java/com/android/base/rx/RxEx.kt @@ -6,6 +6,22 @@ import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.Disposable import timber.log.Timber +operator fun CompositeDisposable?.plusAssign(disposable: Disposable) { + this?.add(disposable) +} + +fun Disposable.addTo(compositeDisposable: CompositeDisposable?) { + compositeDisposable?.add(this) +} + +fun Disposable?.disposeChecked() { + RxKit.disposeChecked(this) +} + +fun newCompositeIfDisposed(cd: CompositeDisposable?): CompositeDisposable { + return RxKit.newCompositeIfUnsubscribed(cd) +} + fun Single.observeOnUI(): Single = this.observeOn(AndroidSchedulers.mainThread()) fun Maybe.observeOnUI(): Maybe = this.observeOn(AndroidSchedulers.mainThread()) fun Observable.observeOnUI(): Observable = this.observeOn(AndroidSchedulers.mainThread()) @@ -106,11 +122,3 @@ fun Single.retryWhen(maxRetries: Int, retryDelayMillis: Long, retryChecke fun Maybe.retryWhen(maxRetries: Int, retryDelayMillis: Long, retryChecker: RetryChecker? = null): Maybe { return this.retryWhen(FlowableRetryDelay(maxRetries, retryDelayMillis, retryChecker)) } - -operator fun CompositeDisposable?.plusAssign(disposable: Disposable) { - this?.add(disposable) -} - -fun Disposable.addTo(compositeDisposable: CompositeDisposable?) { - compositeDisposable?.add(this) -} \ No newline at end of file diff --git a/lib_base/src/main/java/com/android/base/rx/RxKit.java b/lib_base/src/main/java/com/android/base/rx/RxKit.java index c1db177..323e59d 100644 --- a/lib_base/src/main/java/com/android/base/rx/RxKit.java +++ b/lib_base/src/main/java/com/android/base/rx/RxKit.java @@ -32,13 +32,13 @@ public class RxKit { * } * */ - public static void unsubscribeIfNotNull(Disposable disposable) { + public static void disposeChecked(Disposable disposable) { if (disposable != null && !disposable.isDisposed()) { disposable.dispose(); } } - public static CompositeDisposable getNewCompositeSubIfUnsubscribed(CompositeDisposable disposable) { + public static CompositeDisposable newCompositeIfUnsubscribed(CompositeDisposable disposable) { if (disposable == null || disposable.isDisposed()) { return new CompositeDisposable(); }