package com.prank.master.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.prank.master.databinding.ItemHomeBinding;
import com.prank.master.db.Category;
import com.prank.master.ui.AllActivity;
import com.prank.master.utils.ConstValues;

import java.util.List;


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

    private final List<Category> mValues;

    private Context mCon;

    public HomeAdapter(Context context, List<Category> items) {
        mValues = items;
        this.mCon = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        return new ViewHolder(ItemHomeBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));

    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        Category category = mValues.get(position);
        String covert = category.getCovert();
        Glide.with(mCon).load(covert).into(holder.vb.image);
        holder.vb.name.setText(category.getName());
        holder.vb.relative.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mCon, AllActivity.class);
                intent.putExtra(ConstValues.KEY_LIST_DATA, category);
                mCon.startActivity(intent);
            }
        });

    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {

        private ItemHomeBinding vb;

        public ViewHolder(ItemHomeBinding binding) {
            super(binding.getRoot());
            vb = binding;

        }

    }
}