package com.zxhl.main.page.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseRecyclerAdapter
import com.zxhl.cms.net.model.box.GoodList
import com.zxhl.cms.widget.RecycleImageView
import com.zxhl.main.R

class ItemGoodsAdapter : BaseRecyclerAdapter<GoodList, ItemGoodsAdapter.ViewHolder> {
    private var mContext: Context? = null

    constructor(
        content: Context?
    ) : super() {
        mContext = content
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        var bean = mList[position]
        holder.item_goods_img?.setLoadImageUrl(bean.mainImage, false)
        holder.item_goods_name?.text = bean.productName
        holder.item_goods_price?.text = "¥${bean.salePriceStr}"
    }


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

    class ViewHolder : RecyclerView.ViewHolder {
        var item_goods_img: RecycleImageView?
        var item_goods_name: TextView?
        var item_goods_price: TextView?

        constructor(
            itemView: View
        ) : super(itemView) {
            item_goods_img = itemView.findViewById<RecycleImageView>(R.id.id_img_goods)
            item_goods_name = itemView.findViewById<TextView>(R.id.id_tv_goods_name)
            item_goods_price = itemView.findViewById<TextView>(R.id.id_tv_goods_price)

        }
    }
}