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

import java.util.List;

public class HistoryBlogAdapter extends RecyclerView.Adapter<HistoryBlogAdapter.ViewHolder>{
    private List<Blog> historyBlogList;

    //重写构造方法
    public HistoryBlogAdapter(List<Blog> historyBlogList){
        this.historyBlogList = historyBlogList;
    }
    public int getItemCount(){
        return historyBlogList.size();
    }
    //内部类
    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView blog_title,blog_info,blog_read,blog_time;
        public ViewHolder(@NonNull View itemView){
            super(itemView);
            this.blog_title = itemView.findViewById(R.id.blog_title);
            this.blog_info = itemView.findViewById(R.id.blog_info);
            this.blog_read = itemView.findViewById(R.id.blog_read);
            this.blog_time = itemView.findViewById(R.id.blog_time);
        }
    }
    //重写 onCreateViewHolder()方法
    @Override
    public HistoryBlogAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.collect_blog_item,parent,false);
        HistoryBlogAdapter.ViewHolder holder=new HistoryBlogAdapter.ViewHolder(view);
        return holder;
    }
    //重写onBindViewHolder()方法
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder,int position){
        Blog blog = historyBlogList.get(position);
        holder.blog_title.setText(blog.getBtittle());
        holder.blog_info.setText(blog.getBcontent());
        holder.blog_read.setText(String.valueOf(blog.getBbrowse()));
        holder.blog_time.setText(TimeUtil.timeToString(blog.getBtime()));
    }
}


