package com.app.keyboard.colorful.ada;


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

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.app.keyboard.colorful.data.ChildBean;
import com.bumptech.glide.Glide;
import com.app.keyboard.colorful.R;
import com.app.keyboard.colorful.activity.ActivityDownload;
import com.app.keyboard.colorful.databinding.ItemChildBinding;
import com.app.keyboard.colorful.colorlistener.COnClickListener;
import com.app.keyboard.colorful.helper.CommonUtils;

import java.util.ArrayList;
import java.util.List;

public class AdaChild extends RecyclerView.Adapter<AdaChild.ChildViewHolder> {

    private Context mContext;
    private List<ChildBean> mList  ;

    public AdaChild(Context context, List<ChildBean> list) {
        mContext = context;
        this.mList = list;
    }

    @NonNull
    @Override
    public ChildViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemChildBinding inflate = ItemChildBinding.inflate(LayoutInflater.from(parent.getContext()));


        return new ChildViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ChildViewHolder holder, int position) {
        ChildBean childBean = mList.get(position);


        String thumbGif = childBean.getThumbGif();
        String thumb = childBean.getThumbUrl();
        if (!thumbGif.isEmpty()) {
            CommonUtils.INSTANCE.loadWepJif(mContext, thumbGif, holder.binding.imageView);
        } else {
            Glide.with(mContext).load(thumb)
                    .placeholder(R.drawable.def_placeholder)
                    .into(holder.binding.imageView);
        }


        holder.binding.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intentApply = new Intent(mContext, ActivityDownload.class);
                intentApply.putExtra(ActivityDownload.SOURCE_KEY, childBean);
                mContext.startActivity(intentApply);


            }
        });


    }

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

    public static class ChildViewHolder extends RecyclerView.ViewHolder {

        private ItemChildBinding binding;


        public ChildViewHolder(@NonNull ItemChildBinding itemView) {
            super(itemView.getRoot());
            binding = itemView;


        }

    }


}
