package com.lukouguoji.gjc.adapt

import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.model.GjcQueryInfoWh

class GjcQueryInfoWhListAdapter(val activity: Activity, val collectList: MutableList<GjcQueryInfoWh>) :
    RecyclerView.Adapter<GjcQueryInfoWhListAdapter.ViewHolder>() {

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val pc: TextView = view.findViewById(R.id.pc)
        val weight: TextView = view.findViewById(R.id.weight)
        val flight: TextView = view.findViewById(R.id.flight)
        val opDate: TextView = view.findViewById(R.id.opDate)
        val location: TextView = view.findViewById(R.id.location)
        val opId: TextView = view.findViewById(R.id.opId)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.gjc_query_info_wh_list_item, parent, false)
        val viewHolder = ViewHolder(view)

        return viewHolder
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val collect = collectList[position]
        holder.pc.text = collect.pc.toString()
        holder.weight.text = "${collect.weight} KG"
        holder.flight.text = collect.flight
        holder.opDate.text = collect.opDate
        holder.location.text = collect.location
        holder.opId.text = collect.opId
    }

    override fun getItemCount() = collectList.size

    fun append(gjcQueryInfoWh: GjcQueryInfoWh) {
        collectList.add(gjcQueryInfoWh)
        notifyDataSetChanged()
    }
}