Java Code Examples for io.reactivex.Flowable#takeUntil()

The following examples show how to use io.reactivex.Flowable#takeUntil() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RxAutoCleanDelegate.java    From BaseProject with MIT License 6 votes vote down vote up
/**
 * 绑定一个 Activity、Fragment 的生命周期,自动释放资源
 * <br/>
 * 例如:网络请求时绑定{@link ActivityEvent#STOP} 或 {@link FragmentEvent#STOP},
 * onStop()时会自动取消网络请求.
 *
 * @param event 事件类型
 * @see ActivityEvent
 * @see FragmentEvent
 */
@SuppressWarnings("SpellCheckingInspection")
@Override
public <Type> FlowableTransformer<Type, Type> bindEventWithFlowable(final int event) {
    final Flowable<Integer> observable = mBehaviorSubject
            .toFlowable(BackpressureStrategy.LATEST)
            .filter(new Predicate<Integer>() {
                @Override
                public boolean test(Integer integer) throws Exception {
                    return integer == event;
                }
            })
            .take(1);

    return new FlowableTransformer<Type, Type>() {
        @Override
        public Publisher<Type> apply(@io.reactivex.annotations.NonNull Flowable<Type> upstream) {
            return upstream.takeUntil(observable);
        }
    };
}
 
Example 2
Source File: RxAutoCleanDelegate.java    From BaseProject with MIT License 6 votes vote down vote up
/**
 * 绑定一个 Activity、Fragment 的生命周期,自动释放资源
 * <br/>
 * 例如:网络请求时绑定{@link ActivityEvent#STOP} 或 {@link FragmentEvent#STOP},
 * onStop()时会自动取消网络请求.
 *
 * @param event 事件类型
 * @see ActivityEvent
 * @see FragmentEvent
 */
@SuppressWarnings("SpellCheckingInspection")
@Override
public <Type> FlowableTransformer<Type, Type> bindEventWithFlowable(final int event) {
    final Flowable<Integer> observable = mBehaviorSubject
            .toFlowable(BackpressureStrategy.LATEST)
            .filter(new Predicate<Integer>() {
                @Override
                public boolean test(Integer integer) throws Exception {
                    return integer == event;
                }
            })
            .take(1);

    return new FlowableTransformer<Type, Type>() {
        @Override
        public Publisher<Type> apply(@io.reactivex.annotations.NonNull Flowable<Type> upstream) {
            return upstream.takeUntil(observable);
        }
    };
}
 
Example 3
Source File: LifecycleTransformer.java    From Tangram-Android with MIT License 4 votes vote down vote up
@Override
public Publisher<T> apply(Flowable<T> upstream) {
    return upstream.takeUntil(mObservable.toFlowable(BackpressureStrategy.LATEST));
}
 
Example 4
Source File: RxLifecycleTransformer.java    From pandroid with Apache License 2.0 4 votes vote down vote up
@Override
public Publisher<T> apply(Flowable<T> upstream) {
    return upstream.takeUntil(mObservable.toFlowable(BackpressureStrategy.LATEST));
}
 
Example 5
Source File: LifecycleTransformer.java    From recyclerview-binder with Apache License 2.0 4 votes vote down vote up
@Override
public Publisher<T> apply(Flowable<T> upstream) {
    return upstream.takeUntil(observable.toFlowable(BackpressureStrategy.LATEST));
}