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);
}
Aggregations