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.ItemAllBinding;
import com.prank.master.db.Bean;
import com.prank.master.ui.PlayActivity;
import com.prank.master.utils.ConstValues;

import java.util.List;


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

    private final List<Bean> mValues;

    private Context mCon;

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

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

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

    }

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

    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {

        private ItemAllBinding vb;

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

        }

    }
}