package com.app.sounds.prank.party.list;

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

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.app.sounds.prank.party.act.InfoActivity;
import com.app.sounds.prank.party.bean.MyBean;
import com.app.sounds.prank.party.common.Utils;
import com.app.sounds.prank.party.databinding.HomeItemBinding;
import com.bumptech.glide.Glide;

import java.util.List;


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

    private final List<MyBean> mValues;

    private Context mCon;


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

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

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

    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        int i = position % 6;
        holder.vb.relative.setBackground(ContextCompat.getDrawable(mCon, Utils.bgs[i]));
        MyBean myBean = mValues.get(position);
        String covert = myBean.getCovert();
        Glide.with(mCon).load(covert).into(holder.vb.image);
        holder.vb.name.setText(myBean.getName());
        holder.vb.relative.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mCon, InfoActivity.class);
                intent.putExtra(Utils.KEY_LIST_DATA, myBean);
                intent.putExtra(Utils.KEY_LIST_COLOR_POS, i);
                mCon.startActivity(intent);
            }
        });
        if(position == mValues.size()-1||position == mValues.size()-2){
            holder.vb.view.setVisibility(View.VISIBLE);
        }else {
            holder.vb.view.setVisibility(View.GONE);
        }

    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {

        private HomeItemBinding vb;

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

        }
    }
}