me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber Java Examples

The following examples show how to use me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VideoDetailPresenter.java    From Aurora with Apache License 2.0 6 votes vote down vote up
public void getSecondRelaRelateVideoInfo(String path, int id, int startnum) {
    mModel.getSecondRelateVideoInfo(path, id, startnum).compose(RxUtils.applySchedulersWithLifeCycle(mRootView))
            .doOnSubscribe(new Consumer<Disposable>() {
                @Override
                public void accept(@NonNull Disposable disposable) throws Exception {
                    if (startnum==0){
                        mRootView.showLoading();
                    }
                }
            })
            .subscribe(new ErrorHandleSubscriber<VideoListInfo>(mErrorHandler) {
                @Override
                public void onNext(VideoListInfo info) {
                    mRootView.setData(info, true);
                }
            });
}
 
Example #2
Source File: PermissionUtil.java    From AndroidBase with Apache License 2.0 6 votes vote down vote up
/**
     * 请求获取手机状态的权限
     */
    public static void readPhonestate(final RequestPermission requestPermission, RxPermissions rxPermissions, IView view, RxErrorHandler errorHandler) {
//先确保是否已经申请过权限
        boolean isPermissionsGranted =
                rxPermissions
                        .isGranted(Manifest.permission.READ_PHONE_STATE);

        if (isPermissionsGranted) {//已经申请过,直接执行操作
            requestPermission.onRequestPermissionSuccess();
        } else {//没有申请过,则申请
            rxPermissions
                    .request(Manifest.permission.READ_PHONE_STATE)
                    .compose(RxUtils.<Boolean>bindToLifecycle(view))
                    .subscribe(new ErrorHandleSubscriber<Boolean>(errorHandler) {
                        @Override
                        public void onNext(Boolean granted) {
                            if (granted) {
                                Timber.tag(TAG).d("request SEND_SMS success");
                                requestPermission.onRequestPermissionSuccess();
                            } else {
                                Timber.tag(TAG).e("request permissons failure");
                            }
                        }
                    });
        }
    }
 
Example #3
Source File: PermissionUtil.java    From AndroidBase with Apache License 2.0 6 votes vote down vote up
/**
     * 请求打电话权限
     */
    public static void callPhone(final RequestPermission requestPermission, RxPermissions rxPermissions, final IView view, RxErrorHandler errorHandler) {
//先确保是否已经申请过权限
        boolean isPermissionsGranted =
                rxPermissions
                        .isGranted(Manifest.permission.CALL_PHONE);

        if (isPermissionsGranted) {//已经申请过,直接执行操作
            requestPermission.onRequestPermissionSuccess();
        } else {//没有申请过,则申请
            rxPermissions
                    .request(Manifest.permission.CALL_PHONE)
                    .compose(RxUtils.<Boolean>bindToLifecycle(view))
                    .subscribe(new ErrorHandleSubscriber<Boolean>(errorHandler) {
                        @Override
                        public void onNext(Boolean granted) {
                            if (granted) {
                                Timber.tag(TAG).d("request SEND_SMS success");
                                requestPermission.onRequestPermissionSuccess();
                            } else {
                                view.showMessage("request permissons failure");
                            }
                        }
                    });
        }
    }
 
Example #4
Source File: PermissionUtil.java    From AndroidBase with Apache License 2.0 6 votes vote down vote up
/**
     * 请求发送短信权限
     */
    public static void sendSms(final RequestPermission requestPermission, RxPermissions rxPermissions, final IView view, RxErrorHandler errorHandler) {
//先确保是否已经申请过权限
        boolean isPermissionsGranted =
                rxPermissions
                        .isGranted(Manifest.permission.SEND_SMS);

        if (isPermissionsGranted) {//已经申请过,直接执行操作
            requestPermission.onRequestPermissionSuccess();
        } else {//没有申请过,则申请
            rxPermissions
                    .request(Manifest.permission.SEND_SMS)
                    .compose(RxUtils.<Boolean>bindToLifecycle(view))
                    .subscribe(new ErrorHandleSubscriber<Boolean>(errorHandler) {
                        @Override
                        public void onNext(Boolean granted) {
                            if (granted) {
                                Timber.tag(TAG).d("request SEND_SMS success");
                                requestPermission.onRequestPermissionSuccess();
                            } else {
                                view.showMessage("request permissons failure");
                            }
                        }
                    });
        }
    }
 
Example #5
Source File: PermissionUtil.java    From AndroidBase with Apache License 2.0 6 votes vote down vote up
/**
 * 请求外部存储的权限
 */
public static void externalStorage(final RequestPermission requestPermission, RxPermissions rxPermissions, final IView view, RxErrorHandler errorHandler) {
    //先确保是否已经申请过摄像头,和写入外部存储的权限
    boolean isPermissionsGranted =
            rxPermissions
                    .isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE);

    if (isPermissionsGranted) {//已经申请过,直接执行操作
        requestPermission.onRequestPermissionSuccess();
    } else {//没有申请过,则申请
        rxPermissions
                .request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .compose(RxUtils.<Boolean>bindToLifecycle(view))
                .subscribe(new ErrorHandleSubscriber<Boolean>(errorHandler) {
                    @Override
                    public void onNext(Boolean granted) {
                        if (granted) {
                            Timber.tag(TAG).d("request WRITE_EXTERNAL_STORAGE and CAMERA success");
                            requestPermission.onRequestPermissionSuccess();
                        } else {
                            view.showMessage("request permissons failure");
                        }
                    }
                });
    }
}
 
Example #6
Source File: VideoDetailPresenter.java    From LQRBiliBlili with MIT License 6 votes vote down vote up
public void loadData(String aid) {
        Observable.zip(mModel.getSummaryData(aid), mModel.getReplyData(aid, page, rows), (summary, reply) -> new VideoDetail(summary, reply))
                .retryWhen(new RetryWithDelay(3, 2))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
                .subscribe(new ErrorHandleSubscriber<VideoDetail>(mErrorHandler) {
                    @Override
                    public void onNext(@NonNull VideoDetail videoDetail) {
                        setVideoDetail(videoDetail);
                    }
                });
//        mModel.getSummaryData(aid)
//                .retryWhen(new RetryWithDelay(3, 2))
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
//                .subscribe(new ErrorHandleSubscriber<Summary>(mErrorHandler) {
//                    @Override
//                    public void onNext(@NonNull Summary summary) {
//                        setVideoDetail(summary);
//                    }
//                });

    }
 
Example #7
Source File: RecommendPresenter.java    From LQRBiliBlili with MIT License 6 votes vote down vote up
public void loadData(int idx, boolean refresh, boolean clearCache) {
    mModel.getRecommendIndexData(idx, refresh, clearCache)
            .retryWhen(new RetryWithDelay(3, 2))
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .doOnSubscribe(disposable -> {
                if (refresh || clearCache) mRootView.showLoading();
            })
            .doFinally(() -> mRootView.hideLoading())
            .observeOn(Schedulers.io())
            .map(indexData -> mModel.parseIndexData(indexData))
            .observeOn(AndroidSchedulers.mainThread())
            .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
            .subscribe(new ErrorHandleSubscriber<List<RecommendMultiItem>>(mErrorHandler) {
                @Override
                public void onNext(@NonNull List<RecommendMultiItem> recommendMultiItems) {
                    if (recommendMultiItems != null) {
                        setAdapter(recommendMultiItems, refresh);
                    }
                }
            });
}
 
Example #8
Source File: HistoryPresenter.java    From Aurora with Apache License 2.0 6 votes vote down vote up
public void deleteFromNet(VideoDaoEntity daoEntity, final int position) {
    mModel.deleteFromNet(daoEntity)
            .compose(RxUtils.applySchedulers(mRootView,false))
            .subscribe(new ErrorHandleSubscriber<Boolean>(mErrorHandler) {
                @Override
                public void onNext(@NonNull Boolean succeed) {
                    mRootView.deleteData(position);
                    onComplete();
                }

                @Override
                public void onComplete() {
                    mRootView.hideLoading();
                }
            });
}
 
Example #9
Source File: HistoryPresenter.java    From Aurora with Apache License 2.0 6 votes vote down vote up
public void getListFromNet(int start, String userId, boolean isLoadMore) {
    mModel.getListFromNet(start, userId)
            .compose(RxUtils.applySchedulers(mRootView,isLoadMore))
            .subscribe(new ErrorHandleSubscriber<List<VideoDaoEntity>>(mErrorHandler) {
                @Override
                public void onNext(@NonNull List<VideoDaoEntity> videos) {
                    mRootView.setData(videos, isLoadMore);
                    onComplete();
                }

                @Override
                public void onComplete() {
                    mRootView.hideLoading();
                }
            });
}
 
Example #10
Source File: HistoryPresenter.java    From Aurora with Apache License 2.0 6 votes vote down vote up
public void deleteFromDb(VideoDaoEntity daoEntity, final int position) {
    mModel.deleteFromDb(daoEntity)
            .delay(600, TimeUnit.MILLISECONDS)
            .compose(RxUtils.applySchedulers(mRootView,false))
            .subscribe(new ErrorHandleSubscriber<Boolean>(mErrorHandler) {
                @Override
                public void onNext(@NonNull Boolean succeed) {
                    mRootView.deleteData(position);
                    onComplete();
                }

                @Override
                public void onComplete() {
                    mRootView.hideLoading();
                }
            });

}
 
Example #11
Source File: HistoryPresenter.java    From Aurora with Apache License 2.0 6 votes vote down vote up
public void getListFromDb(int start, boolean isLoadMore) {
    mModel.getListFromDb(start)
            .delay(600, TimeUnit.MILLISECONDS)
            .compose(RxUtils.applySchedulers(mRootView,isLoadMore))
            .subscribe(new ErrorHandleSubscriber<List<VideoDaoEntity>>(mErrorHandler) {
                @Override
                public void onNext(@NonNull List<VideoDaoEntity> videos) {
                    mRootView.setData(videos, isLoadMore);
                    onComplete();
                }

                @Override
                public void onComplete() {
                    mRootView.hideLoading();
                }
            });

}
 
Example #12
Source File: SearchPresent.java    From Hands-Chopping with Apache License 2.0 6 votes vote down vote up
public void searchFromSteam(String keyword){

        mModel.getSteamSearchGame(keyword)
                .subscribeOn(Schedulers.io())
                .retryWhen(new RetryWithDelay(3,2))
                .doOnSubscribe(disposable -> {mRootView.showLoading();})
                .subscribeOn(AndroidSchedulers.mainThread())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
                .subscribe(new ErrorHandleSubscriber<GameSearchList>(mErrorHandler){
                    @Override
                    public void onNext(GameSearchList gameSearchList) {
                        gsl.setGameSearchBeanArrayList(gameSearchList.getGameSearchBeanArrayList());
                        searchFromSanko(keyword);
                    }
//                        int i=0;
//                        for(GameSearchBean bean:gameSearchList.getGameSearchBeanArrayList()){
//                            i++;
//                            Timber.tag("Steam").w(bean.getId());
//                            Timber.tag("Steam").w(bean.getImgUrl());
//                            Timber.tag("Steam").w(bean.getPrice()+" "+i);
//                            Timber.tag("Steam").w(bean.getTitle());
//                        }
//                    }
                });
    }
 
Example #13
Source File: SalePresenter.java    From Hands-Chopping with Apache License 2.0 6 votes vote down vote up
public void requestSankoSaleGameList(){
        mModel.getSankoSaleGame()
                .subscribeOn(Schedulers.io())
                .retryWhen(new RetryWithDelay(3,2))
                .subscribeOn(AndroidSchedulers.mainThread())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
                .subscribe(new ErrorHandleSubscriber<GameSaleList>(mErrorHandler) {
                    @Override
                    public void onNext(GameSaleList gameSaleList) {
                        gsl.setGameListBeanArrayList(gameSaleList.getGameListBeanArrayList());
                        requestSteamSaleGameList();
//                        int i=0;
//                        for(GameListBean bean:gameSaleList.getGameListBeanArrayList()){
//                            i++;
//                            Timber.tag("Sanko").w(bean.getId());
//                            Timber.tag("Sanko").w(bean.getImgUrl());
//                            Timber.tag("Sanko").w(bean.getOff()+" "+i);
//                            Timber.tag("Sanko").w(bean.getOldPrice()+" "+i);
//                            Timber.tag("Sanko").w(bean.getNowPrice()+" "+i);
//                            Timber.tag("Sanko").w(bean.getTitle());
//                        }
                    }
                });
    }
 
Example #14
Source File: ZhihuHomePresenter.java    From lifecycle-component with Apache License 2.0 6 votes vote down vote up
public void requestDailyList() {
    mModel.getDailyList()
            .subscribeOn(Schedulers.io())
            .retryWhen(new RetryWithDelay(3, 2))//遇到错误时重试,第一个参数为重试几次,第二个参数为重试的间隔
            .doOnSubscribe(disposable -> {
                mRootView.showLoading();//显示下拉刷新的进度条
            }).subscribeOn(AndroidSchedulers.mainThread())
            .observeOn(AndroidSchedulers.mainThread())
            .doFinally(() -> {
                mRootView.hideLoading();//隐藏下拉刷新的进度条
            })
            .compose(RxLifecycleUtils.bindToLifecycle(mRootView))//使用 Rxlifecycle,使 Disposable 和 Activity 一起销毁
            .subscribe(new ErrorHandleSubscriber<DailyListBean>(mErrorHandler) {
                @Override
                public void onNext(DailyListBean dailyListBean) {
                    mDatas.clear();
                    mDatas.addAll(dailyListBean.getStories());
                    mAdapter.notifyDataSetChanged();
                }
            });
}
 
Example #15
Source File: DetailPresenter.java    From lifecycle-component with Apache License 2.0 6 votes vote down vote up
public void requestDetailInfo(int id){
    mModel.getDetailInfo(id)
            .subscribeOn(Schedulers.io())
            .retryWhen(new RetryWithDelay(3, 2))//遇到错误时重试,第一个参数为重试几次,第二个参数为重试的间隔
            .doOnSubscribe(disposable -> {
                mRootView.showLoading();//显示下拉刷新的进度条
            }).subscribeOn(AndroidSchedulers.mainThread())
            .observeOn(AndroidSchedulers.mainThread())
            .doFinally(() -> {
                mRootView.hideLoading();//隐藏下拉刷新的进度条
            })
            .compose(RxLifecycleUtils.bindToLifecycle(mRootView))//使用 Rxlifecycle,使 Disposable 和 Activity 一起销毁
            .subscribe(new ErrorHandleSubscriber<ZhihuDetailBean>(mErrorHandler) {
                @Override
                public void onNext(ZhihuDetailBean zhihuDetailBean) {
                    mRootView.shonContent(zhihuDetailBean);
                }
            });
}
 
Example #16
Source File: DetailPresenter.java    From Hands-Chopping with Apache License 2.0 6 votes vote down vote up
public void requestSteamGameDetail(String id,String name,boolean isBundle){
    mModel.getSteamGameDetail(id,name,isBundle)
            .subscribeOn(Schedulers.io())
            .retryWhen(new RetryWithDelay(3,2))
            .subscribeOn(AndroidSchedulers.mainThread())
            .observeOn(AndroidSchedulers.mainThread())
            .doFinally(()->{
                mRootView.hideLoading();
            })
            .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
            .subscribe(new ErrorHandleSubscriber<GameDetailBean>(mErrorHandler) {
                @Override
                public void onNext(GameDetailBean gameDetailBean) {
                    if(!isBundle){
                        requestSteamGameReview(id, name,gameDetailBean);
                    }else {
                        mRootView.onSteamFinished(gameDetailBean);
                        mRootView.hideLoading();
                    }
                }
            });
}
 
Example #17
Source File: SearchPresenter.java    From Aurora with Apache License 2.0 6 votes vote down vote up
public void getSearchList(String start,String query,boolean isLoadMore) {
    mModel.getSearchList(start,query).compose(RxUtils.applySchedulers(mRootView,isLoadMore))
            .doFinally(new Action() {
                @Override
                public void run() throws Exception {
                    if (!isLoadMore){
                        mRootView.hideLoading();
                    }
                }
            })
            .subscribe(new ErrorHandleSubscriber<VideoListInfo>(mErrorHandler) {

                @Override
                public void onSubscribe(@NonNull Disposable d) {
                    if (!isLoadMore){
                        mRootView.showLoading();
                    }
                }

                @Override
                public void onNext(VideoListInfo info) {
                    mRootView.setListData(filter(info),isLoadMore,info.getTotal());
                }
            });
}
 
Example #18
Source File: DetailPresenter.java    From Hands-Chopping with Apache License 2.0 6 votes vote down vote up
public void requestSteamGameReview(String id,String name,GameDetailBean glb){
    mModel.getSteamGameReview(id, name)
            .subscribeOn(Schedulers.io())
            .retryWhen(new RetryWithDelay(3,2))
            .subscribeOn(AndroidSchedulers.mainThread())
            .observeOn(AndroidSchedulers.mainThread())
            .doFinally(()->{
                mRootView.hideLoading();
            })
            .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
            .subscribe(new ErrorHandleSubscriber<GameDetailBean>(mErrorHandler) {
                @Override
                public void onNext(GameDetailBean gameDetailBean) {
                    glb.setReviews(gameDetailBean.getReviews());
                    glb.setId(id);
                    glb.setTitle(name);
                    mRootView.onSteamFinished(glb);
                }
            });
}
 
Example #19
Source File: VideoDetailPresenter.java    From LQRBiliBlili with MIT License 5 votes vote down vote up
public void loadPlayUrl(String aid) {
    // TODO: 2017/11/1 根据加载情况动态修改提示
    mRootView.setTvVideoStartInfoStr(startInfoStr);
    mModel.getPlayurl(aid)
            .retryWhen(new RetryWithDelay(3, 2))
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
            .subscribe(new ErrorHandleSubscriber<PlayUrl>(mErrorHandler) {
                @Override
                public void onNext(PlayUrl playUrl) {
                    mRootView.playVideo(playUrl);
                }
            });
}
 
Example #20
Source File: AuthorDetailPresenter.java    From Aurora with Apache License 2.0 5 votes vote down vote up
public void getShareInfo(int id) {
    mModel.getShareInfo(id).compose(RxUtils.applySchedulersWithLifeCycle(mRootView))
            .subscribe(new ErrorHandleSubscriber<ShareInfo>(mErrorHandler) {
                @Override
                public void onNext(ShareInfo info) {
                    mRootView.setShareInfo(info);
                }
            });
}
 
Example #21
Source File: AuthorDetailPresenter.java    From Aurora with Apache License 2.0 5 votes vote down vote up
public void getAuthorIndexInfo(int id) {
    mModel.getAuthorIndexInfo(id).compose(RxUtils.applySchedulersWithLifeCycle(mRootView))
            .subscribe(new ErrorHandleSubscriber<AuthorIndexInfo>(mErrorHandler) {
                @Override
                public void onNext(AuthorIndexInfo info) {
                    mRootView.setIndexInfo(info);
                }
            });
}
 
Example #22
Source File: AuthorDetailPresenter.java    From Aurora with Apache License 2.0 5 votes vote down vote up
public void getAuthorDynamicList(int id, int startCount, boolean isLoadMore) {
    mModel.getAuthorDynamicList(id,startCount).compose(RxUtils.applySchedulers(mRootView,isLoadMore))
            .subscribe(new ErrorHandleSubscriber<AuthorDynamicInfo>(mErrorHandler) {
                @Override
                public void onNext(AuthorDynamicInfo info) {
                    mRootView.setAuthorDynamicInfo(info.getItemList(),isLoadMore);
                }
            });
}
 
Example #23
Source File: AuthorDetailPresenter.java    From Aurora with Apache License 2.0 5 votes vote down vote up
public void getAuthorAlbumList(int id, int startCount, boolean isLoadMore) {
    mModel.getAuthorAlbumList(id,startCount).compose(RxUtils.applySchedulers(mRootView,isLoadMore))
            .subscribe(new ErrorHandleSubscriber<AuthorAlbumInfo>(mErrorHandler) {
                @Override
                public void onNext(AuthorAlbumInfo info) {
                    mRootView.setAuthorAlbumInfo(info.getItemList(),isLoadMore);
                }
            });
}
 
Example #24
Source File: LivePresenter.java    From LQRBiliBlili with MIT License 5 votes vote down vote up
public void loadData(boolean refresh) {
    mModel.getLiveList(refresh)
            .retryWhen(new RetryWithDelay(3, 2))
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .doOnSubscribe(disposable -> {
                mRootView.showLoading();
            })
            .doFinally(() -> {
                mRootView.hideLoading();
            })
            .observeOn(Schedulers.io())
            .map(getAllListDataResult -> {
                GetAllListData.DataBean getAllListData = getAllListDataResult.getData();
                List<LiveMultiItem> data = new ArrayList<>();
                if (getAllListData != null) {
                    // 轮播
                    mBanner = getAllListData.getBanner();
                    // 推荐
                    data.addAll(mModel.parseRecommendData(getAllListData));
                    // 分类数据
                    data.addAll(mModel.parsePartitions(getAllListData));
                }
                return data;
            })
            .observeOn(AndroidSchedulers.mainThread())
            .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
            .subscribe(new ErrorHandleSubscriber<List<LiveMultiItem>>(mErrorHandler) {
                @Override
                public void onNext(@NonNull List<LiveMultiItem> liveMultiItems) {
                    setBanner();
                    if (liveMultiItems != null)
                        setAdapter(liveMultiItems);
                }
            });
}
 
Example #25
Source File: SalePresenter.java    From Hands-Chopping with Apache License 2.0 5 votes vote down vote up
public void requestSteamSaleGameList(){
        mModel.getSteamSaleGame()
                .subscribeOn(Schedulers.io())
                .retryWhen(new RetryWithDelay(3,2))
                .subscribeOn(AndroidSchedulers.mainThread())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
                .subscribe(new ErrorHandleSubscriber<GameSaleList>(mErrorHandler) {
                    @Override
                    public void onNext(GameSaleList gameSaleList) {
                        gsl.getGameListBeanArrayList().addAll(gameSaleList.getGameListBeanArrayList());
                        mDatas.clear();
                        mDatas.addAll(gsl.getGameListBeanArrayList());
                        mAdapter.notifyDataSetChanged();
                        mRootView.imgLoad();
//                        int i=0;
//                        for(GameListBean bean:gameSaleList.getGameListBeanArrayList()){
//                            i++;
//                            Timber.tag("Steam").w(bean.getId());
//                            Timber.tag("Steam").w(bean.getImgUrl());
//                            Timber.tag("Steam").w(bean.getOff()+" "+i);
//                            Timber.tag("Steam").w(bean.getOldPrice()+" "+i);
//                            Timber.tag("Steam").w(bean.getNowPrice()+" "+i);
//                            Timber.tag("Steam").w(bean.getTitle());
//                        }
                    }
                });
    }
 
Example #26
Source File: AuthorDetailPresenter.java    From Aurora with Apache License 2.0 5 votes vote down vote up
public void getAuthorVideoList(int id,int start ,boolean isLoadMore) {
    mModel.getAuthorVideoList(id,start).compose(RxUtils.applySchedulers(mRootView,isLoadMore))
            .subscribe(new ErrorHandleSubscriber<VideoListInfo>(mErrorHandler) {
                @Override
                public void onNext(VideoListInfo info) {
                    mRootView.setVideosData(info.getItemList(),isLoadMore);
                }
            });
}
 
Example #27
Source File: PermissionUtil.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
/**
 * 请求摄像头权限
 */
public static void launchCamera(final RequestPermission requestPermission, RxPermissions rxPermissions, final IView view, RxErrorHandler errorHandler) {
    //先确保是否已经申请过摄像头,和写入外部存储的权限
    boolean isPermissionsGranted =
            rxPermissions
                    .isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE) &&
                    rxPermissions
                            .isGranted(Manifest.permission.CAMERA);

    if (isPermissionsGranted) {//已经申请过,直接执行操作
        requestPermission.onRequestPermissionSuccess();
    } else {//没有申请过,则申请
        rxPermissions
                .request(Manifest.permission.WRITE_EXTERNAL_STORAGE
                        , Manifest.permission.CAMERA)
                .compose(RxUtils.<Boolean>bindToLifecycle(view))
                .subscribe(new ErrorHandleSubscriber<Boolean>(errorHandler) {
                    @Override
                    public void onNext(Boolean granted) {
                        if (granted) {
                            Timber.tag(TAG).d("request WRITE_EXTERNAL_STORAGE and CAMERA success");
                            requestPermission.onRequestPermissionSuccess();
                        } else {
                            view.showMessage("request permissons failure");
                        }
                    }
                });
    }
}
 
Example #28
Source File: GankHomePresenter.java    From lifecycle-component with Apache License 2.0 5 votes vote down vote up
public void requestGirls(final boolean pullToRefresh) {
    if (pullToRefresh) lastPage = 1;//下拉刷新默认只请求第一页

    mModel.getGirlList(NUMBER_OF_PAGE, lastPage)
            .subscribeOn(Schedulers.io())
            .retryWhen(new RetryWithDelay(3, 2))//遇到错误时重试,第一个参数为重试几次,第二个参数为重试的间隔
            .doOnSubscribe(disposable -> {
                if (pullToRefresh)
                    mRootView.showLoading();//显示下拉刷新的进度条
                else
                    mRootView.startLoadMore();//显示上拉加载更多的进度条
            }).subscribeOn(AndroidSchedulers.mainThread())
            .observeOn(AndroidSchedulers.mainThread())
            .doFinally(() -> {
                if (pullToRefresh)
                    mRootView.hideLoading();//隐藏下拉刷新的进度条
                else
                    mRootView.endLoadMore();//隐藏上拉加载更多的进度条
            })
            .compose(RxLifecycleUtils.bindToLifecycle(mRootView))//使用 Rxlifecycle,使 Disposable 和 Activity 一起销毁
            .subscribe(new ErrorHandleSubscriber<GankBaseResponse<List<GankItemBean>>>(mErrorHandler) {
                @Override
                public void onNext(GankBaseResponse<List<GankItemBean>> datas) {
                    lastPage = lastPage + 1;
                    if (pullToRefresh) mDatas.clear();//如果是下拉刷新则清空列表
                    preEndIndex = mDatas.size();//更新之前列表总长度,用于确定加载更多的起始位置
                    mDatas.addAll(datas.getResults());
                    if (pullToRefresh)
                        mAdapter.notifyDataSetChanged();
                    else
                        mAdapter.notifyItemRangeInserted(preEndIndex, datas.getResults().size());
                }
            });
}
 
Example #29
Source File: AuthorDetailPresenter.java    From Aurora with Apache License 2.0 5 votes vote down vote up
public void getAuthorTabs(int id) {
    mModel.getAuthorTabs(id).compose(RxUtils.applySchedulersWithLifeCycle(mRootView))
            .subscribe(new ErrorHandleSubscriber<AuthorTabsInfo>(mErrorHandler) {
                @Override
                public void onNext(AuthorTabsInfo info) {
                    mRootView.setTabs(info);
                }
            });
}
 
Example #30
Source File: VideoDetailPresenter.java    From Aurora with Apache License 2.0 5 votes vote down vote up
public void getVideoData(int videoId) {
    mModel.getVideoData(videoId).compose(RxUtils.applySchedulersWithLifeCycle(mRootView))
            .subscribe(new ErrorHandleSubscriber<VideoListInfo.Video.VideoData>(mErrorHandler) {
                @Override
                public void onNext(VideoListInfo.Video.VideoData data) {
                    mRootView.setVideoData(data);
                }
            });
}