Search in sources :

Example 6 with RetryWhenProcess

use of com.dante.rxjava.RetryWhenProcess in project 91Pop by DanteAndroid.

the class PlayVideoPresenter method loadVideoUrl.

@Override
public void loadVideoUrl(final UnLimit91PornItem unLimit91PornItem) {
    String viewKey = unLimit91PornItem.getViewKey();
    dataManager.loadPorn91VideoUrl(viewKey).map(new Function<VideoResult, VideoResult>() {

        @Override
        public VideoResult apply(VideoResult videoResult) throws VideoException {
            if (TextUtils.isEmpty(videoResult.getVideoUrl())) {
                if (VideoResult.OUT_OF_WATCH_TIMES.equals(videoResult.getId())) {
                    // 尝试强行重置,并上报异常
                    cookieManager.resetPorn91VideoWatchTiem(true);
                    Bugsnag.notify(new Throwable(TAG + ":ten videos each day "), Severity.WARNING);
                    throw new VideoException("观看次数达到上限了!");
                } else {
                    throw new VideoException("解析视频链接失败了");
                }
            }
            return videoResult;
        }
    }).retryWhen(new RetryWhenProcess(RetryWhenProcess.PROCESS_TIME)).compose(RxSchedulersHelper.<VideoResult>ioMainThread()).compose(provider.<VideoResult>bindUntilEvent(Lifecycle.Event.ON_DESTROY)).subscribe(new CallBackWrapper<VideoResult>() {

        @Override
        public void onBegin(Disposable d) {
            ifViewAttached(new ViewAction<PlayVideoView>() {

                @Override
                public void run(@NonNull PlayVideoView view) {
                    view.showParsingDialog();
                }
            });
        }

        @Override
        public void onSuccess(final VideoResult videoResult) {
            cookieManager.resetPorn91VideoWatchTiem(false);
            ifViewAttached(new ViewAction<PlayVideoView>() {

                @Override
                public void run(@NonNull PlayVideoView view) {
                    view.playVideo(saveVideoUrl(videoResult, unLimit91PornItem));
                }
            });
        }

        @Override
        public void onError(final String msg, int code) {
            ifViewAttached(new ViewAction<PlayVideoView>() {

                @Override
                public void run(@NonNull PlayVideoView view) {
                    view.errorParseVideoUrl(msg);
                }
            });
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) RetryWhenProcess(com.dante.rxjava.RetryWhenProcess) VideoException(com.dante.exception.VideoException) VideoResult(com.dante.data.model.VideoResult) NonNull(android.support.annotation.NonNull)

Aggregations

RetryWhenProcess (com.dante.rxjava.RetryWhenProcess)6 NonNull (android.support.annotation.NonNull)4 MessageException (com.dante.exception.MessageException)4 Disposable (io.reactivex.disposables.Disposable)4 List (java.util.List)3 BaseResult (com.dante.data.model.BaseResult)2 UnLimit91PornItem (com.dante.data.model.UnLimit91PornItem)2 User (com.dante.data.model.User)2 FavoriteException (com.dante.exception.FavoriteException)2 VideoComment (com.dante.data.model.VideoComment)1 VideoResult (com.dante.data.model.VideoResult)1 VideoException (com.dante.exception.VideoException)1 Function (io.reactivex.functions.Function)1 ArrayList (java.util.ArrayList)1