Merge pull request #54 from TouchInstinct/feature/singles-and-completables

Feature/singles and completables
This commit is contained in:
Gavriil 2017-03-23 18:53:48 +03:00 committed by GitHub
commit 6883a7bf4d
5 changed files with 530 additions and 31 deletions

View File

@ -33,7 +33,9 @@ import android.view.View;
import ru.touchin.roboswag.components.utils.LifecycleBindable;
import ru.touchin.roboswag.core.utils.ShouldNotHappenException;
import rx.Completable;
import rx.Observable;
import rx.Single;
import rx.Subscription;
import rx.functions.Action0;
import rx.functions.Action1;
@ -42,6 +44,7 @@ import rx.functions.Action1;
* Created by Gavriil Sitnikov on 12/8/2016.
* ViewHolder that implements {@link LifecycleBindable} and uses parent bindable object as bridge (Activity, ViewController etc.).
*/
@SuppressWarnings("PMD.TooManyMethods")
public class BindableViewHolder extends RecyclerView.ViewHolder implements LifecycleBindable {
@NonNull
@ -154,6 +157,46 @@ public class BindableViewHolder extends RecyclerView.ViewHolder implements Lifec
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction, onCompletedAction);
}
@NonNull
@Override
public <T> Subscription untilStop(@NonNull final Single<T> single) {
return baseLifecycleBindable.untilStop(single);
}
@NonNull
@Override
public <T> Subscription untilStop(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
return baseLifecycleBindable.untilStop(single, onSuccessAction);
}
@NonNull
@Override
public <T> Subscription untilStop(@NonNull final Single<T> single,
@NonNull final Action1<T> onSuccessAction,
@NonNull final Action1<Throwable> onErrorAction) {
return baseLifecycleBindable.untilStop(single, onSuccessAction, onErrorAction);
}
@NonNull
@Override
public Subscription untilStop(@NonNull final Completable completable) {
return baseLifecycleBindable.untilStop(completable);
}
@NonNull
@Override
public Subscription untilStop(@NonNull final Completable completable, @NonNull final Action0 onCompletedAction) {
return baseLifecycleBindable.untilStop(completable, onCompletedAction);
}
@NonNull
@Override
public Subscription untilStop(@NonNull final Completable completable,
@NonNull final Action0 onCompletedAction,
@NonNull final Action1<Throwable> onErrorAction) {
return baseLifecycleBindable.untilStop(completable, onCompletedAction, onErrorAction);
}
@NonNull
@Override
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable) {
@ -183,4 +226,44 @@ public class BindableViewHolder extends RecyclerView.ViewHolder implements Lifec
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction, onCompletedAction);
}
@NonNull
@Override
public <T> Subscription untilDestroy(@NonNull final Single<T> single) {
return baseLifecycleBindable.untilDestroy(single);
}
@NonNull
@Override
public <T> Subscription untilDestroy(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
return baseLifecycleBindable.untilDestroy(single, onSuccessAction);
}
@NonNull
@Override
public <T> Subscription untilDestroy(@NonNull final Single<T> single,
@NonNull final Action1<T> onSuccessAction,
@NonNull final Action1<Throwable> onErrorAction) {
return baseLifecycleBindable.untilDestroy(single, onSuccessAction, onErrorAction);
}
@NonNull
@Override
public Subscription untilDestroy(@NonNull final Completable completable) {
return baseLifecycleBindable.untilDestroy(completable);
}
@NonNull
@Override
public Subscription untilDestroy(@NonNull final Completable completable, @NonNull final Action0 onCompletedAction) {
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction);
}
@NonNull
@Override
public Subscription untilDestroy(@NonNull final Completable completable,
@NonNull final Action0 onCompletedAction,
@NonNull final Action1<Throwable> onErrorAction) {
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction, onErrorAction);
}
}

View File

@ -44,7 +44,9 @@ import ru.touchin.roboswag.components.utils.LifecycleBindable;
import ru.touchin.roboswag.components.utils.UiUtils;
import ru.touchin.roboswag.core.log.Lc;
import ru.touchin.roboswag.core.utils.ShouldNotHappenException;
import rx.Completable;
import rx.Observable;
import rx.Single;
import rx.Subscription;
import rx.functions.Action0;
import rx.functions.Action1;
@ -56,7 +58,7 @@ import rx.functions.Action1;
* @param <TActivity> Type of activity where such {@link ViewController} could be;
* @param <TFragment> Type of fragment where such {@link ViewController} could be;
*/
@SuppressWarnings("PMD.TooManyMethods")
@SuppressWarnings({"PMD.TooManyMethods", "PMD.ExcessivePublicCount"})
public class ViewController<TActivity extends ViewControllerActivity<?>,
TFragment extends ViewControllerFragment<?, TActivity>>
implements LifecycleBindable {
@ -372,6 +374,46 @@ public class ViewController<TActivity extends ViewControllerActivity<?>,
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction, onCompletedAction);
}
@NonNull
@Override
public <T> Subscription untilStop(@NonNull final Single<T> single) {
return baseLifecycleBindable.untilStop(single);
}
@NonNull
@Override
public <T> Subscription untilStop(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
return baseLifecycleBindable.untilStop(single, onSuccessAction);
}
@NonNull
@Override
public <T> Subscription untilStop(@NonNull final Single<T> single,
@NonNull final Action1<T> onSuccessAction,
@NonNull final Action1<Throwable> onErrorAction) {
return baseLifecycleBindable.untilStop(single, onSuccessAction, onErrorAction);
}
@NonNull
@Override
public Subscription untilStop(@NonNull final Completable completable) {
return baseLifecycleBindable.untilStop(completable);
}
@NonNull
@Override
public Subscription untilStop(@NonNull final Completable completable, @NonNull final Action0 onCompletedAction) {
return baseLifecycleBindable.untilStop(completable, onCompletedAction);
}
@NonNull
@Override
public Subscription untilStop(@NonNull final Completable completable,
@NonNull final Action0 onCompletedAction,
@NonNull final Action1<Throwable> onErrorAction) {
return baseLifecycleBindable.untilStop(completable, onCompletedAction, onErrorAction);
}
@NonNull
@Override
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable) {
@ -401,6 +443,46 @@ public class ViewController<TActivity extends ViewControllerActivity<?>,
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction, onCompletedAction);
}
@NonNull
@Override
public <T> Subscription untilDestroy(@NonNull final Single<T> single) {
return baseLifecycleBindable.untilDestroy(single);
}
@NonNull
@Override
public <T> Subscription untilDestroy(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
return baseLifecycleBindable.untilDestroy(single, onSuccessAction);
}
@NonNull
@Override
public <T> Subscription untilDestroy(@NonNull final Single<T> single,
@NonNull final Action1<T> onSuccessAction,
@NonNull final Action1<Throwable> onErrorAction) {
return baseLifecycleBindable.untilDestroy(single, onSuccessAction, onErrorAction);
}
@NonNull
@Override
public Subscription untilDestroy(@NonNull final Completable completable) {
return baseLifecycleBindable.untilDestroy(completable);
}
@NonNull
@Override
public Subscription untilDestroy(@NonNull final Completable completable, @NonNull final Action0 onCompletedAction) {
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction);
}
@NonNull
@Override
public Subscription untilDestroy(@NonNull final Completable completable,
@NonNull final Action0 onCompletedAction,
@NonNull final Action1<Throwable> onErrorAction) {
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction, onErrorAction);
}
@SuppressWarnings("CPD-END")
//CPD: it is same as in other implementation based on BaseLifecycleBindable
/**

View File

@ -40,7 +40,9 @@ import ru.touchin.roboswag.components.utils.BaseLifecycleBindable;
import ru.touchin.roboswag.components.utils.LifecycleBindable;
import ru.touchin.roboswag.components.utils.UiUtils;
import ru.touchin.roboswag.core.log.Lc;
import rx.Completable;
import rx.Observable;
import rx.Single;
import rx.Subscription;
import rx.functions.Action0;
import rx.functions.Action1;
@ -269,6 +271,46 @@ public abstract class BaseActivity extends AppCompatActivity
return baseLifecycleBindable.untilStop(observable, onNextAction, onErrorAction, onCompletedAction);
}
@NonNull
@Override
public <T> Subscription untilStop(@NonNull final Single<T> single) {
return baseLifecycleBindable.untilStop(single);
}
@NonNull
@Override
public <T> Subscription untilStop(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
return baseLifecycleBindable.untilStop(single, onSuccessAction);
}
@NonNull
@Override
public <T> Subscription untilStop(@NonNull final Single<T> single,
@NonNull final Action1<T> onSuccessAction,
@NonNull final Action1<Throwable> onErrorAction) {
return baseLifecycleBindable.untilStop(single, onSuccessAction, onErrorAction);
}
@NonNull
@Override
public Subscription untilStop(@NonNull final Completable completable) {
return baseLifecycleBindable.untilStop(completable);
}
@NonNull
@Override
public Subscription untilStop(@NonNull final Completable completable, @NonNull final Action0 onCompletedAction) {
return baseLifecycleBindable.untilStop(completable, onCompletedAction);
}
@NonNull
@Override
public Subscription untilStop(@NonNull final Completable completable,
@NonNull final Action0 onCompletedAction,
@NonNull final Action1<Throwable> onErrorAction) {
return baseLifecycleBindable.untilStop(completable, onCompletedAction, onErrorAction);
}
@NonNull
@Override
public <T> Subscription untilStop(@NonNull final Observable<T> observable) {
@ -310,6 +352,46 @@ public abstract class BaseActivity extends AppCompatActivity
return baseLifecycleBindable.untilDestroy(observable, onNextAction, onErrorAction, onCompletedAction);
}
@NonNull
@Override
public <T> Subscription untilDestroy(@NonNull final Single<T> single) {
return baseLifecycleBindable.untilDestroy(single);
}
@NonNull
@Override
public <T> Subscription untilDestroy(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
return baseLifecycleBindable.untilDestroy(single, onSuccessAction);
}
@NonNull
@Override
public <T> Subscription untilDestroy(@NonNull final Single<T> single,
@NonNull final Action1<T> onSuccessAction,
@NonNull final Action1<Throwable> onErrorAction) {
return baseLifecycleBindable.untilDestroy(single, onSuccessAction, onErrorAction);
}
@NonNull
@Override
public Subscription untilDestroy(@NonNull final Completable completable) {
return baseLifecycleBindable.untilDestroy(completable);
}
@NonNull
@Override
public Subscription untilDestroy(@NonNull final Completable completable, @NonNull final Action0 onCompletedAction) {
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction);
}
@NonNull
@Override
public Subscription untilDestroy(@NonNull final Completable completable,
@NonNull final Action0 onCompletedAction,
@NonNull final Action1<Throwable> onErrorAction) {
return baseLifecycleBindable.untilDestroy(completable, onCompletedAction, onErrorAction);
}
@SuppressWarnings("CPD-END")
//CPD: it is same as in other implementation based on BaseLifecycleBindable
/**

View File

@ -23,7 +23,9 @@ import android.support.annotation.NonNull;
import ru.touchin.roboswag.core.log.Lc;
import ru.touchin.roboswag.core.utils.ShouldNotHappenException;
import rx.Completable;
import rx.Observable;
import rx.Single;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.exceptions.OnErrorThrowable;
@ -36,8 +38,12 @@ import rx.subjects.BehaviorSubject;
* Created by Gavriil Sitnikov on 18/04/16.
* Simple implementation of {@link LifecycleBindable}. Could be used to not implement interface but use such object inside.
*/
@SuppressWarnings("PMD.TooManyMethods")
public class BaseLifecycleBindable implements LifecycleBindable {
private static final String UNTIL_DESTROY_METHOD = "untilDestroy";
private static final String UNTIL_STOP_METHOD = "untilStop";
@NonNull
private final BehaviorSubject<Boolean> isCreatedSubject = BehaviorSubject.create();
@NonNull
@ -77,26 +83,21 @@ public class BaseLifecycleBindable implements LifecycleBindable {
final String codePoint = Lc.getCodePoint(this, 2);
return isStartedSubject.switchMap(started -> started ? observable.observeOn(AndroidSchedulers.mainThread()) : Observable.never())
.takeUntil(isCreatedSubject.filter(created -> !created))
.subscribe(onNextAction,
throwable -> Lc.assertion(new ShouldNotHappenException("Unexpected error on untilStop at " + codePoint, throwable)));
.subscribe(onNextAction, getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD));
}
@NonNull
@Override
public <T> Subscription untilStop(@NonNull final Observable<T> observable) {
final String codePoint = Lc.getCodePoint(this, 2);
return untilStop(observable, Actions.empty(),
throwable -> Lc.assertion(new ShouldNotHappenException("Unexpected error on untilStop at " + codePoint, throwable)),
Actions.empty());
return untilStop(observable, Actions.empty(), getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD), Actions.empty());
}
@NonNull
@Override
public <T> Subscription untilStop(@NonNull final Observable<T> observable, @NonNull final Action1<T> onNextAction) {
final String codePoint = Lc.getCodePoint(this, 2);
return untilStop(observable, onNextAction,
throwable -> Lc.assertion(new ShouldNotHappenException("Unexpected error on untilStop at " + codePoint, throwable)),
Actions.empty());
return untilStop(observable, onNextAction, getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD), Actions.empty());
}
@NonNull
@ -116,13 +117,56 @@ public class BaseLifecycleBindable implements LifecycleBindable {
return until(observable, isStartedSubject.map(started -> !started), onNextAction, onErrorAction, onCompletedAction);
}
@NonNull
@Override
public <T> Subscription untilStop(@NonNull final Single<T> single) {
final String codePoint = Lc.getCodePoint(this, 2);
return untilStop(single, Actions.empty(), getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD));
}
@NonNull
@Override
public <T> Subscription untilStop(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
final String codePoint = Lc.getCodePoint(this, 2);
return untilStop(single, onSuccessAction, getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD));
}
@NonNull
@Override
public <T> Subscription untilStop(@NonNull final Single<T> single,
@NonNull final Action1<T> onSuccessAction,
@NonNull final Action1<Throwable> onErrorAction) {
return until(single.toObservable(), isStartedSubject.map(started -> !started), onSuccessAction, onErrorAction, Actions.empty());
}
@NonNull
@Override
public Subscription untilStop(@NonNull final Completable completable) {
final String codePoint = Lc.getCodePoint(this, 2);
return untilStop(completable, Actions.empty(), getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD));
}
@NonNull
@Override
public Subscription untilStop(@NonNull final Completable completable,
@NonNull final Action0 onCompletedAction) {
final String codePoint = Lc.getCodePoint(this, 2);
return untilStop(completable, onCompletedAction, getActionThrowableForAssertion(codePoint, UNTIL_STOP_METHOD));
}
@NonNull
@Override
public Subscription untilStop(@NonNull final Completable completable,
@NonNull final Action0 onCompletedAction,
@NonNull final Action1<Throwable> onErrorAction) {
return until(completable.toObservable(), isStartedSubject.map(started -> !started), Actions.empty(), onErrorAction, onCompletedAction);
}
@NonNull
@Override
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable) {
final String codePoint = Lc.getCodePoint(this, 2);
return untilDestroy(observable, Actions.empty(),
throwable -> Lc.assertion(new ShouldNotHappenException("Unexpected error on untilDestroy at " + codePoint, throwable)),
Actions.empty());
return untilDestroy(observable, Actions.empty(), getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD), Actions.empty());
}
@NonNull
@ -130,9 +174,7 @@ public class BaseLifecycleBindable implements LifecycleBindable {
public <T> Subscription untilDestroy(@NonNull final Observable<T> observable,
@NonNull final Action1<T> onNextAction) {
final String codePoint = Lc.getCodePoint(this, 2);
return untilDestroy(observable, onNextAction,
throwable -> Lc.assertion(new ShouldNotHappenException("Unexpected error on untilDestroy at " + codePoint, throwable)),
Actions.empty());
return untilDestroy(observable, onNextAction, getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD), Actions.empty());
}
@NonNull
@ -152,6 +194,51 @@ public class BaseLifecycleBindable implements LifecycleBindable {
return until(observable, isCreatedSubject.map(created -> !created), onNextAction, onErrorAction, onCompletedAction);
}
@NonNull
@Override
public <T> Subscription untilDestroy(@NonNull final Single<T> single) {
final String codePoint = Lc.getCodePoint(this, 2);
return untilDestroy(single, Actions.empty(), getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD));
}
@NonNull
@Override
public <T> Subscription untilDestroy(@NonNull final Single<T> single, @NonNull final Action1<T> onSuccessAction) {
final String codePoint = Lc.getCodePoint(this, 2);
return untilDestroy(single, onSuccessAction, getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD));
}
@NonNull
@Override
public <T> Subscription untilDestroy(@NonNull final Single<T> single,
@NonNull final Action1<T> onSuccessAction,
@NonNull final Action1<Throwable> onErrorAction) {
return until(single.toObservable(), isCreatedSubject.map(created -> !created), onSuccessAction, onErrorAction, Actions.empty());
}
@NonNull
@Override
public Subscription untilDestroy(@NonNull final Completable completable) {
final String codePoint = Lc.getCodePoint(this, 2);
return untilDestroy(completable, Actions.empty(), getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD));
}
@NonNull
@Override
public Subscription untilDestroy(@NonNull final Completable completable, @NonNull final Action0 onCompletedAction) {
final String codePoint = Lc.getCodePoint(this, 2);
return untilDestroy(completable, onCompletedAction, getActionThrowableForAssertion(codePoint, UNTIL_DESTROY_METHOD));
}
@NonNull
@Override
public Subscription untilDestroy(@NonNull final Completable completable,
@NonNull final Action0 onCompletedAction,
@NonNull final Action1<Throwable> onErrorAction) {
return until(completable.toObservable(), isCreatedSubject.map(created -> !created), Actions.empty(), onErrorAction, onCompletedAction);
}
@NonNull
private <T> Subscription until(@NonNull final Observable<T> observable,
@NonNull final Observable<Boolean> conditionSubject,
@ -178,4 +265,9 @@ public class BaseLifecycleBindable implements LifecycleBindable {
});
}
@NonNull
private Action1<Throwable> getActionThrowableForAssertion(@NonNull final String codePoint, @NonNull final String method) {
return throwable -> Lc.assertion(new ShouldNotHappenException("Unexpected error on " + method + " at " + codePoint, throwable));
}
}

View File

@ -21,7 +21,10 @@ package ru.touchin.roboswag.components.utils;
import android.support.annotation.NonNull;
import rx.Completable;
import rx.Observable;
import rx.Single;
import rx.SingleSubscriber;
import rx.Subscriber;
import rx.Subscription;
import rx.functions.Action0;
@ -36,10 +39,11 @@ import rx.functions.Func1;
* Use {@link #untilStop(Observable)} method to subscribe to observable where you want and unsubscribe onStop.
* Use {@link #untilDestroy(Observable)} method to subscribe to observable where you want and unsubscribe onDestroy.
*/
@SuppressWarnings("PMD.TooManyMethods")
public interface LifecycleBindable {
/**
* Method should be used to subscribe to observable while this element is in started state.
* Method should be used to subscribe to the observable while this element is in started state.
* Passed observable should NOT emit errors. It is illegal as in that case it stops emitting items and binding lost after error.
* If you want to process errors return something via {@link Observable#onErrorReturn(Func1)} method and process in onNextAction.
*
@ -53,7 +57,7 @@ public interface LifecycleBindable {
/**
* Method should be used to guarantee that observable won't be subscribed after onStop.
* It is automatically subscribing to observable.
* It is automatically subscribing to the observable.
* Usually it is using to stop requests/execution while element is off or to not do illegal actions after onStop like fragment's stack changing.
* Don't forget to process errors if observable can emit them.
*
@ -66,7 +70,7 @@ public interface LifecycleBindable {
/**
* Method should be used to guarantee that observable won't be subscribed after onStop.
* It is automatically subscribing to observable and calls onNextAction on every emitted item.
* It is automatically subscribing to the observable and calls onNextAction on every emitted item.
* Usually it is using to stop requests/execution while element is off or to not do illegal actions after onStop like fragment's stack changing.
* Don't forget to process errors if observable can emit them.
*
@ -80,7 +84,7 @@ public interface LifecycleBindable {
/**
* Method should be used to guarantee that observable won't be subscribed after onStop.
* It is automatically subscribing to observable and calls onNextAction, onErrorAction on observable events.
* It is automatically subscribing to the observable and calls onNextAction and onErrorAction on observable events.
* Usually it is using to stop requests/execution while element is off or to not do illegal actions after onStop like fragment's stack changing.
* Don't forget to process errors if observable can emit them.
*
@ -95,7 +99,7 @@ public interface LifecycleBindable {
/**
* Method should be used to guarantee that observable won't be subscribed after onStop.
* It is automatically subscribing to observable and calls onNextAction, onErrorAction, onCompletedAction on observable events.
* It is automatically subscribing to the observable and calls onNextAction, onErrorAction and onCompletedAction on observable events.
* Usually it is using to stop requests/execution while element is off or to not do illegal actions after onStop like fragment's stack changing.
* Don't forget to process errors if observable can emit them.
*
@ -104,54 +108,135 @@ public interface LifecycleBindable {
* @param onErrorAction Action which will raise on every {@link Subscriber#onError(Throwable)} throwable;
* @param onCompletedAction Action which will raise at {@link Subscriber#onCompleted()} on completion of observable;
* @param <T> Type of emitted by observable items;
* @return {@link Observable} which is wrapping source observable to unsubscribe from it onStop.
* @return {@link Subscription} which is wrapping source observable to unsubscribe from it onStop.
*/
@NonNull
<T> Subscription untilStop(@NonNull Observable<T> observable,
@NonNull Action1<T> onNextAction, @NonNull Action1<Throwable> onErrorAction, @NonNull Action0 onCompletedAction);
/**
* Method should be used to guarantee that single won't be subscribed after onStop.
* It is automatically subscribing to the single.
* Usually it is using to stop requests/execution while element is off or to not do illegal actions after onStop like fragment's stack changing.
* Don't forget to process errors if single can emit them.
*
* @param single {@link Single} to subscribe until onStop;
* @param <T> Type of emitted by single item;
* @return {@link Subscription} which will unsubscribes from single onStop.
*/
@NonNull
<T> Subscription untilStop(@NonNull Single<T> single);
/**
* Method should be used to guarantee that single won't be subscribed after onStop.
* It is automatically subscribing to the single and calls onSuccessAction on the emitted item.
* Usually it is using to stop requests/execution while element is off or to not do illegal actions after onStop like fragment's stack changing.
* Don't forget to process errors if single can emit them.
*
* @param single {@link Single} to subscribe until onStop;
* @param onSuccessAction Action which will raise on every {@link SingleSubscriber#onSuccess(Object)} item;
* @param <T> Type of emitted by single item;
* @return {@link Subscription} which will unsubscribes from single onStop.
*/
@NonNull
<T> Subscription untilStop(@NonNull Single<T> single, @NonNull Action1<T> onSuccessAction);
/**
* Method should be used to guarantee that single won't be subscribed after onStop.
* It is automatically subscribing to the single and calls onSuccessAction and onErrorAction on single events.
* Usually it is using to stop requests/execution while element is off or to not do illegal actions after onStop like fragment's stack changing.
* Don't forget to process errors if single can emit them.
*
* @param single {@link Single} to subscribe until onStop;
* @param onSuccessAction Action which will raise on every {@link SingleSubscriber#onSuccess(Object)} item;
* @param onErrorAction Action which will raise on every {@link SingleSubscriber#onError(Throwable)} throwable;
* @param <T> Type of emitted by observable items;
* @return {@link Subscription} which is wrapping source single to unsubscribe from it onStop.
*/
@NonNull
<T> Subscription untilStop(@NonNull Single<T> single, @NonNull Action1<T> onSuccessAction, @NonNull Action1<Throwable> onErrorAction);
/**
* Method should be used to guarantee that completable won't be subscribed after onStop.
* It is automatically subscribing to the completable.
* Usually it is using to stop requests/execution while element is off or to not do illegal actions after onStop like fragment's stack changing.
* Don't forget to process errors if completable can emit them.
*
* @param completable {@link Completable} to subscribe until onStop;
* @return {@link Subscription} which will unsubscribes from completable onStop.
*/
@NonNull
Subscription untilStop(@NonNull Completable completable);
/**
* Method should be used to guarantee that completable won't be subscribed after onStop.
* It is automatically subscribing to the completable and calls onCompletedAction on completable item.
* Usually it is using to stop requests/execution while element is off or to not do illegal actions after onStop like fragment's stack changing.
* Don't forget to process errors if completable can emit them.
*
* @param completable {@link Completable} to subscribe until onStop;
* @param onCompletedAction Action which will raise at {@link Completable.CompletableSubscriber#onCompleted()} on completion of observable;
* @return {@link Subscription} which is wrapping source completable to unsubscribe from it onStop.
*/
@NonNull
Subscription untilStop(@NonNull Completable completable, @NonNull Action0 onCompletedAction);
/**
* Method should be used to guarantee that completable won't be subscribed after onStop.
* It is automatically subscribing to the completable and calls onCompletedAction and onErrorAction on completable item.
* Usually it is using to stop requests/execution while element is off or to not do illegal actions after onStop like fragment's stack changing.
* Don't forget to process errors if completable can emit them.
*
* @param completable {@link Completable} to subscribe until onStop;
* @param onCompletedAction Action which will raise at {@link Completable.CompletableSubscriber#onCompleted()} on completion of observable;
* @param onErrorAction Action which will raise on every {@link Completable.CompletableSubscriber#onError(Throwable)} throwable;
* @return {@link Subscription} which is wrapping source completable to unsubscribe from it onStop.
*/
@NonNull
Subscription untilStop(@NonNull Completable completable, @NonNull Action0 onCompletedAction, @NonNull Action1<Throwable> onErrorAction);
/**
* Method should be used to guarantee that observable won't be subscribed after onDestroy.
* It is automatically subscribing to observable.
* It is automatically subscribing to the observable.
* Don't forget to process errors if observable can emit them.
*
* @param observable {@link Observable} to subscribe until onDestroy;
* @param <T> Type of emitted by observable items;
* @return {@link Observable} which is wrapping source observable to unsubscribe from it onDestroy.
* @return {@link Subscription} which is wrapping source observable to unsubscribe from it onDestroy.
*/
@NonNull
<T> Subscription untilDestroy(@NonNull Observable<T> observable);
/**
* Method should be used to guarantee that observable won't be subscribed after onDestroy.
* It is automatically subscribing to observable and calls onNextAction on every emitted item.
* It is automatically subscribing to the observable and calls onNextAction on every emitted item.
* Don't forget to process errors if observable can emit them.
*
* @param observable {@link Observable} to subscribe until onDestroy;
* @param onNextAction Action which will raise on every {@link Subscriber#onNext(Object)} item;
* @param <T> Type of emitted by observable items;
* @return {@link Observable} which is wrapping source observable to unsubscribe from it onDestroy.
* @return {@link Subscription} which is wrapping source observable to unsubscribe from it onDestroy.
*/
@NonNull
<T> Subscription untilDestroy(@NonNull Observable<T> observable, @NonNull Action1<T> onNextAction);
/**
* Method should be used to guarantee that observable won't be subscribed after onDestroy.
* It is automatically subscribing to observable and calls onNextAction, onErrorAction on observable events.
* It is automatically subscribing to the observable and calls onNextAction and onErrorAction on observable events.
* Don't forget to process errors if observable can emit them.
*
* @param observable {@link Observable} to subscribe until onDestroy;
* @param onNextAction Action which will raise on every {@link Subscriber#onNext(Object)} item;
* @param onErrorAction Action which will raise on every {@link Subscriber#onError(Throwable)} throwable;
* @param <T> Type of emitted by observable items;
* @return {@link Observable} which is wrapping source observable to unsubscribe from it onDestroy.
* @return {@link Subscription} which is wrapping source observable to unsubscribe from it onDestroy.
*/
@NonNull
<T> Subscription untilDestroy(@NonNull Observable<T> observable, @NonNull Action1<T> onNextAction, @NonNull Action1<Throwable> onErrorAction);
/**
* Method should be used to guarantee that observable won't be subscribed after onDestroy.
* It is automatically subscribing to observable and calls onNextAction, onErrorAction, onCompletedAction on observable events.
* It is automatically subscribing to the observable and calls onNextAction, onErrorAction and onCompletedAction on observable events.
* Don't forget to process errors if observable can emit them.
*
* @param observable {@link Observable} to subscribe until onDestroy;
@ -159,10 +244,85 @@ public interface LifecycleBindable {
* @param onErrorAction Action which will raise on every {@link Subscriber#onError(Throwable)} throwable;
* @param onCompletedAction Action which will raise at {@link Subscriber#onCompleted()} on completion of observable;
* @param <T> Type of emitted by observable items;
* @return {@link Observable} which is wrapping source observable to unsubscribe from it onDestroy.
* @return {@link Subscription} which is wrapping source observable to unsubscribe from it onDestroy.
*/
@NonNull
<T> Subscription untilDestroy(@NonNull Observable<T> observable,
@NonNull Action1<T> onNextAction, @NonNull Action1<Throwable> onErrorAction, @NonNull Action0 onCompletedAction);
/**
* Method should be used to guarantee that single won't be subscribed after onDestroy.
* It is automatically subscribing to the single.
* Don't forget to process errors if single can emit them.
*
* @param single {@link Single} to subscribe until onDestroy;
* @param <T> Type of emitted by single items;
* @return {@link Subscription} which is wrapping source single to unsubscribe from it onDestroy.
*/
@NonNull
<T> Subscription untilDestroy(@NonNull Single<T> single);
/**
* Method should be used to guarantee that single won't be subscribed after onDestroy.
* It is automatically subscribing to the single and calls onSuccessAction on every emitted item.
* Don't forget to process errors if single can emit them.
*
* @param single {@link Single} to subscribe until onDestroy;
* @param onSuccessAction Action which will raise on every {@link SingleSubscriber#onSuccess(Object)} item;
* @param <T> Type of emitted by single items;
* @return {@link Subscription} which is wrapping source single to unsubscribe from it onDestroy.
*/
@NonNull
<T> Subscription untilDestroy(@NonNull Single<T> single, @NonNull Action1<T> onSuccessAction);
/**
* Method should be used to guarantee that single won't be subscribed after onDestroy.
* It is automatically subscribing to the single and calls onSuccessAction and onErrorAction on single events.
* Don't forget to process errors if single can emit them.
*
* @param single {@link Single} to subscribe until onDestroy;
* @param onSuccessAction Action which will raise on every {@link SingleSubscriber#onSuccess(Object)} item;
* @param onErrorAction Action which will raise on every {@link SingleSubscriber#onError(Throwable)} throwable;
* @param <T> Type of emitted by single items;
* @return {@link Subscription} which is wrapping source single to unsubscribe from it onDestroy.
*/
@NonNull
<T> Subscription untilDestroy(@NonNull Single<T> single, @NonNull Action1<T> onSuccessAction, @NonNull Action1<Throwable> onErrorAction);
/**
* Method should be used to guarantee that completable won't be subscribed after onDestroy.
* It is automatically subscribing to the completable.
* Don't forget to process errors if completable can emit them.
*
* @param completable {@link Completable} to subscribe until onDestroy;
* @return {@link Subscription} which is wrapping source completable to unsubscribe from it onDestroy.
*/
@NonNull
Subscription untilDestroy(@NonNull Completable completable);
/**
* Method should be used to guarantee that completable won't be subscribed after onDestroy.
* It is automatically subscribing to the completable and calls onCompletedAction on completable item.
* Don't forget to process errors if single can emit them.
*
* @param completable {@link Completable} to subscribe until onDestroy;
* @param onCompletedAction Action which will raise on every {@link Completable.CompletableSubscriber#onCompleted()} item;
* @return {@link Subscription} which is wrapping source single to unsubscribe from it onDestroy.
*/
@NonNull
Subscription untilDestroy(@NonNull Completable completable, @NonNull Action0 onCompletedAction);
/**
* Method should be used to guarantee that completable won't be subscribed after onDestroy.
* It is automatically subscribing to the completable and calls onCompletedAction and onErrorAction on completable events.
* Don't forget to process errors if completable can emit them.
*
* @param completable {@link Completable} to subscribe until onDestroy;
* @param onCompletedAction Action which will raise on every {@link Completable.CompletableSubscriber#onCompleted()} item;
* @param onErrorAction Action which will raise on every {@link Completable.CompletableSubscriber#onError(Throwable)} throwable;
* @return {@link Subscription} which is wrapping source completable to unsubscribe from it onDestroy.
*/
@NonNull
Subscription untilDestroy(@NonNull Completable completable, @NonNull Action0 onCompletedAction, @NonNull Action1<Throwable> onErrorAction);
}