Search in sources :

Example 26 with NonNull

use of io.reactivex.annotations.NonNull in project Varis-Android by dkhmelenko.

the class BuildsDetailsPresenter method cancelBuild.

/**
     * Cancels build process
     */
public void cancelBuild() {
    RequestBody emptyBody = RequestBody.create(MediaType.parse("application/json"), "");
    Disposable subscription = mTravisRestClient.getApiService().cancelBuild(mBuildId, emptyBody).onErrorReturn(throwable -> new Object()).flatMap(new Function<Object, SingleSource<BuildDetails>>() {

        @Override
        public SingleSource<BuildDetails> apply(@NonNull Object o) throws Exception {
            return mTravisRestClient.getApiService().getBuild(mRepoSlug, mBuildId);
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe((buildDetails, throwable) -> {
        if (throwable == null) {
            handleBuildDetails(buildDetails);
        } else {
            handleLoadingFailed(throwable);
        }
    });
    mSubscriptions.add(subscription);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Function(io.reactivex.functions.Function) BuildDetails(com.khmelenko.lab.varis.network.response.BuildDetails) NonNull(io.reactivex.annotations.NonNull) RequestBody(okhttp3.RequestBody)

Example 27 with NonNull

use of io.reactivex.annotations.NonNull in project Varis-Android by dkhmelenko.

the class BuildsDetailsPresenter method startLoadingData.

/**
 * Starts loading data
 *
 * @param intentUrl Intent URL
 * @param repoSlug  Repository slug
 * @param buildId   Build ID
 */
public void startLoadingData(String intentUrl, String repoSlug, long buildId) {
    mRepoSlug = repoSlug;
    mBuildId = buildId;
    Single<BuildDetails> buildDetailsSingle;
    if (!StringUtils.isEmpty(intentUrl)) {
        buildDetailsSingle = mRawClient.singleRequest(intentUrl).doOnSuccess(response -> {
            String redirectUrl = intentUrl;
            if (response.isRedirect()) {
                redirectUrl = response.header("Location", "");
            }
            parseIntentUrl(redirectUrl);
        }).flatMap(new Function<okhttp3.Response, SingleSource<BuildDetails>>() {

            @Override
            public SingleSource<BuildDetails> apply(@NonNull okhttp3.Response response) throws Exception {
                return mTravisRestClient.getApiService().getBuild(mRepoSlug, mBuildId);
            }
        });
    } else {
        buildDetailsSingle = mTravisRestClient.getApiService().getBuild(mRepoSlug, mBuildId);
    }
    Disposable subscription = buildDetailsSingle.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe((buildDetails, throwable) -> {
        if (throwable == null) {
            handleBuildDetails(buildDetails);
        } else {
            handleLoadingFailed(throwable);
        }
    });
    mSubscriptions.add(subscription);
    getView().showProgress();
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Function(io.reactivex.functions.Function) BuildDetails(com.khmelenko.lab.varis.network.response.BuildDetails) NonNull(io.reactivex.annotations.NonNull)

Example 28 with NonNull

use of io.reactivex.annotations.NonNull in project Mvp-Rxjava-Retrofit-dagger2 by pengMaster.

the class RecordSuperviseListPresenter method downLoadSuperviseRecordBaseInfo.

/**
 * 下载监督记录基本信息
 *
 * @param id
 */
public void downLoadSuperviseRecordBaseInfo(final String id) {
    Observable<SuperviseContentGsonBean> superviseContent = mModel.getSuperviseContentNet(id);
    Observable<superviseForm> recordBaseInfo = mModel.getRecordBaseInfo(id);
    Observable<LawDocumentGsonBean> lawFileNet = mModel.getLawFileNet(id);
    Observable.zip(recordBaseInfo, superviseContent, lawFileNet, new Function3<superviseForm, SuperviseContentGsonBean, LawDocumentGsonBean, RecordBaseGsonBean>() {

        @Override
        public RecordBaseGsonBean apply(@NonNull superviseForm superviseForm, @NonNull SuperviseContentGsonBean categoryResult, @NonNull LawDocumentGsonBean lawDocumentGsonBean) throws Exception {
            // 合并两次请求的结果
            RecordBaseGsonBean baseGsonBean = new RecordBaseGsonBean();
            baseGsonBean.setSuperviseForm(superviseForm);
            baseGsonBean.setCategoryResult(categoryResult);
            baseGsonBean.setLawDocumentGsonBean(lawDocumentGsonBean);
            baseGsonBean.setId(id);
            return baseGsonBean;
        }
    }).subscribeOn(Schedulers.io()).doOnSubscribe(new // 在执行任务前,做准备操作
    Consumer<Disposable>() {

        @Override
        public void accept(Disposable disposable) throws Exception {
            // 在执行任务之前 do some thing ...
            mRootView.showLoading();
        }
    }).observeOn(AndroidSchedulers.mainThread()).doFinally(new // 任务结束 do some thing ...
    Action() {

        @Override
        public void run() throws Exception {
            mRootView.hideLoading();
        }
    }).subscribe(new Consumer<RecordBaseGsonBean>() {

        @Override
        public void accept(@NonNull RecordBaseGsonBean recordBaseGsonBean) throws Exception {
            mRootView.hideLoading();
            mRootView.startActivity(recordBaseGsonBean);
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(@NonNull Throwable throwable) throws Exception {
            ToastUtils.showShort(throwable.getMessage());
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) Action(io.reactivex.functions.Action) Function3(io.reactivex.functions.Function3) SuperviseContentGsonBean(com.mtm.mrecord.mvp.model.entity.SuperviseContentGsonBean) com.mtm.mrecord.mvp.model.entity.superviseForm(com.mtm.mrecord.mvp.model.entity.superviseForm) Consumer(io.reactivex.functions.Consumer) NonNull(io.reactivex.annotations.NonNull) LawDocumentGsonBean(com.mtm.mrecord.mvp.model.entity.LawDocumentGsonBean) RecordBaseGsonBean(com.mtm.mrecord.mvp.model.entity.RecordBaseGsonBean)

Example 29 with NonNull

use of io.reactivex.annotations.NonNull in project Shuttle by timusus.

the class AestheticCheckBox method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    subscriptions = new CompositeDisposable();
    // noinspection ConstantConditions
    subscriptions.add(Observable.combineLatest(ViewUtil.getObservableForResId(getContext(), backgroundResId, Aesthetic.get(getContext()).colorAccent()), Aesthetic.get(getContext()).isDark(), ColorIsDarkState.creator()).compose(Rx.<ColorIsDarkState>distinctToMainThread()).subscribe(new Consumer<ColorIsDarkState>() {

        @Override
        public void accept(@NonNull ColorIsDarkState colorIsDarkState) {
            invalidateColors(colorIsDarkState);
        }
    }, onErrorLogAndRethrow()));
    subscriptions.add(Aesthetic.get(getContext()).textColorPrimary().compose(Rx.<Integer>distinctToMainThread()).subscribe(ViewTextColorAction.create(this)));
}
Also used : Consumer(io.reactivex.functions.Consumer) NonNull(io.reactivex.annotations.NonNull) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 30 with NonNull

use of io.reactivex.annotations.NonNull in project android-mvp-architecture by MindorksOpenSource.

the class BlogPresenter method onViewPrepared.

@Override
public void onViewPrepared() {
    getMvpView().showLoading();
    getCompositeDisposable().add(getDataManager().getBlogApiCall().subscribeOn(getSchedulerProvider().io()).observeOn(getSchedulerProvider().ui()).subscribe(new Consumer<BlogResponse>() {

        @Override
        public void accept(@NonNull BlogResponse blogResponse) throws Exception {
            if (blogResponse != null && blogResponse.getData() != null) {
                getMvpView().updateBlog(blogResponse.getData());
            }
            getMvpView().hideLoading();
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(@NonNull Throwable throwable) throws Exception {
            if (!isViewAttached()) {
                return;
            }
            getMvpView().hideLoading();
            // handle the error here
            if (throwable instanceof ANError) {
                ANError anError = (ANError) throwable;
                handleApiError(anError);
            }
        }
    }));
}
Also used : Consumer(io.reactivex.functions.Consumer) NonNull(io.reactivex.annotations.NonNull) BlogResponse(com.mindorks.framework.mvp.data.network.model.BlogResponse) ANError(com.androidnetworking.error.ANError)

Aggregations

NonNull (io.reactivex.annotations.NonNull)39 Disposable (io.reactivex.disposables.Disposable)17 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)15 Consumer (io.reactivex.functions.Consumer)14 Function (io.reactivex.functions.Function)13 BuildDetails (com.khmelenko.lab.varis.network.response.BuildDetails)6 OnClick (butterknife.OnClick)5 List (java.util.List)5 RequestBody (okhttp3.RequestBody)5 ObservableEmitter (io.reactivex.ObservableEmitter)4 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Headers (okhttp3.Headers)3 View (android.view.View)2 ANError (com.androidnetworking.error.ANError)2 User (com.khmelenko.lab.varis.network.response.User)2 LzyResponse (com.lzy.demo.model.LzyResponse)2 ServerModel (com.lzy.demo.model.ServerModel)2 Action (io.reactivex.functions.Action)2