package com.example.leudaemialikeme.Adapter;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.leudaemialikeme.Activity.DetailActivity;
import com.example.leudaemialikeme.R;
import com.example.leudaemialikeme.Model.Recnews;

import java.util.List;

public class InfoAdapter extends RecyclerView.Adapter<InfoAdapter.ViewHolder> {
    private List<Recnews> mRecnewsList;

    static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView image;
        TextView theme;
        TextView intro;
        TextView visNum;
        TextView time;
        LinearLayout linear;
        public ViewHolder(View view){
            super(view);
            image=(ImageView)view.findViewById(R.id.recNews_image);
            theme=(TextView)view.findViewById(R.id.recNews_theme);
            intro=(TextView)view.findViewById(R.id.recNews_intro);
            visNum=(TextView)view.findViewById(R.id.recNews_visNum);
            time=(TextView)view.findViewById(R.id.recNews_time);
            linear=(LinearLayout)view.findViewById(R.id.info);
        }

    }

    public InfoAdapter(List<Recnews> recnewsList){
        mRecnewsList=recnewsList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.info_item,parent,false);
        ViewHolder holder=new ViewHolder(view);
        holder.linear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(view.getContext(), DetailActivity.class);
                //intent.putExtra("from",String.valueOf(view.getContext()));
                //Log.e("activity",String.valueOf(view.getContext()));
                view.getContext().startActivity(intent);
            }
        });
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull InfoAdapter.ViewHolder holder, int position) {
        Recnews recnews=mRecnewsList.get(position);
        holder.image.setImageResource(recnews.getImageNum());
        holder.visNum.setText(String.valueOf(recnews.getVisNum()));
        holder.intro.setText(recnews.getIntro());
        holder.theme.setText(recnews.getTheme());
        holder.time.setText(recnews.getTime());

    }

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