当前位置: 首页>>代码示例>>Java>>正文


Java ObservableTransformer类代码示例

本文整理汇总了Java中io.reactivex.ObservableTransformer的典型用法代码示例。如果您正苦于以下问题:Java ObservableTransformer类的具体用法?Java ObservableTransformer怎么用?Java ObservableTransformer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ObservableTransformer类属于io.reactivex包,在下文中一共展示了ObservableTransformer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: actionsToResults

import io.reactivex.ObservableTransformer; //导入依赖的package包/类
@Override
protected ObservableTransformer<Action, Result> actionsToResults() {
    return upstream -> {

        final Observable<EmailLoginActions.LoginAction> loginActionObservable = upstream
                .ofType(EmailLoginActions.LoginAction.class);
        return loginActionObservable
                .flatMap(loginAction -> {
                    if (!Patterns.EMAIL_ADDRESS.matcher(loginAction.getEmail()).matches()) {
                        return Observable.just(Result.<Boolean, EmailLoginActions.LoginAction>error(loginAction, new FormValidationException("Must enter a valid email address!")));
                    }
                    if (!Pattern.compile("[0-9a-zA-Z]{6,}").matcher(loginAction.getPassword()).matches()) {
                        return Observable.just(Result.<Boolean, EmailLoginActions.LoginAction>error(loginAction, new FormValidationException("Password must be at least 6 characters long!")));
                    }
                    return useCase.performAction(loginAction)
                            .onErrorReturn(throwable -> Result.error(loginAction, throwable))
                            .startWith(Result.<Boolean, EmailLoginActions.LoginAction>loading(loginAction));
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io());

    };
}
 
开发者ID:sztomek,项目名称:cleanarchitecture-unidirectional,代码行数:24,代码来源:EmailLoginPresenter.java

示例2: checkWechatResult

import io.reactivex.ObservableTransformer; //导入依赖的package包/类
public static ObservableTransformer<WxPayResult, WxPayResult> checkWechatResult() {
    return new ObservableTransformer<WxPayResult, WxPayResult>() {
        @Override
        public ObservableSource<WxPayResult> apply(Observable<WxPayResult> payResultObservable) {
            return payResultObservable.map(new Function<WxPayResult, WxPayResult>() {
                @Override
                public WxPayResult apply(WxPayResult wxPayResult) {
                    if (!wxPayResult.isSucceed()) {
                        throw new PayFailedException(wxPayResult.getErrInfo());
                    }
                    return wxPayResult;
                }
            });
        }
    };
}
 
开发者ID:simplezhli,项目名称:RxPay,代码行数:17,代码来源:RxPayUtils.java

示例3: compose

import io.reactivex.ObservableTransformer; //导入依赖的package包/类
public static <T> ObservableTransformer<T, T> compose() {
    return new ObservableTransformer<T, T>() {
        @Override
        public ObservableSource<T> apply(Observable<T> observable) {
            return observable
                    .subscribeOn(Schedulers.io())
                    .doOnSubscribe(new Consumer<Disposable>() {
                        @Override
                        public void accept(Disposable disposable) throws Exception {
                            if (!Utils.isNetworkAvailable()) {
                                //disposable.dispose();
                                //throw new NetworkNoAvailableException("no network,please check and retry");
                                //Utils.MakeShortToast("no network,please check and retry");
                                //throw new Exception();
                            }
                        }
                    })
                    .observeOn(AndroidSchedulers.mainThread());
        }
    };
}
 
开发者ID:nowandfurure,项目名称:richeditor,代码行数:22,代码来源:RxSchedulers.java

示例4: logObservable

import io.reactivex.ObservableTransformer; //导入依赖的package包/类
/**
 * Creates transform operator, which logs defined events in observable's lifecycle
 * @param msg     message
 * @param bitMask bitmask of events which you want to log
 * @param <T>     type
 * @return transformer
 */
public static <T> ObservableTransformer<T, T> logObservable(final String msg, final int bitMask) {
    return upstream -> {
        if ((bitMask & LOG_SUBSCRIBE) > 0) {
            upstream = upstream.compose(oLogSubscribe(msg));
        }
        if ((bitMask & LOG_TERMINATE) > 0) {
            upstream = upstream.compose(oLogTerminate(msg));
        }
        if ((bitMask & LOG_ERROR) > 0) {
            upstream = upstream.compose(oLogError(msg));
        }
        if ((bitMask & LOG_COMPLETE) > 0) {
            upstream = upstream.compose(oLogComplete(msg));
        }
        if ((bitMask & LOG_NEXT_DATA) > 0) {
            upstream = upstream.compose(oLogNext(msg));
        } else if ((bitMask & LOG_NEXT_EVENT) > 0) {
            upstream = upstream.compose(oLogNextEvent(msg));
        }
        if ((bitMask & LOG_DISPOSE) > 0) {
            upstream = upstream.compose(oLogDispose(msg));
        }
        return upstream;
    };
}
 
开发者ID:Team-SOFTsk,项目名称:RxLog,代码行数:33,代码来源:RxLog.java

示例5: applySchedulers

import io.reactivex.ObservableTransformer; //导入依赖的package包/类
public static <T> ObservableTransformer<T, T> applySchedulers(final IView view) {
    return new ObservableTransformer<T, T>() {
        @Override
        public Observable<T> apply(Observable<T> observable) {
            return observable.subscribeOn(Schedulers.io())
                    .doOnSubscribe(new Consumer<Disposable>() {
                        @Override
                        public void accept(@NonNull Disposable disposable) throws Exception {
                            view.showLoading();//显示进度条
                        }
                    })
                    .subscribeOn(AndroidSchedulers.mainThread())
                    .observeOn(AndroidSchedulers.mainThread())
                    .doAfterTerminate(new Action() {
                        @Override
                        public void run() {
                            view.hideLoading();//隐藏进度条
                        }
                    }).compose(RxUtils.bindToLifecycle(view));
        }
    };
}
 
开发者ID:devzwy,项目名称:NeiHanDuanZiTV,代码行数:23,代码来源:RxUtils.java

示例6: handleResult

import io.reactivex.ObservableTransformer; //导入依赖的package包/类
public static <T> ObservableTransformer<BaseResponse<T>, T> handleResult() {
    try {
        return baseResponseObservable -> baseResponseObservable
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .flatMap(baseResponse -> {
                    if (baseResponse.getErrorCode() == 0) {
                        if (baseResponse.getData() != null) {
                            return Observable.just(baseResponse.getData());
                        } else {
                            //这种情况是没有data的情况下需要走onComplete来进行处理
                            return Observable.empty();
                        }
                    } else {
                        return Observable.error(new DlException(baseResponse.getErrorCode(), baseResponse.getMsg()));
                    }
                });
    } catch (Exception e) {
        e.printStackTrace();
        return baseResponseObservable -> baseResponseObservable
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .flatMap(baseResponse -> Observable.error(new Throwable("服务器错误")));
    }
}
 
开发者ID:chenzj-king,项目名称:RetrofitSample,代码行数:26,代码来源:NetUtil.java

示例7: setUp

import io.reactivex.ObservableTransformer; //导入依赖的package包/类
@Before public void setUp() throws IOException {
  helper = new TestDb(InstrumentationRegistry.getContext(), dbFolder.newFile().getPath());
  real = helper.getWritableDatabase();

  SqlBrite.Logger logger = new SqlBrite.Logger() {
    @Override public void log(String message) {
      logs.add(message);
    }
  };
  ObservableTransformer<Query, Query> queryTransformer =
      new ObservableTransformer<Query, Query>() {
        @Override public ObservableSource<Query> apply(Observable<Query> upstream) {
          return upstream.takeUntil(killSwitch);
        }
      };
  PublishSubject<Set<String>> triggers = PublishSubject.create();
  db = new BriteDatabase(helper, logger, triggers, triggers, scheduler, queryTransformer);
}
 
开发者ID:jiechic,项目名称:sqlbrite-sqlcipher,代码行数:19,代码来源:BriteDatabaseTest.java

示例8: applySchedulers

import io.reactivex.ObservableTransformer; //导入依赖的package包/类
public static <T> ObservableTransformer<T, T> applySchedulers(final IView view) {
    return new ObservableTransformer<T, T>() {
        @Override
        public Observable<T> apply(Observable<T> observable) {
            return observable.subscribeOn(Schedulers.io())
                    .doOnSubscribe(new Consumer<Disposable>() {
                        @Override
                        public void accept(@NonNull Disposable disposable) throws Exception {
                            view.showLoading();//显示进度条
                        }
                    })
                    .subscribeOn(AndroidSchedulers.mainThread())
                    .observeOn(AndroidSchedulers.mainThread())
                    .doFinally(new Action() {
                        @Override
                        public void run() {
                            view.hideLoading();//隐藏进度条
                        }
                    }).compose(RxLifecycleUtils.bindToLifecycle(view));
        }
    };
}
 
开发者ID:Superingxz,项目名称:MoligyMvpArms,代码行数:23,代码来源:RxUtils.java

示例9: forObservable

import io.reactivex.ObservableTransformer; //导入依赖的package包/类
public static <R extends Result> ObservableTransformer<R, R> forObservable() {
    return upstream -> upstream.onErrorResumeNext(throwable -> {
        if(throwable instanceof StatusException) {
            StatusException statusException = (StatusException) throwable;

            if(statusException.getStatus().hasResolution()) {
                return Observable.just((R) statusException.getResult());
            } else {
                return Observable.error(throwable);
            }

        } else {
            return Observable.error(throwable);
        }
    });
}
 
开发者ID:florent37,项目名称:RxGps,代码行数:17,代码来源:StatusExceptionResumeNextTransformer.java

示例10: actionsToResults

import io.reactivex.ObservableTransformer; //导入依赖的package包/类
@Override
protected ObservableTransformer<Action, Result> actionsToResults() {
    return upstream -> Observable.merge(
            upstream.ofType(TimezonesUiActions.RefreshAction.class)
                    .flatMap(refreshAction ->
                            listUseCase.performAction(refreshAction)
                                    .onErrorReturn(t -> Result.error(refreshAction, t))
                                    .startWith(Result.loading(refreshAction))),
            upstream.ofType(TimezonesUiActions.LoadMoreAction.class)
                    .flatMap(loadMoreAction ->
                            listUseCase.performAction(loadMoreAction)
                                    .onErrorReturn(t -> Result.error(loadMoreAction, t))
                                    .startWith(Result.loading(loadMoreAction))),
            upstream.ofType(DeleteTimezoneAction.class)
                    .flatMap(action ->
                            deleteUseCase.performAction(action)
                                    .onErrorReturn(t -> Result.error(action, t))
                                    .startWith(Result.loading(action)))
    );
}
 
开发者ID:sztomek,项目名称:cleanarchitecture-unidirectional,代码行数:21,代码来源:TimezonePresenter.java

示例11: io_main

import io.reactivex.ObservableTransformer; //导入依赖的package包/类
public static <T> ObservableTransformer<T, T> io_main() {
    return new ObservableTransformer<T, T>() {
        @Override
        public ObservableSource<T> apply(@NonNull Observable<T> upstream) {
            return upstream
                    .subscribeOn(Schedulers.io())
                    .unsubscribeOn(Schedulers.io())
                    .doOnSubscribe(new Consumer<Disposable>() {
                        @Override
                        public void accept(@NonNull Disposable disposable) throws Exception {
                            HttpLog.i("+++doOnSubscribe+++" + disposable.isDisposed());
                        }
                    })
                    .doFinally(new Action() {
                        @Override
                        public void run() throws Exception {
                            HttpLog.i("+++doFinally+++");
                        }
                    })
                    .observeOn(AndroidSchedulers.mainThread());
        }
    };
}
 
开发者ID:zhou-you,项目名称:RxEasyHttp,代码行数:24,代码来源:RxUtil.java

示例12: checkAliPayResult

import io.reactivex.ObservableTransformer; //导入依赖的package包/类
public static ObservableTransformer<PayResult, PayResult> checkAliPayResult() {
    return new ObservableTransformer<PayResult, PayResult>() {
        @Override
        public ObservableSource<PayResult> apply(Observable<PayResult> upstream) {
            return upstream.map(new Function<PayResult, PayResult>() {
                @Override
                public PayResult apply(PayResult payResult) throws Exception {
                    if (!payResult.isSucceed()) {
                        throw new PayFailedException(payResult.getErrInfo());
                    }
                    return payResult;
                }
            });
        }
    };
}
 
开发者ID:simplezhli,项目名称:RxPay,代码行数:17,代码来源:RxPayUtils.java

示例13: applySchedulersWithLifeCycle

import io.reactivex.ObservableTransformer; //导入依赖的package包/类
public static <T> ObservableTransformer<T, T> applySchedulersWithLifeCycle(IView view) {
    return new ObservableTransformer<T, T>() {
        @Override
        public Observable<T> apply(Observable<T> observable) {
            return observable.subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .doAfterTerminate(new Action() {
                        @Override
                        public void run() {
                            view.hideLoading();//隐藏进度条
                        }
                    })
                    .compose(RxLifecycleUtils.bindToLifecycle(view));
        }
    };
}
 
开发者ID:Zweihui,项目名称:Aurora,代码行数:17,代码来源:RxUtils.java

示例14: compose

import io.reactivex.ObservableTransformer; //导入依赖的package包/类
public static <T> ObservableTransformer<T, T> compose() {
        return new ObservableTransformer<T, T>() {
            @Override
            public ObservableSource<T> apply(Observable<T> observable) {
                return observable
                        .subscribeOn(Schedulers.io())
                        .doOnSubscribe(new Consumer<Disposable>() {
                            @Override
                            public void accept(Disposable disposable) throws Exception {
//                               if (!NetworkUtils.isConnected()) {
//                                    Toast.makeText(Bing.getApplicationContext(), R.string.toast_network_error, Toast.LENGTH_SHORT).show();
//                                }
                            }
                        })
                        .observeOn(AndroidSchedulers.mainThread());
            }
        };
    }
 
开发者ID:wang2016215,项目名称:Bing,代码行数:19,代码来源:RxSchedulers.java

示例15: handleEvents

import io.reactivex.ObservableTransformer; //导入依赖的package包/类
@Override
protected Observable<Result> handleEvents(Observable<UiEvent> events) {
    ObservableTransformer<LoadConcertEvent, Result> loadConcert = loadEvents ->
            loadEvents.flatMap(event -> {
                return getRepository().getConcert(concertId)
                        .map(LoadConcertResult::success)
                        .onErrorReturn(LoadConcertResult::error)
                        .toObservable()
                        .startWith(LoadConcertResult.IN_PROGRESS);
            });

    return events.publish(sharedEvents -> Observable.merge(
            handleEventsOfClass(sharedEvents, LoadConcertEvent.class, loadConcert),
            sharedEvents.ofType(Result.class)
    ));
}
 
开发者ID:andreybgm,项目名称:gigreminder,代码行数:17,代码来源:ConcertDetailsPresenter.java


注:本文中的io.reactivex.ObservableTransformer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。