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);
}
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();
}
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());
}
});
}
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)));
}
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);
}
}
}));
}
Aggregations