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.TransactionStatus
import com.wayne.www.waynelib.ui.view.TransactionStatusItemView

/**
 * Created by Justin on 4/13/2018.
 */
class TransactionStatusAdapter : BaseAdapter {

    private var transactionStatus: List<TransactionStatus?>? = null
    private var context: Context? = null

    constructor(baseContext: Context?, trxList: List<TransactionStatus?>) {
        this.context = baseContext
        this.transactionStatus = trxList
    }

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

    override fun getView(position: Int, view: View?, viewGroup: ViewGroup?): View {
        if (view == null) {
            val v = TransactionStatusItemView(this.context, this.transactionStatus!!.get(position)!!)
            return v
        } else {
            return TransactionStatusItemView(this.context, this.transactionStatus!!.get(position)!!)
        }
    }

    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()
    }
}