package com.example.leudaemialikeme.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
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 java.util.List;

public class HistoryNewsAdapter extends RecyclerView.Adapter<HistoryNewsAdapter.ViewHolder>{
    private List<News> historyNewsList;

    //重写构造方法
    public HistoryNewsAdapter(List<News> historyNewsList){
        this.historyNewsList = historyNewsList;
    }
    public int getItemCount(){
        return historyNewsList.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 HistoryNewsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.collect_news_item,parent,false);
        HistoryNewsAdapter.ViewHolder holder=new HistoryNewsAdapter.ViewHolder(view);
        return holder;
    }
    //重写onBindViewHolder()方法
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder,int position){
        News news = historyNewsList.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()));

    }
}

