package com.ym.userinfo.module.adapter

import android.content.Context
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 com.ym.library.base.BaseRecyclerAdapter
import com.ym.library.module.WithdrawEntity
import com.ym.module.userinfo.R

/**
 *Craeted by ${junqi.li}
 *Craeted by 2020/8/27
 */
class WithdrawalsRecordAdapter :
    BaseRecyclerAdapter<WithdrawEntity, WithdrawalsRecordAdapter.RecordViewHodler> {

    private var context: Context? = null

    constructor(context: Context?) : super() {
        this.context = context
    }

    override fun getItemCount(): Int {
        return mList.size
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecordViewHodler {
        return RecordViewHodler(
            LayoutInflater.from(context).inflate(
                R.layout.item_withdrawals_record,
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(holder: RecordViewHodler, position: Int) {
        val data = mList[position]
        holder.tvTitle.text = data.title
        holder.tvTime.text = data.time
        holder.tvMoney.text = "${data.wdAmount}元"
        if ("提现成功".equals(data.result)) {
            holder.ivStatus.visibility = View.VISIBLE
        } else {
            holder.ivStatus.visibility = View.GONE
        }
    }

    class RecordViewHodler : RecyclerView.ViewHolder {
        var tvTitle: TextView
        var tvTime: TextView
        var tvMoney: TextView
        var ivStatus: ImageView

        constructor(itemView: View) : super(itemView) {
            tvTitle = itemView.findViewById(R.id.tv_record_title)
            tvTime = itemView.findViewById(R.id.tv_record_time)
            tvMoney = itemView.findViewById(R.id.tv_record_money)
            ivStatus = itemView.findViewById(R.id.iv_record_status)
        }
    }
}