package com.example.leudaemialikeme.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.leudaemialikeme.Model.Collect;
import com.example.leudaemialikeme.R;

import java.util.List;

public class CollectAdapter extends RecyclerView.Adapter<CollectAdapter.ViewHolder>{
    private List<Collect> collectList;

    //重写构造方法
    public CollectAdapter(List<Collect> collectList){
        this.collectList = collectList;
    }
    public int getItemCount(){
        return collectList.size();
    }
    //内部类
    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView collectTitle,collectName,collectContent,collectRead;
        ImageView collectIcon,collectImg;

        public ViewHolder(@NonNull View itemView){
            super(itemView);
            this.collectTitle = (TextView)itemView.findViewById(R.id.collectTitle);
            this.collectIcon = (ImageView)itemView.findViewById(R.id.collectIcon);
            this.collectName = (TextView)itemView.findViewById(R.id.collectName);
            this.collectContent = (TextView)itemView.findViewById(R.id.collectContent);
            this.collectImg = (ImageView)itemView.findViewById(R.id.collectImg);
            this.collectRead = (TextView)itemView.findViewById(R.id.collectRead);
        }
    }
    //重写 onCreateViewHolder()方法
    @Override
    public CollectAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.collect_item,parent,false);
        CollectAdapter.ViewHolder holder=new CollectAdapter.ViewHolder(view);
        return holder;
    }
    //重写onBindViewHolder()方法
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder,int position){
        Collect collect = collectList.get(position);
        holder.collectTitle.setText(collect.getCollectTitle());
        holder.collectName.setText(collect.getCollectName());
        holder.collectContent.setText(collect.getCollectContent());
        holder.collectRead.setText(collect.getCollectRead());
        holder.collectIcon.setImageResource(collect.getCollectIconId());
        holder.collectImg.setImageResource(collect.getCollectImgId());
    }
}
