package com.design.mischiefgo.ut

import android.content.Context
import android.content.Intent
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.design.mischiefgo.entity.Usual
import com.design.mischiefgo.databinding.ItemYellowCenterBinding
import com.design.mischiefgo.ui.TypeInActivity
import com.bumptech.glide.Glide

class YellowCenterAdapter: RecyclerView.Adapter<YellowCenterAdapter.DoubleViewHolder>() {
    private lateinit var context:Context
    private var beanList :List<Usual> = arrayListOf()


    class DoubleViewHolder(val binding: ItemYellowCenterBinding): RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DoubleViewHolder {
        context=parent.context
        val binding=ItemYellowCenterBinding.inflate(LayoutInflater.from(context),parent,false)
        return DoubleViewHolder(binding)
    }
    override fun getItemCount(): Int {
        return beanList.size
    }
    override fun onBindViewHolder(holder: DoubleViewHolder, position: Int) {

        val myBean = beanList[position]
        val covert: String = myBean.convert
        Log.d("covert",covert)
        Glide.with(context).load(covert).into(holder.binding.image)
        holder.binding.title.text = myBean.name
        holder.binding.imgRelay.setOnClickListener {
            val intent = Intent(context, TypeInActivity::class.java)
            intent.putExtra(TypeInActivity.KEY_LIST_DATA, myBean)
            context.startActivity(intent)
        }
    }
    fun setList(list: List<Usual>){
        this.beanList=list
    }
}