CommentAdapter.java 3.42 KB
package com.cnlive.gundam.video.adpter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.cnlive.gundam.R;
import com.cnlive.libs.util.model.CommentItem;

import java.util.ArrayList;
import java.util.List;


/**
 * @author 陈硕
 * @time 2017/6/9  10:56
 * @desc ${TODD}
 */
public class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.CommentHolder> {

    private List<CommentItem> mItems = new ArrayList<CommentItem>();
    private OnImageViewClick onImageViewClick;
    Context context;
    private  LayoutInflater mLayoutInflater;
    private CommentHolder commentHolder;

    public CommentAdapter(Context context) {
        this.context = context;
        mLayoutInflater = LayoutInflater.from(context);

    }

    public void addItems(List<CommentItem> items) {

        mItems.addAll(items);
        notifyDataSetChanged();
    }

    public void addItem(CommentItem item) {

        mItems.add(0,item);

        notifyDataSetChanged();
    }


    public void refreshItems(List<CommentItem> items) {
        mItems.clear();
        mItems.addAll(items);
        notifyDataSetChanged();
    }

    public void clearItems() {
        mItems.clear();
    }


    @Override
    public CommentHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mLayoutInflater.inflate(R.layout.commet_item, parent, false);
        commentHolder = new CommentHolder(view);
        return commentHolder;
    }





    @Override
    public void onBindViewHolder(CommentHolder holder, int position) {


         final CommentItem commentItem = mItems.get(position);


        Glide.with(context).load(commentItem.getFacepath()).into(commentHolder.img_head);
        commentHolder.nick_name.setText(commentItem.getUid());
        commentHolder.comment_message.setText(commentItem.getContent());
        commentHolder.comment_good_count.setText(commentItem.getPraise());
        commentHolder.good_imv1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onImageViewClick != null) {
                    onImageViewClick.praiseComment(commentItem);
                }
            }
        });


    }

    @Override
    public int getItemCount() {
        return mItems.size();
    }

    public void setOnImageViewClick(OnImageViewClick onImageViewClick) {
        this.onImageViewClick = onImageViewClick;
    }


    public interface OnImageViewClick {
        void praiseComment(CommentItem commentItem);
    }

    class CommentHolder extends RecyclerView.ViewHolder {

        public  TextView nick_name;
        public  TextView comment_message;
        public  TextView comment_good_count;
        public  ImageView good_imv1;
        public  ImageView img_head;

        public CommentHolder(View itemView) {
            super(itemView);
            nick_name = (TextView) itemView.findViewById(R.id.nick_name);
            good_imv1 = (ImageView) itemView.findViewById(R.id.good_imv);
            comment_message = (TextView) itemView.findViewById(R.id.comment_message);
            comment_good_count = (TextView) itemView.findViewById(R.id.comment_good_count);
            img_head = (ImageView) itemView.findViewById(R.id.img_head);


        }


    }


}