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.MagicCoinLogEntity
import com.zxhl.cms.widget.RecycleImageView
import com.zxhl.main.R

class MagicCoinAdapter : BaseRecyclerAdapter<MagicCoinLogEntity, MagicCoinAdapter.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.img, false)
        holder.id_tv_time?.text=bean.createdAt
        if(bean.fluctuate==0){
            holder.id_tv_pay_price?.text="-${bean.amount}"
        }else{
            holder.id_tv_pay_price?.text="+${bean.amount}"
        }
        holder.id_tv_goods_name?.text="${bean.typeDesc}｜"+"${bean.title}"
        holder.id_tv_yu_e?.text="余额:${bean.balance}魔币"

    }


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(
            LayoutInflater.from(AppContext.get())
                .inflate(R.layout.item_layout_magic_coin, 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_time: TextView?
        var id_tv_yu_e: TextView?

        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_pay_price)
            id_img_goods = itemView.findViewById<RecycleImageView>(R.id.id_img_goods)
            id_tv_time = itemView.findViewById<TextView>(R.id.id_tv_time)
            id_tv_yu_e = itemView.findViewById<TextView>(R.id.id_tv_yu_e)
        }
    }
}