@@ -19,6 +19,11 @@ package cn.nekocode.gank.base
1919import android.support.v4.app.NavUtils
2020import android.support.v7.app.AppCompatActivity
2121import android.view.MenuItem
22+ import com.uber.autodispose.*
23+ import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider
24+ import io.reactivex.*
25+ import io.reactivex.annotations.CheckReturnValue
26+ import io.reactivex.parallel.ParallelFlowable
2227
2328/* *
2429 * @author nekocode ([email protected] ) @@ -40,4 +45,28 @@ open class BaseActivity: AppCompatActivity() {
4045 }
4146 }
4247 }
48+
49+ private val scopeProvider by lazy { AndroidLifecycleScopeProvider .from(this ) }
50+
51+ /* *
52+ * Modified from https://github.com/uber/AutoDispose
53+ */
54+ @CheckReturnValue
55+ fun <T > Flowable<T>.autoDisposable (): FlowableSubscribeProxy <T >
56+ = this .`as `(AutoDispose .autoDisposable(scopeProvider))
57+ @CheckReturnValue
58+ fun <T > Observable<T>.autoDisposable (): ObservableSubscribeProxy <T >
59+ = this .`as `(AutoDispose .autoDisposable(scopeProvider))
60+ @CheckReturnValue
61+ fun <T > Single<T>.autoDisposable (): SingleSubscribeProxy <T >
62+ = this .`as `(AutoDispose .autoDisposable(scopeProvider))
63+ @CheckReturnValue
64+ fun <T > Maybe<T>.autoDisposable (): MaybeSubscribeProxy <T >
65+ = this .`as `(AutoDispose .autoDisposable(scopeProvider))
66+ @CheckReturnValue
67+ fun Completable.autoDisposable (): CompletableSubscribeProxy
68+ = this .`as `(AutoDispose .autoDisposable<Any >(scopeProvider))
69+ @CheckReturnValue
70+ fun <T > ParallelFlowable<T>.autoDisposable (): ParallelFlowableSubscribeProxy <T >
71+ = this .`as `(AutoDispose .autoDisposable(scopeProvider))
4372}
0 commit comments