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.Attention;
import com.example.leudaemialikeme.R;

import java.util.List;

public class AttentionAdapter extends RecyclerView.Adapter<AttentionAdapter.ViewHolder> {
    private List<Attention> attentionList;

    //重写构造方法
    public AttentionAdapter(List<Attention> attentionList) {
        this.attentionList = attentionList;
    }

    public int getItemCount() {
        return attentionList.size();
    }

    //内部类
    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView  attentionTitle,attentionInfo;
        ImageView attentionIconId;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            this.attentionTitle = (TextView) itemView.findViewById(R.id.attentionTitle);
            this.attentionIconId = (ImageView) itemView.findViewById(R.id.attentionIcon);
            this.attentionInfo = (TextView) itemView.findViewById(R.id.attentionInfo);
        }
    }

    //重写 onCreateViewHolder()方法
    @Override
    public AttentionAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.attention_item, parent, false);
        AttentionAdapter.ViewHolder holder = new AttentionAdapter.ViewHolder(view);
        return holder;
    }

    //重写onBindViewHolder()方法
    @Override
    public void onBindViewHolder(@NonNull AttentionAdapter.ViewHolder holder, int position) {
        Attention attention = attentionList.get(position);
        holder.attentionTitle.setText(attention.getAttentionTitle());
        holder.attentionInfo.setText(attention.getAttentionInfo());
        holder.attentionIconId.setImageResource(attention.getAttentionIconId());
    }
}
