Search in sources :

Example 1 with MessageException

use of com.dante.exception.MessageException 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 MessageException

use of com.dante.exception.MessageException 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 MessageException

use of com.dante.exception.MessageException 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 4 with MessageException

use of com.dante.exception.MessageException 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

MessageException (com.dante.exception.MessageException)4 RetryWhenProcess (com.dante.rxjava.RetryWhenProcess)4 NonNull (android.support.annotation.NonNull)2 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 Disposable (io.reactivex.disposables.Disposable)2 List (java.util.List)2