package com.example.leudaemialikeme.Adapter;

import android.util.Log;
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.Comment;
import com.example.leudaemialikeme.R;

import java.util.List;

public class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.ViewHolder>{
    List<Comment> mCommentList;
    Comment comment;

    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView comName;
        TextView comContent;
        TextView comTime;
        public ViewHolder(View view){
            super(view);
            comName=(TextView) view.findViewById(R.id.comment_user_name);
            comContent=(TextView)view.findViewById(R.id.comment_content);
            comTime=(TextView)view.findViewById(R.id.comment_time);
        }
    }

    public void setMCommentList(List<Comment> commentList){
        mCommentList=commentList;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.comment_item,parent,false);
        CommentAdapter.ViewHolder holder = new CommentAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull CommentAdapter.ViewHolder holder, int position) {
        comment=mCommentList.get(position);
        holder.comName.setText(comment.getUName());
        holder.comContent.setText(comment.getContent());
        holder.comTime.setText(String.valueOf(comment.getTime()).substring(0,19));
    }

    @Override
    public int getItemCount() {
        return mCommentList.size();
    }
}
