package com.xm.test.myfilemaster.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.ImageView
import android.widget.TextView
import com.trustlook.sdk.data.AppInfo
import com.xm.test.myfilemaster.R

class ScanResultAdapter(dataList: ArrayList<AppInfo>,
                        context: Context) : BaseAdapter() {
    private var dataList: ArrayList<AppInfo>
    private var inflater: LayoutInflater
    private var context: Context

    init {
        this.dataList = dataList
        this.context = context
        this.inflater = LayoutInflater.from(context)
    }
    override fun getCount(): Int {
        return dataList.size
    }

    override fun getItem(position: Int): Any {
        return dataList[position]
    }

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

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var view: View
        var viewHolder : ScanResultViewHolder
        if (convertView != null){
            view = convertView
            viewHolder = view.tag as ScanResultViewHolder
        }else{
            viewHolder = ScanResultViewHolder()
            view = inflater.inflate(R.layout.scan_result_list_item_layout, null)
            viewHolder.appIcon = view.findViewById(R.id.scan_app_icon)
            viewHolder.appName = view.findViewById(R.id.scan_app_name)
            viewHolder.appHint = view.findViewById(R.id.scan_app_hint)
            view.tag = viewHolder
        }

        viewHolder.appIcon
        viewHolder.appName.text = dataList[position].appName
        viewHolder.appHint.text = dataList[position].virusName

        return view
    }

    class ScanResultViewHolder{
        lateinit var appIcon: ImageView
        lateinit var appName: TextView
        lateinit var appHint: TextView
    }
}