package com.sipai.jspatrol.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.sipai.jspatrol.Bean.Message;
import com.sipai.jspatrol.R;

import java.util.List;

/**
 * Created by lvliming on 2017/10/24.
 */

public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHolder> {
    private List<Message> list;

    public MessageAdapter(List<Message> list) {
        this.list = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_message,parent,false);
        final ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.msg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Message item = list.get(position);
        holder.time.setText(item.getSdt());
        holder.content.setText(item.getContent());
    }

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

    static class ViewHolder extends RecyclerView.ViewHolder{
        View msg;
        TextView time,content;
        public ViewHolder(View itemView) {
            super(itemView);
            msg = itemView;
            time = itemView.findViewById(R.id.moudle_item_message_tv_time);
            content = itemView.findViewById(R.id.moudle_item_message_tv_content);

        }
    }
}
