Search in sources :

Example 1 with CommentDataBean

use of com.xinshang.audient.model.entities.CommentDataBean in project Audient by komamj.

the class CommentPresenter method loadComments.

@Override
public void loadComments(Audient audient) {
    String storeId = mRepository.getStoreId();
    Disposable disposable = mRepository.getComments(audient.mediaId, null, storeId, 0, 300).map(new Function<ApiResponse<CommentDataBean>, CommentDataBean>() {

        @Override
        public CommentDataBean apply(ApiResponse<CommentDataBean> commentDataBeanApiResponse) throws Exception {
            return commentDataBeanApiResponse.data;
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).doOnNext(new Consumer<CommentDataBean>() {

        @Override
        public void accept(CommentDataBean commentDataBean) throws Exception {
            if (mView.isActive()) {
                mView.showCommentDataBean(commentDataBean);
                if ((commentDataBean.othersComment.comments.isEmpty())) {
                    mView.showEmpty(true);
                } else {
                    mView.showEmpty(false);
                }
            }
        }
    }).observeOn(Schedulers.io()).map(new Function<CommentDataBean, List<Comment>>() {

        @Override
        public List<Comment> apply(CommentDataBean commentDataBean) throws Exception {
            List<Comment> comments = new ArrayList<>();
            comments.addAll(commentDataBean.inStoreComment.comments);
            comments.addAll(commentDataBean.othersComment.comments);
            return comments;
        }
    }).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSubscriber<List<Comment>>() {

        @Override
        public void onNext(List<Comment> comments) {
            if (mView.isActive()) {
                mView.showComments(comments);
            }
        }

        @Override
        public void onError(Throwable t) {
            LogUtils.e(TAG, "loadComments error :" + t.toString());
            if (mView.isActive()) {
                mView.setLoadingIncator(false);
                mView.showEmpty(true);
                mView.showLoadingError();
            }
        }

        @Override
        public void onComplete() {
            if (mView.isActive()) {
                mView.setLoadingIncator(false);
                mView.showSuccessfulMessage();
            }
        }
    });
    mDisposable.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Comment(com.xinshang.audient.model.entities.Comment) ApiResponse(com.xinshang.audient.model.entities.ApiResponse) Function(io.reactivex.functions.Function) ArrayList(java.util.ArrayList) List(java.util.List) CommentDataBean(com.xinshang.audient.model.entities.CommentDataBean)

Aggregations

ApiResponse (com.xinshang.audient.model.entities.ApiResponse)1 Comment (com.xinshang.audient.model.entities.Comment)1 CommentDataBean (com.xinshang.audient.model.entities.CommentDataBean)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Disposable (io.reactivex.disposables.Disposable)1 Function (io.reactivex.functions.Function)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1