Java Code Examples for io.reactivex.Observable#subscribeWith()

The following examples show how to use io.reactivex.Observable#subscribeWith() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@Test public void test(){
    Observable<Todo> todoObservable = Observable.create(new ObservableOnSubscribe<Todo>() {
        @Override
        public void subscribe(ObservableEmitter<Todo> emitter) throws Exception {
            try {
                List<Todo> todos = RxJavaUnitTest.this.getTodos();
                if (todos!=null){
                    throw new NullPointerException("todos was null");
                }
                for (Todo todo : todos) {
                    emitter.onNext(todo);
                }
                emitter.onComplete();
            } catch (Exception e) {
                emitter.onError(e);
            }
        }
    });
    TestObserver<Object> testObserver = new TestObserver<>();
    todoObservable.subscribeWith(testObserver);
    testObserver.assertError(NullPointerException.class);

}
 
Example 2
Source Project: RxEasyHttp   File: PostRequest.java    License: Apache License 2.0 5 votes vote down vote up
public <T> Disposable execute(CallBackProxy<? extends ApiResult<T>, T> proxy) {
    Observable<CacheResult<T>> observable = build().toObservable(generateRequest(), proxy);
    if (CacheResult.class != proxy.getCallBack().getRawType()) {
        return observable.compose(new ObservableTransformer<CacheResult<T>, T>() {
            @Override
            public ObservableSource<T> apply(@NonNull Observable<CacheResult<T>> upstream) {
                return upstream.map(new CacheResultFunc<T>());
            }
        }).subscribeWith(new CallBackSubsciber<T>(context, proxy.getCallBack()));
    } else {
        return observable.subscribeWith(new CallBackSubsciber<CacheResult<T>>(context, proxy.getCallBack()));
    }
}
 
Example 3
Source Project: RxEasyHttp   File: GetRequest.java    License: Apache License 2.0 5 votes vote down vote up
public <T> Disposable execute(CallBackProxy<? extends ApiResult<T>, T> proxy) {
    Observable<CacheResult<T>> observable = build().toObservable(apiManager.get(url, params.urlParamsMap), proxy);
    if (CacheResult.class != proxy.getCallBack().getRawType()) {
        return observable.compose(new ObservableTransformer<CacheResult<T>, T>() {
            @Override
            public ObservableSource<T> apply(@NonNull Observable<CacheResult<T>> upstream) {
                return upstream.map(new CacheResultFunc<T>());
            }
        }).subscribeWith(new CallBackSubsciber<T>(context, proxy.getCallBack()));
    } else {
        return observable.subscribeWith(new CallBackSubsciber<CacheResult<T>>(context, proxy.getCallBack()));
    }
}
 
Example 4
Source Project: RxEasyHttp   File: CustomRequest.java    License: Apache License 2.0 5 votes vote down vote up
public <T> Disposable call(Observable<T> observable, CallBackProxy<? extends ApiResult<T>, T> proxy) {
    Observable<CacheResult<T>> cacheobservable = build().toObservable(observable, proxy);
    if (CacheResult.class != proxy.getCallBack().getRawType()) {
        return cacheobservable.compose(new ObservableTransformer<CacheResult<T>, T>() {
            @Override
            public ObservableSource<T> apply(@NonNull Observable<CacheResult<T>> upstream) {
                return upstream.map(new CacheResultFunc<T>());
            }
        }).subscribeWith(new CallBackSubsciber<T>(context, proxy.getCallBack()));
    } else {
        return cacheobservable.subscribeWith(new CallBackSubsciber<CacheResult<T>>(context, proxy.getCallBack()));
    }
}
 
Example 5
Source Project: RxEasyHttp   File: PutRequest.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> Disposable execute(CallBackProxy<? extends ApiResult<T>, T> proxy) {
    Observable<CacheResult<T>> observable = build().toObservable(generateRequest(), proxy);
    if (CacheResult.class != proxy.getCallBack().getRawType()) {
        return observable.compose(new ObservableTransformer<CacheResult<T>, T>() {
            @Override
            public ObservableSource<T> apply(@NonNull Observable<CacheResult<T>> upstream) {
                return upstream.map(new CacheResultFunc<T>());
            }
        }).subscribeWith(new CallBackSubsciber<T>(context, proxy.getCallBack()));
    } else {
        return observable.subscribeWith(new CallBackSubsciber<CacheResult<T>>(context, proxy.getCallBack()));
    }
}
 
Example 6
Source Project: RxEasyHttp   File: DeleteRequest.java    License: Apache License 2.0 5 votes vote down vote up
public <T> Disposable execute(CallBackProxy<? extends ApiResult<T>, T> proxy) {
    Observable<CacheResult<T>> observable = build().toObservable(generateRequest(), proxy);
    if (CacheResult.class != proxy.getCallBack().getRawType()) {
        return observable.compose(new ObservableTransformer<CacheResult<T>, T>() {
            @Override
            public ObservableSource<T> apply(@NonNull Observable<CacheResult<T>> upstream) {
                return upstream.map(new CacheResultFunc<T>());
            }
        }).subscribeWith(new CallBackSubsciber<T>(context, proxy.getCallBack()));
    } else {
        return observable.subscribeWith(new CallBackSubsciber<CacheResult<T>>(context, proxy.getCallBack()));
    }
}
 
Example 7
Source Project: mosby   File: MviBasePresenter.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * This method subscribes the Observable emitting {@code ViewState} over time to the passed
 * consumer.
 * <b>Only invoke this method once! Typically, in {@link #bindIntents()}</b>
 * <p>
 * Internally, Mosby will hold some relays to ensure that no items emitted from the ViewState
 * Observable will be lost while viewState is not attached nor that the subscriptions to
 * viewState intents will cause memory leaks while viewState detached.
 * </p>
 * <p>
 * Typically, this method is used in {@link #bindIntents()}  like this:
 * <pre><code>
 *   Observable<MyViewState> viewState =  ... ;
 *   subscribeViewStateConsumerActually(viewState, new ViewStateConsumer() {
 *      @Override
 *      public void accept(MyView view, MyViewState viewState){
 *         view.render(viewState);
 *      }
 *   }
 * </code></pre>
 *
 * @param viewStateObservable The Observable emitting new ViewState. Typically, an intent {@link
 *                            #intent(ViewIntentBinder)} causes the underlying business logic to do a change and eventually
 *                            create a new ViewState.
 * @param consumer            {@link ViewStateConsumer} The consumer that will update ("render") the view.
 */
@MainThread
protected void subscribeViewState(@NonNull Observable<VS> viewStateObservable,
                                  @NonNull ViewStateConsumer<V, VS> consumer) {
    if (subscribeViewStateMethodCalled) {
        throw new IllegalStateException(
                "subscribeViewState() method is only allowed to be called once");
    }
    subscribeViewStateMethodCalled = true;

    if (viewStateObservable == null) {
        throw new NullPointerException("ViewState Observable is null");
    }

    if (consumer == null) {
        throw new NullPointerException("ViewStateBinder is null");
    }

    this.viewStateConsumer = consumer;

    viewStateDisposable = viewStateObservable.subscribeWith(
            new DisposableViewStateObserver<>(viewStateBehaviorSubject));
}