use of com.xinshang.audient.model.entities.Comment 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);
}
use of com.xinshang.audient.model.entities.Comment in project Audient by komamj.
the class CommentFragment method onViewCreated.
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
LogUtils.i(TAG, "onViewCreated");
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
if (mPresenter != null) {
mPresenter.loadComments(mAudient);
}
}
});
mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent, R.color.colorPrimaryDark, R.color.colorPrimary);
setLoadingIncator(true);
mAdapter = new CommentAdapter(mContext);
mAdapter.setListener(new CommentAdapter.EventListener() {
@Override
public void onThumbUpClick(Comment comment) {
if (mPresenter != null) {
mPresenter.thumbUpComment(comment);
}
}
});
mRecyclerView.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.addItemDecoration(new AudientItemDecoration(mContext));
mRecyclerView.setAdapter(mAdapter);
// load data
if (mPresenter != null) {
mPresenter.loadComments(mAudient);
}
}
use of com.xinshang.audient.model.entities.Comment in project Audient by komamj.
the class CommentAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(CommentViewHolder holder, int position) {
Comment comment = mData.get(position);
if (getItemViewType(position) == VIEW_TYPE_HEADER) {
if (position == 0) {
((CommentHeaderViewHolder) holder).mTitle.setText(mContext.getString(R.string.store_comment_description));
} else {
((CommentHeaderViewHolder) holder).mTitle.setText(mContext.getString(R.string.all_comment_description));
}
}
mGlideRequest.load(comment.avatar).into(holder.mUserImage);
holder.mMessage.setText(comment.comment);
String userName = comment.userNickname;
if (TextUtils.isEmpty(userName)) {
userName = comment.userName;
}
holder.mUserName.setText(userName);
holder.mStoreName.setText(comment.storeName);
holder.mTime.setText(comment.commentDate);
holder.mCount.setText(String.valueOf(comment.voteCount));
if (comment.voted) {
holder.mThumbUp.setImageResource(R.drawable.ic_thumb_uped);
} else {
holder.mThumbUp.setImageResource(R.drawable.ic_thumb_up_inactive);
}
}
Aggregations