package com.sybotan.android.demo.adapter

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.ListView
import android.widget.TextView
import com.sybotan.android.demo.R
import com.sybotan.android.demo.data.Data
import com.sybotan.android.demo.entitiies.MajorEntity
import com.sybotan.android.demo.tree.BaseTreeAdapter
import com.sybotan.android.demo.tree.Node

class TreeAdapter(
    data: List<MajorEntity>, context: Context, listView: ListView
) : BaseTreeAdapter<MajorEntity>(data, context, listView) {
    override fun getConvertView(
        node: Node<MajorEntity>,
        position: Int,
        convertView: View?,
        parent: ViewGroup?
    ): View {
        var view = convertView
        val holder: Holder
        if (view == null) {
            view = mInflater.inflate(R.layout.item_tree, parent, false)
            holder = Holder()
            holder.label = view.findViewById(R.id.labelTv)!!
            view.tag = holder
        } else {
            holder = view.tag as Holder
        }
        holder.label.text = node.label
        return view!!
    }

    inner class Holder {
        lateinit var label: TextView
    }
}