diff --git a/autodispose-rxlifecycle/src/main/java/com/ubercab/autodispose/rxlifecycle/RxLifecycleInterop.java b/autodispose-rxlifecycle/src/main/java/com/ubercab/autodispose/rxlifecycle/RxLifecycleInterop.java index 7190c9cd8..9a5046c0c 100644 --- a/autodispose-rxlifecycle/src/main/java/com/ubercab/autodispose/rxlifecycle/RxLifecycleInterop.java +++ b/autodispose-rxlifecycle/src/main/java/com/ubercab/autodispose/rxlifecycle/RxLifecycleInterop.java @@ -2,6 +2,7 @@ import com.trello.rxlifecycle2.LifecycleProvider; import com.trello.rxlifecycle2.OutsideLifecycleException; +import com.uber.autodispose.AutoDispose.ScopeHandler; import com.uber.autodispose.LifecycleEndedException; import com.uber.autodispose.ScopeProvider; import io.reactivex.Maybe; @@ -28,6 +29,21 @@ private RxLifecycleInterop() { private static final Object DEFAULT_THROWAWAY_OBJECT = new Object(); + /** + * Converter for transforming {@link LifecycleProvider} to {@link ScopeProvider}. + * It disposes the source when the next reasonable event occurs. + *

+ * Example usage: + *


+   *   Observable.just(1)
+   *        .to(RxLifecycleInterop.from(lifecycleProvider))
+   *        .subscribe(...)
+   * 
+ * + * @param the lifecycle event. + * @param provider the {@link LifecycleProvider} for RxLifecycle. + * @return a {@link ScopeHandler} to create AutoDisposing transformation + */ public static ScopeProvider from(final LifecycleProvider provider) { return new ScopeProvider() { @Override public Maybe requestScope() { @@ -40,6 +56,22 @@ public static ScopeProvider from(final LifecycleProvider provider) { }; } + /** + * Converter for transforming {@link LifecycleProvider} to {@link ScopeProvider}. + * It disposes the source when a specific event occurs. + *

+ * Example usage: + *


+   *   Observable.just(1)
+   *        .to(RxLifecycleInterop.from(lifecycleProvider, event))
+   *        .subscribe(...)
+   * 
+ * + * @param the lifecycle event. + * @param provider the {@link LifecycleProvider} for RxLifecycle. + * @param event the event at which the source is disposed. + * @return a {@link ScopeHandler} to create AutoDisposing transformation + */ public static ScopeProvider from(final LifecycleProvider provider, final E event) { return new ScopeProvider() { @Override public Maybe requestScope() {