當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。