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.News;
import com.example.leudaemialikeme.R;
import com.example.leudaemialikeme.Utils.TimeUtil;

import org.w3c.dom.Text;

import java.util.List;

public class CollectNewsAdapter extends RecyclerView.Adapter<CollectNewsAdapter.ViewHolder>{
    private List<News> collectNewsList;

    //重写构造方法
    public CollectNewsAdapter(List<News> collectNewsList){
        this.collectNewsList = collectNewsList;
    }
    public int getItemCount(){
        return collectNewsList.size();
    }
    //内部类
    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView news_title,news_info,news_read,news_time;

        public ViewHolder(@NonNull View itemView){
            super(itemView);
           this.news_title = (TextView)itemView.findViewById(R.id.News_title);
           this.news_info = (TextView)itemView.findViewById(R.id.News_info);
           this.news_read = (TextView)itemView.findViewById(R.id.News_read);
           this.news_time = (TextView)itemView.findViewById(R.id.News_time);
        }
    }
    //重写 onCreateViewHolder()方法
    @Override
    public CollectNewsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.collect_news_item,parent,false);
        CollectNewsAdapter.ViewHolder holder=new CollectNewsAdapter.ViewHolder(view);
        return holder;
    }
    //重写onBindViewHolder()方法
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder,int position){
        News news = collectNewsList.get(position);
        holder.news_title.setText(news.getStittle());
        holder.news_info.setText(news.getScontent());
        holder.news_read.setText(String.valueOf(news.getSbrowseNum()));
        holder.news_time.setText(TimeUtil.timeToString(news.getStime()));

    }
}
