package com.app.input.inputaura.onjfsgvfsf;

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.input.inputaura.R;
import com.app.input.inputaura.dasda.Shikamaru;
import com.app.input.inputaura.databinding.CuysnBinding;
import com.app.input.inputaura.lmyfvfs.ViyVyg;
import com.app.input.inputaura.kfsdfbsd.IutFhfg;
import com.bumptech.glide.Glide;

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

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

    private Context mContext;
    private List<Shikamaru> mList = new ArrayList<>();

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

    @NonNull
    @Override
    public ChildViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        CuysnBinding inflate = CuysnBinding.inflate(
                LayoutInflater.from(parent.getContext()),
                parent,
                false
        );
        return new ChildViewHolder(inflate);
    }

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

        String thumbGif = shikamaru.getThumbGif();
        String thumb = shikamaru.getThumbUrl();

        // 加载图片
        if (thumbGif != null && !thumbGif.isEmpty()) {
            IutFhfg.INSTANCE.loadWepJif(mContext, thumbGif, holder.binding.imageView);
        } else {
            Glide.with(mContext)
                    .load(thumb)
                    .error(R.drawable.hffghfgh)
                    .placeholder(R.drawable.hffghfgh)
                    .centerCrop()
                    .into(holder.binding.imageView);
        }

        // 设置点击事件
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 直接跳转，不加动画
                Intent intentApply = new Intent(mContext, ViyVyg.class);
                intentApply.putExtra(ViyVyg.SOURCE_KEY, shikamaru);
                intentApply.putExtra(ViyVyg.DISPLAY_URL_KEY, shikamaru.getImgPath());
                intentApply.putExtra(ViyVyg.ZIP_URL_KEY, shikamaru.getZipPath());
                intentApply.putExtra(ViyVyg.NAME_KEY, shikamaru.getTitleName());
                intentApply.putExtra(ViyVyg.GIF_KEY, shikamaru.getImgGif());

                String intent_thumb;
                if (thumbGif != null && !thumbGif.isEmpty()) {
                    intent_thumb = thumbGif;
                } else {
                    intent_thumb = thumb;
                }
                intentApply.putExtra(ViyVyg.THUMB_KEY, intent_thumb);

                mContext.startActivity(intentApply);
            }
        });
    }

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

    public static class ChildViewHolder extends RecyclerView.ViewHolder {
        private CuysnBinding binding;

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