diff --git a/autodispose-rxlifecycle/build.gradle b/autodispose-rxlifecycle/build.gradle index 56c49924d..69f655287 100644 --- a/autodispose-rxlifecycle/build.gradle +++ b/autodispose-rxlifecycle/build.gradle @@ -40,8 +40,8 @@ dependencies { apt deps.build.nullAway testApt deps.build.nullAway - compile project(':autodispose') - compile deps.misc.rxlifecycle + api project(':autodispose') + api deps.misc.rxlifecycle compileOnly deps.misc.errorProneAnnotations compileOnly deps.misc.javaxExtras 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 a11185687..16e9c58fb 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 @@ -18,24 +18,17 @@ 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; /** - * Interop for RxLifecycle. It provides static utility methods to convert {@link - * LifecycleProvider} to {@link ScopeProvider}. - * - *

There are several static utility converter - * methods such as {@link #from(LifecycleProvider)} for {@link - * LifecycleProvider#bindToLifecycle()} and {@link #from(LifecycleProvider, Object)} for - * {@link LifecycleProvider#bindUntilEvent(Object)}. - *

+ * Interop for RxLifecycle. This provides static factory methods to convert {@link + * LifecycleProvider}s into {@link ScopeProvider} representations. * * Note: RxLifecycle treats the {@link OutsideLifecycleException} * as normal terminal event. There is no mapping to {@link LifecycleEndedException} and in such - * cases the stream is normally disposed. + * cases the stream is just disposed. */ public final class RxLifecycleInterop { @@ -46,19 +39,18 @@ 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. + * Factory creating a {@link ScopeProvider} representation of a {@link LifecycleProvider}. *

* Example usage: *


    *   Observable.just(1)
-   *        .to(RxLifecycleInterop.from(lifecycleProvider))
+   *        .to(AutoDispose.with(RxLifecycleInterop.from(lifecycleProvider)).forObservable())
    *        .subscribe(...)
    * 
* * @param the lifecycle event. - * @param provider the {@link LifecycleProvider} for RxLifecycle. - * @return a {@link ScopeHandler} to create AutoDisposing transformation + * @param provider the {@link LifecycleProvider}. + * @return a {@link ScopeProvider} */ public static ScopeProvider from(final LifecycleProvider provider) { return new ScopeProvider() { @@ -73,20 +65,19 @@ public static ScopeProvider from(final LifecycleProvider provider) { } /** - * Converter for transforming {@link LifecycleProvider} to {@link ScopeProvider}. - * It disposes the source when a specific event occurs. + * Factory creating a {@link ScopeProvider} representation of a {@link LifecycleProvider}. *

* Example usage: *


    *   Observable.just(1)
-   *        .to(RxLifecycleInterop.from(lifecycleProvider, event))
+   *        .to(AutoDispose.with(RxLifecycleInterop.from(lifecycleProvider, event)).forObservable())
    *        .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 + * @param provider the {@link LifecycleProvider}. + * @param event a target event to dispose upon. + * @return a {@link ScopeProvider} */ public static ScopeProvider from(final LifecycleProvider provider, final E event) { return new ScopeProvider() { diff --git a/autodispose-rxlifecycle/src/test/java/com/ubercab/autodispose/rxlifecycle/RxLifecycleInteropTest.java b/autodispose-rxlifecycle/src/test/java/com/ubercab/autodispose/rxlifecycle/RxLifecycleInteropTest.java index cf6101a86..e0051534a 100644 --- a/autodispose-rxlifecycle/src/test/java/com/ubercab/autodispose/rxlifecycle/RxLifecycleInteropTest.java +++ b/autodispose-rxlifecycle/src/test/java/com/ubercab/autodispose/rxlifecycle/RxLifecycleInteropTest.java @@ -35,14 +35,14 @@ public class RxLifecycleInteropTest { private TestLifecycleProvider lifecycleProvider = new TestLifecycleProvider(); - @Test - public void bindLifecycle_normalTermination_completeTheStream() { + @Test public void bindLifecycle_normalTermination_completeTheStream() { lifecycleProvider.emitCreate(); TestObserver o = new TestObserver<>(); PublishSubject source = PublishSubject.create(); - Disposable d = source.to(AutoDispose.with( - RxLifecycleInterop.from(lifecycleProvider)).forObservable()) - .subscribeWith(o); + Disposable d = + source.to(AutoDispose.with(RxLifecycleInterop.from(lifecycleProvider)) + .forObservable()) + .subscribeWith(o); o.assertSubscribed(); assertThat(source.hasObservers()).isTrue(); @@ -58,13 +58,11 @@ public void bindLifecycle_normalTermination_completeTheStream() { assertThat(source.hasObservers()).isFalse(); } - @Test - public void bindLifecycle_normalTermination_unsubscribe() { + @Test public void bindLifecycle_normalTermination_unsubscribe() { lifecycleProvider.emitCreate(); RecordingObserver o = new RecordingObserver<>(LOGGER); PublishSubject source = PublishSubject.create(); - source.to(AutoDispose.with( - RxLifecycleInterop.from(lifecycleProvider)).forObservable()) + source.to(AutoDispose.with(RxLifecycleInterop.from(lifecycleProvider)).forObservable()) .subscribe(o); o.takeSubscribe(); @@ -79,33 +77,27 @@ public void bindLifecycle_normalTermination_unsubscribe() { assertThat(source.hasObservers()).isFalse(); } - @Test - public void bindLifecycle_outsideLifecycleBound_unsubscribe() { + @Test public void bindLifecycle_outsideLifecycleBound_unsubscribe() { lifecycleProvider.emitCreate(); RecordingObserver o = new RecordingObserver<>(LOGGER); PublishSubject source = PublishSubject.create(); lifecycleProvider.emitDestroy(); - source - .to(AutoDispose.with( - RxLifecycleInterop.from(lifecycleProvider)).forObservable()) + source.to(AutoDispose.with(RxLifecycleInterop.from(lifecycleProvider)).forObservable()) .subscribe(o); o.takeSubscribe(); source.onNext(2); o.assertNoMoreEvents(); - assertThat( - source.hasObservers()).isFalse(); // Because RxLifecycle + assertThat(source.hasObservers()).isFalse(); // Because RxLifecycle // treats OutsideLifecycleException as terminal event. } - @Test - public void bindUntilEvent_normalTermination_completeTheStream() { + @Test public void bindUntilEvent_normalTermination_completeTheStream() { lifecycleProvider.emitCreate(); TestObserver o = new TestObserver<>(); PublishSubject source = PublishSubject.create(); - Disposable d = source.to(AutoDispose.with(RxLifecycleInterop.from( - lifecycleProvider, + Disposable d = source.to(AutoDispose.with(RxLifecycleInterop.from(lifecycleProvider, TestLifecycleProvider.Event.DESTROY)).forObservable()) .subscribeWith(o); o.assertSubscribed(); @@ -123,8 +115,7 @@ public void bindUntilEvent_normalTermination_completeTheStream() { assertThat(source.hasObservers()).isFalse(); } - @Test - public void bindUntilEvent_interruptedTermination_unsubscribe() { + @Test public void bindUntilEvent_interruptedTermination_unsubscribe() { lifecycleProvider.emitCreate(); RecordingObserver o = new RecordingObserver<>(LOGGER); PublishSubject source = PublishSubject.create(); diff --git a/autodispose-rxlifecycle/src/test/java/com/ubercab/autodispose/rxlifecycle/TestLifecycleProvider.java b/autodispose-rxlifecycle/src/test/java/com/ubercab/autodispose/rxlifecycle/TestLifecycleProvider.java index 7cac2cb8c..fe26ee3b5 100644 --- a/autodispose-rxlifecycle/src/test/java/com/ubercab/autodispose/rxlifecycle/TestLifecycleProvider.java +++ b/autodispose-rxlifecycle/src/test/java/com/ubercab/autodispose/rxlifecycle/TestLifecycleProvider.java @@ -27,8 +27,7 @@ final class TestLifecycleProvider implements LifecycleProvider { private static final Function CORRESPONDING_EVENTS = new Function() { - @Override public Event apply(Event event) - throws Exception { + @Override public Event apply(Event event) throws Exception { switch (event) { case CREATE: return Event.DESTROY; @@ -44,8 +43,7 @@ final class TestLifecycleProvider implements LifecycleProvider LifecycleTransformer bindUntilEvent(Event event) { + @Override public LifecycleTransformer bindUntilEvent(Event event) { return RxLifecycle.bindUntilEvent(lifecycle, event); } @@ -62,7 +60,6 @@ void emitDestroy() { } enum Event { - CREATE, - DESTROY + CREATE, DESTROY } }