Search in sources :

Example 1 with Comment

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

Example 2 with Comment

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);
    }
}
Also used : Comment(com.xinshang.audient.model.entities.Comment) AudientItemDecoration(com.xinshang.audient.widget.AudientItemDecoration) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Example 3 with Comment

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);
    }
}
Also used : Comment(com.xinshang.audient.model.entities.Comment)

Aggregations

Comment (com.xinshang.audient.model.entities.Comment)3 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 ApiResponse (com.xinshang.audient.model.entities.ApiResponse)1 CommentDataBean (com.xinshang.audient.model.entities.CommentDataBean)1 AudientItemDecoration (com.xinshang.audient.widget.AudientItemDecoration)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