Search in sources :

Example 1 with RetryWhenProcess

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

the class SearchPresenter method searchVideos.

@Override
public void searchVideos(String searchId, String sort, final boolean pullToRefresh) {
    String viewType = "basic";
    String searchType = "search_videos";
    if (pullToRefresh) {
        page = 1;
    }
    dataManager.searchPorn91Videos(viewType, page, searchType, searchId, sort).map(new Function<BaseResult<List<UnLimit91PornItem>>, List<UnLimit91PornItem>>() {

        @Override
        public List<UnLimit91PornItem> apply(BaseResult<List<UnLimit91PornItem>> baseResult) throws Exception {
            if (baseResult.getCode() == BaseResult.ERROR_CODE) {
                throw new MessageException(baseResult.getMessage());
            }
            if (page == 1) {
                totalPage = baseResult.getTotalPage();
            }
            return baseResult.getData();
        }
    }).retryWhen(new RetryWhenProcess(2)).compose(RxSchedulersHelper.<List<UnLimit91PornItem>>ioMainThread()).compose(provider.<List<UnLimit91PornItem>>bindUntilEvent(Lifecycle.Event.ON_DESTROY)).subscribe(new CallBackWrapper<List<UnLimit91PornItem>>() {

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

                @Override
                public void run(@NonNull SearchView view) {
                    if (page == 1 && pullToRefresh) {
                        view.showLoading(pullToRefresh);
                    }
                }
            });
        }

        @Override
        public void onSuccess(final List<UnLimit91PornItem> unLimit91PornItems) {
            ifViewAttached(new ViewAction<SearchView>() {

                @Override
                public void run(@NonNull SearchView view) {
                    if (page == 1) {
                        view.setData(unLimit91PornItems);
                        view.showContent();
                    } else {
                        view.loadMoreDataComplete();
                        view.setMoreData(unLimit91PornItems);
                    }
                    // 已经最后一页了
                    if (page == totalPage) {
                        view.noMoreData();
                    } else {
                        page++;
                    }
                    view.showContent();
                }
            });
        }

        @Override
        public void onError(final String msg, int code) {
            // 首次加载失败,显示重试页
            ifViewAttached(new ViewAction<SearchView>() {

                @Override
                public void run(@NonNull SearchView view) {
                    if (page == 1) {
                        view.showError(msg);
                    } else {
                        view.loadMoreFailed();
                    }
                }
            });
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) BaseResult(com.dante.data.model.BaseResult) RetryWhenProcess(com.dante.rxjava.RetryWhenProcess) MessageException(com.dante.exception.MessageException) MessageException(com.dante.exception.MessageException) NonNull(android.support.annotation.NonNull) List(java.util.List) UnLimit91PornItem(com.dante.data.model.UnLimit91PornItem)

Example 2 with RetryWhenProcess

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

the class AppApiHelper method userRegisterPorn91Video.

@Override
public Observable<User> userRegisterPorn91Video(String username, String password1, String password2, String email, String captchaInput) {
    String next = "";
    // String fingerprint = "2192328486";
    String fingerprint = UserHelper.randomFingerprint();
    String vip = "";
    String actionSignUp = "Sign Up";
    String submitX = "45";
    String submitY = "13";
    String ipAddress = addressHelper.getRandomIPAddress();
    return noLimit91PornServiceApi.register(next, username, password1, password2, email, captchaInput, fingerprint, vip, actionSignUp, submitX, submitY, HeaderUtils.getUserHeader(addressHelper, "signup"), ipAddress).retryWhen(new RetryWhenProcess(2)).map(new Function<String, User>() {

        @Override
        public User apply(String s) throws Exception {
            if (!UserHelper.isPornVideoLoginSuccess(s)) {
                String errorInfo = Parse91PronVideo.parseErrorInfo(s);
                throw new MessageException(errorInfo);
            }
            return Parse91PronVideo.parseUserInfo(s);
        }
    });
}
Also used : RetryWhenProcess(com.dante.rxjava.RetryWhenProcess) User(com.dante.data.model.User) MessageException(com.dante.exception.MessageException) FavoriteException(com.dante.exception.FavoriteException) MessageException(com.dante.exception.MessageException)

Example 3 with RetryWhenProcess

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

the class PlayVideoPresenter method loadVideoComment.

@Override
public void loadVideoComment(String videoId, String viewKey, final boolean pullToRefresh) {
    if (pullToRefresh) {
        start = 1;
    }
    dataManager.loadPorn91VideoComments(videoId, start, viewKey).retryWhen(new RetryWhenProcess(RetryWhenProcess.PROCESS_TIME)).compose(RxSchedulersHelper.<List<VideoComment>>ioMainThread()).compose(provider.<List<VideoComment>>bindUntilEvent(Lifecycle.Event.ON_STOP)).map(new Function<List<VideoComment>, List<VideoComment>>() {

        @Override
        public List<VideoComment> apply(List<VideoComment> videoComments) throws Exception {
            List<VideoComment> newList = new ArrayList<>();
            for (VideoComment c : videoComments) {
                List<String> list = c.getCommentQuoteList();
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < list.size(); i++) {
                    builder.append(list.get(i));
                }
                if (invalidComment(builder.toString())) {
                    Logger.d("invalidComment " + builder.toString());
                } else {
                    newList.add(c);
                }
            }
            return newList;
        }
    }).subscribe(new CallBackWrapper<List<VideoComment>>() {

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

                @Override
                public void run(@NonNull PlayVideoView view) {
                    if (start == 1 && pullToRefresh) {
                        view.showLoading(pullToRefresh);
                    }
                }
            });
        }

        @Override
        public void onSuccess(final List<VideoComment> videoCommentList) {
            ifViewAttached(new ViewAction<PlayVideoView>() {

                @Override
                public void run(@NonNull PlayVideoView view) {
                    if (start == 1) {
                        view.setVideoCommentData(videoCommentList, pullToRefresh);
                    } else {
                        view.setMoreVideoCommentData(videoCommentList);
                    }
                    if (videoCommentList.size() == 0 && start == 1) {
                        view.noMoreVideoCommentData("暂无评论");
                    } else if (videoCommentList.size() == 0 && start > 1) {
                        view.noMoreVideoCommentData("没有更多评论了");
                    }
                    start++;
                    view.showContent();
                }
            });
        }

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

                @Override
                public void run(@NonNull PlayVideoView view) {
                    if (start == 1) {
                        view.loadVideoCommentError(msg);
                    } else {
                        view.loadMoreVideoCommentError(msg);
                    }
                }
            });
        }

        @Override
        public void onCancel(boolean isCancel) {
            ifViewAttached(new ViewAction<PlayVideoView>() {

                @Override
                public void run(@NonNull PlayVideoView view) {
                    Logger.t(TAG).d("------getVideoComments  onCancel----------------------------");
                    if (start == 1) {
                        view.loadVideoCommentError("取消请求");
                    } else {
                        view.loadMoreVideoCommentError("取消请求");
                    }
                }
            });
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) RetryWhenProcess(com.dante.rxjava.RetryWhenProcess) ArrayList(java.util.ArrayList) VideoComment(com.dante.data.model.VideoComment) Function(io.reactivex.functions.Function) NonNull(android.support.annotation.NonNull) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with RetryWhenProcess

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

the class AuthorPresenter method authorVideos.

@Override
public void authorVideos(String uid, final boolean pullToRefresh) {
    String type = "public";
    if (pullToRefresh) {
        page = 1;
        cleanCache = true;
    }
    dataManager.loadPorn91authorVideos(uid, type, page, cleanCache).map(new Function<BaseResult<List<UnLimit91PornItem>>, List<UnLimit91PornItem>>() {

        @Override
        public List<UnLimit91PornItem> apply(BaseResult<List<UnLimit91PornItem>> baseResult) throws Exception {
            if (baseResult.getCode() == BaseResult.ERROR_CODE) {
                throw new MessageException(baseResult.getMessage());
            }
            if (page == 1) {
                totalPage = baseResult.getTotalPage();
            }
            return baseResult.getData();
        }
    }).retryWhen(new RetryWhenProcess(RetryWhenProcess.PROCESS_TIME)).compose(RxSchedulersHelper.<List<UnLimit91PornItem>>ioMainThread()).compose(provider.<List<UnLimit91PornItem>>bindUntilEvent(Lifecycle.Event.ON_DESTROY)).subscribe(new CallBackWrapper<List<UnLimit91PornItem>>() {

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

                @Override
                public void run(@NonNull AuthorView view) {
                    if (page == 1 && !pullToRefresh) {
                        view.showLoading(pullToRefresh);
                    }
                }
            });
        }

        @Override
        public void onSuccess(final List<UnLimit91PornItem> unLimit91PornItems) {
            ifViewAttached(new ViewAction<AuthorView>() {

                @Override
                public void run(@NonNull AuthorView view) {
                    if (page == 1) {
                        view.setData(unLimit91PornItems);
                        view.showContent();
                    } else {
                        view.loadMoreDataComplete();
                        view.setMoreData(unLimit91PornItems);
                    }
                    if (page >= totalPage) {
                        view.noMoreData();
                    } else {
                        page++;
                    }
                    view.showContent();
                }
            });
        }

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

                @Override
                public void run(@NonNull AuthorView view) {
                    if (page == 1) {
                        view.showError(msg);
                    } else {
                        view.loadMoreFailed();
                    }
                }
            });
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) BaseResult(com.dante.data.model.BaseResult) RetryWhenProcess(com.dante.rxjava.RetryWhenProcess) MessageException(com.dante.exception.MessageException) MessageException(com.dante.exception.MessageException) NonNull(android.support.annotation.NonNull) List(java.util.List) UnLimit91PornItem(com.dante.data.model.UnLimit91PornItem)

Example 5 with RetryWhenProcess

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

the class AppApiHelper method userLoginPorn91Video.

@Override
public Observable<User> userLoginPorn91Video(String username, String password, String captcha) {
    String fingerprint = UserHelper.randomFingerprint();
    String fingerprint2 = UserHelper.randomFingerprint2();
    String actionLogin = "Log In";
    String x = "47";
    String y = "12";
    return noLimit91PornServiceApi.login(username, password, fingerprint, fingerprint2, captcha, actionLogin, x, y, HeaderUtils.getUserHeader(addressHelper, "login")).retryWhen(new RetryWhenProcess(2)).map(new Function<String, User>() {

        @Override
        public User apply(String s) throws Exception {
            if (!UserHelper.isPornVideoLoginSuccess(s)) {
                String errorInfo = Parse91PronVideo.parseErrorInfo(s);
                if (TextUtils.isEmpty(errorInfo)) {
                    errorInfo = "未知错误,请确认地址是否正确";
                }
                throw new MessageException(errorInfo);
            }
            return Parse91PronVideo.parseUserInfo(s);
        }
    });
}
Also used : RetryWhenProcess(com.dante.rxjava.RetryWhenProcess) User(com.dante.data.model.User) MessageException(com.dante.exception.MessageException) FavoriteException(com.dante.exception.FavoriteException) MessageException(com.dante.exception.MessageException)

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