package com.zxhl.uc.page.fragment

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
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.HomeBoxListEntity
import com.zxhl.cms.utils.JumpUtils
import com.zxhl.cms.utils.NoDoubleClickListener
import com.zxhl.cms.widget.RecycleImageView
import com.zxhl.uc.R

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

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

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        var bean = mList[position]
        holder.id_img_goods?.setLoadImageUrl(bean.mainImage, false)
        holder.id_tv_goods_name?.text = bean.boxName
        holder.id_tv_pay_price?.text = "${bean.onePriceStr}"
        holder.id_tv_goods_nums?.text=AppContext.get().getString(R.string.box_detail_open_box_num,"${bean.totalSalesVolume}")
        holder.id_ll_item?.setOnClickListener(object :NoDoubleClickListener(){
            override fun onNoDoubleClick(v: View?) {
                JumpUtils.goodsDetailJump(bean?.boxId)
            }

        })
    }


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

    class ViewHolder : RecyclerView.ViewHolder {

        var id_img_goods: RecycleImageView?
        var id_tv_goods_name: TextView?
        var id_tv_pay_price: TextView?
        var id_tv_goods_nums: TextView?
        var id_ll_item:LinearLayout?

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

            id_tv_goods_name = itemView.findViewById<TextView>(R.id.id_tv_goods_name)
            id_tv_pay_price = itemView.findViewById<TextView>(R.id.id_tv_goods_price)
            id_tv_goods_nums = itemView.findViewById<TextView>(R.id.id_tv_goods_nums)
            id_img_goods = itemView.findViewById<RecycleImageView>(R.id.id_img_goods)
            id_ll_item = itemView.findViewById<LinearLayout>(R.id.id_ll_item)

        }
    }
}