package com.example.bpa.view.control;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.example.bpa.R;
import com.example.bpa.view.mode.MenuMode;
import java.util.List;

public class MainMeunAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private final LayoutInflater mLayoutInflater;
    private Context context;
    private List<MenuMode> list;

    public MainMeunAdapter(Context context, List<MenuMode> list) {
        this.context = context;
        this.list = list;
        mLayoutInflater = LayoutInflater.from(context);
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = mLayoutInflater.inflate(R.layout.meunbuttonitem, parent, false);
        return new MyViewHolder(inflate);

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MyViewHolder) {
            MyViewHolder myViewHolder = (MyViewHolder) holder;
            myViewHolder.textView.setText(list.get(position).Name);
            myViewHolder.imageView.setImageResource(list.get(position).Url);
        }
    }

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

    static class MyViewHolder extends RecyclerView.ViewHolder {
        TextView textView;
        ImageView imageView;
        public MyViewHolder(View view) {
            super(view);
            textView = (TextView) view.findViewById(R.id.meun_textview);
            imageView = (ImageView) view.findViewById(R.id.meun_imageview);
        }
    }

}