use of io.reactivex.functions.Function3 in project Shuttle by timusus.
the class FolderFragment method changeDir.
@SuppressLint("CheckResult")
public void changeDir(File newDir) {
if (setItemsDisposable != null) {
setItemsDisposable.dispose();
}
disposables.add(Single.zip(DataManager.getInstance().getIncludeItems().first(Collections.emptyList()), DataManager.getInstance().getExcludeItems().first(Collections.emptyList()), Single.fromCallable(() -> {
final String path = FileHelper.getPath(newDir);
if (TextUtils.isEmpty(path)) {
return new ArrayList<>();
}
currentDir = path;
return fileBrowser.loadDir(new File(path));
}), (Function3<List<InclExclItem>, List<InclExclItem>, List<BaseFileObject>, List<ViewModel>>) (whitelist, blacklist, baseFileObjects) -> {
List<ViewModel> items = Stream.of(baseFileObjects).map(baseFileObject -> {
// Look for an existing FolderView wrapping the BaseFileObject, we'll reuse it if it exists.
FolderView folderView = (FolderView) Stream.of(adapter.items).filter(viewModel -> viewModel instanceof FolderView && (((FolderView) viewModel).baseFileObject.equals(baseFileObject))).findFirst().orElse(null);
if (folderView == null) {
folderView = new FolderView(baseFileObject, Stream.of(whitelist).anyMatch(inclExclItem -> inclExclItem.path.equals(baseFileObject.path)), Stream.of(blacklist).anyMatch(inclExclItem -> inclExclItem.path.equals(baseFileObject.path)));
folderView.setShowWhitelist(isShowingWhitelist);
folderView.setShowBlacklist(isShowingBlacklist);
folderView.setClickListener(FolderFragment.this);
}
return folderView;
}).collect(Collectors.toList());
if (showBreadcrumbsInList && breadcrumbsView != null) {
breadcrumbsView.setBreadcrumbsPath(currentDir);
breadcrumbsView.setListener(FolderFragment.this);
items.add(0, breadcrumbsView);
}
return items;
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
if (adapter != null) {
setItemsDisposable = adapter.setItems(adaptableItems);
}
if (breadcrumb != null) {
breadcrumb.changeBreadcrumbPath(currentDir);
}
if (adapter != null) {
changeBreadcrumbPath();
}
updateMenuItems();
}, error -> LogUtils.logException(TAG, "Error changing dir", error)));
}
use of io.reactivex.functions.Function3 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());
}
});
}
Aggregations