package com.wayne.www.waynelib.ui.adapter

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import com.wayne.www.waynelib.entity.ShellTrxStatus
import com.wayne.www.waynelib.listener.OnItemViewButtonClickListener
import com.wayne.www.waynelib.ui.view.ShellTrxStatusView

class ShellTrxGridViewAdapter : BaseAdapter {
    private var transactionStatus: List<ShellTrxStatus?>? = mutableListOf()
    private var context: Context? = null
    private var onItemViewButtonClickListener: OnItemViewButtonClickListener? = null

    constructor(baseContext: Context?, onItemViewButtonClickListener: OnItemViewButtonClickListener? ) {
        this.context = baseContext
        this.onItemViewButtonClickListener = onItemViewButtonClickListener
    }

    fun setData(data: List<ShellTrxStatus?>?) {
        this.transactionStatus = data
    }

    override fun getView(position: Int, view: View?, viewGroup: ViewGroup?): View {
        val v = ShellTrxStatusView(this.context, this.transactionStatus!!.get(position)!!, position)
        v.addOnItemViewButtonClickListener(this.onItemViewButtonClickListener)
        return v
    }

    override fun getItem(position: Int): Any {
        return transactionStatus!!.get(position)!!
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getCount(): Int {
        return transactionStatus!!.count()
    }
}