androidx
Zhanty 5 years ago
parent 19a744db26
commit 81fc69b647
  1. 24
      lib_base/src/main/java/com/android/base/rx/RxEx.kt
  2. 4
      lib_base/src/main/java/com/android/base/rx/RxKit.java

@ -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 <T> Single<T>.observeOnUI(): Single<T> = this.observeOn(AndroidSchedulers.mainThread())
fun <T> Maybe<T>.observeOnUI(): Maybe<T> = this.observeOn(AndroidSchedulers.mainThread())
fun <T> Observable<T>.observeOnUI(): Observable<T> = this.observeOn(AndroidSchedulers.mainThread())
@ -106,11 +122,3 @@ fun <T> Single<T>.retryWhen(maxRetries: Int, retryDelayMillis: Long, retryChecke
fun <T> Maybe<T>.retryWhen(maxRetries: Int, retryDelayMillis: Long, retryChecker: RetryChecker? = null): Maybe<T> {
return this.retryWhen(FlowableRetryDelay(maxRetries, retryDelayMillis, retryChecker))
}
operator fun CompositeDisposable?.plusAssign(disposable: Disposable) {
this?.add(disposable)
}
fun Disposable.addTo(compositeDisposable: CompositeDisposable?) {
compositeDisposable?.add(this)
}

@ -32,13 +32,13 @@ public class RxKit {
* }
* </pre>
*/
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();
}

Loading…
Cancel
Save