package com.cr.adapter

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.cr.cruav.R
import com.cr.models.AircraftLineCountModel

/**
 * 操作系统：MAC系统
 * 创建者：王成
 * 创建日期：2023/9/19 14:31
 * 描述：航点明细适配器
 */
class CrWaypointDetailAdapter @JvmOverloads constructor(
    context:Context,
    dataList:MutableList<AircraftLineCountModel.WaypointDetailModel>
) : CrAdapter<AircraftLineCountModel.WaypointDetailModel>(context,dataList) {
    companion object{
        class ViewHolder{
            var lblCount:TextView?= null // define: 2023/9/19 数量
            var lblDate:TextView?= null // define: 2023/9/19 日期
        }
    }

    /**
     * 重写获取视图方法
     * @param position Int 索引位置
     * @param convertView View?  视图
     * @param p2 ViewGroup? 视图组
     * @return View? 视图
     */
    override fun getView(position: Int, convertView: View?, p2: ViewGroup?): View? {
        var holder: ViewHolder?=null
        var view = convertView
        if(convertView == null){
            holder = ViewHolder()
            view = inflater?.inflate(R.layout.item_waypoint_detail,null)
            holder.lblCount = view?.findViewById(R.id.lbl_count)
            holder.lblDate = view?.findViewById(R.id.lbl_date)
            view?.tag = holder
        }else{
            holder = view?.tag as ViewHolder
        }
        // todo: 2023/9/19 获取数据
        var model = dataList!![position]
        holder.lblDate?.text = model.date
        holder.lblCount?.text = "${model.count}个"
        return view
    }
}