package com.zxbw.modulemain.adapter

import android.app.Activity
import android.content.Context
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestOptions
import com.zxbw.modulemain.R
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseRecyclerAdapter
import com.zxhl.cms.net.model.qy.JgqQyEntity
import com.zxhl.cms.utils.OnRecycleItemClickListener
import kotlinx.android.synthetic.main.activity_layout_rights_detail.*


class JgqQyAdapter : BaseRecyclerAdapter<JgqQyEntity, JgqQyAdapter.ViewHolder> {
    private var mContext: Activity? = null
    private val listener: OnRecycleItemClickListener<JgqQyEntity>

    constructor(
        content: Activity?,
        listener: OnRecycleItemClickListener<JgqQyEntity>
    ) : super() {
        mContext = content
        this.listener = listener
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val bean = mList[position]

        Glide.with(mContext!!).load("https://t10.baidu.com/it/u=3105518379,1723849651&fm=58")
            .apply(RequestOptions.bitmapTransform(CircleCrop()))
            .into(holder?.id_icon!!)
        holder.id_name?.text = bean.brand
        holder.id_ll_qy_item_view?.setOnClickListener {
            listener.onItemClick(it, position, bean)
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(
            LayoutInflater.from(AppContext.get())
                .inflate(R.layout.item_layout_jgq_qy_view, parent, false)
        )
    }

    class ViewHolder : RecyclerView.ViewHolder {
        var id_ll_qy_item_view: LinearLayout?
        var id_icon: ImageView?
        var id_name: TextView?

        constructor(
            itemView: View
        ) : super(itemView) {
            id_ll_qy_item_view = itemView.findViewById<LinearLayout>(R.id.id_ll_qy_item_view)
            id_icon =
                itemView.findViewById<ImageView>(R.id.id_img_qy_icon)
            id_name =
                itemView.findViewById<TextView>(R.id.id_tv_qy_name)


        }
    }
}