package com.prankster.fx.ui.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.prankster.fx.R;
import com.prankster.fx.databinding.ItemLikeBinding;
import com.prankster.fx.db.Bean;
import com.prankster.fx.ui.activity.FXPlayAct;
import com.prankster.fx.utils.ConstValues;

import java.util.List;


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

    private List<Bean> mValues;
    private Context mCOn;

    public likeAdapter(Context context, List<Bean> items) {
        mValues = items;
        mCOn = context;
    }

    public void updateData(List<Bean> items){
        mValues = items;
        notifyDataSetChanged();
    }

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

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

    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        Bean bean = mValues.get(position);
        holder.vb.ttvName.setText(bean.getName());

        if(bean.isCustomization()){
            Glide.with(mCOn).load(R.drawable.import_audio).into(holder.vb.image);
        }else {
            Glide.with(mCOn).load(bean.getCovert()).into(holder.vb.image);
        }


        holder.vb.frameIm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mCOn, FXPlayAct.class);
                intent.putExtra(ConstValues.KEY_PLAY_DATA, bean);
                mCOn.startActivity(intent);
            }
        });
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {

        public ItemLikeBinding vb;

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

        }

    }
}