本文整理汇总了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());
};
}
示例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;
}
});
}
};
}
示例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());
}
};
}
示例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;
};
}
示例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));
}
};
}
示例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("服务器错误")));
}
}
示例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);
}
示例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));
}
};
}
示例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);
}
});
}
示例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)))
);
}
示例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());
}
};
}
示例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;
}
});
}
};
}
示例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));
}
};
}
示例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());
}
};
}
示例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)
));
}