package fsir.tqqe

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.bumptech.glide.Glide
import com.test.basd.supercleanermax.R
import pxds.lmmd.zmwf.Khko.setTrackedOnClickListener

class Slnz : RecyclerView.Adapter<Slnz.ContentViewHolder> {

    private val mListener: Vtzf<Kikc>

    fun updateData(mList: List<Kikc>) {
        this.mList = mList
        notifyDataSetChanged()
    }

    override fun getItemCount(): Int = mList.size

    inner class ContentViewHolder : ViewHolder {

        val mName: TextView
        val mNum: TextView
        val mImage: ImageView

        constructor(itemView: View) : super(itemView) {

            mName = itemView.findViewById(R.id.bliklep)
            mNum = itemView.findViewById(R.id.gvjwbji)
            mImage = itemView.findViewById(R.id.numbvea)

            itemView.setTrackedOnClickListener {
                if(position>=0&&position<mList.size){
                    val entity = mList[position]
                    mListener.onItemClick(position, entity)
                }

            }
        }
    }

    constructor(mList: List<Kikc>, mListener: Vtzf<Kikc>) : super() {
        this.mList = mList
        this.mListener = mListener
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ContentViewHolder {

        return ContentViewHolder(
            LayoutInflater.from(parent.context).inflate(R.layout.jvgiyv, parent, false)
        )
    }

    private var mList: List<Kikc>

    override fun onBindViewHolder(holder: ContentViewHolder, position: Int) {

        val entity = mList[position]

        holder.mName.text = entity.name
        holder.mNum.text = entity.num.toString()

        Glide.with(holder.itemView.context).load(entity.src).into(holder.mImage)
    }
}