package com.hongyegroup.cpt_parttime.adapter

import android.widget.GridView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.guadou.lib_baselib.ext.checkEmpty
import com.hongyegroup.cpt_parttime.R
import com.hongyegroup.cpt_parttime.bean.PopupTitleSubTitleBean

/**
 * 筛选职位信息弹窗中的列表
 */
class PopupPositionAdapter(data: MutableList<PopupTitleSubTitleBean>) :
    BaseQuickAdapter<PopupTitleSubTitleBean, BaseViewHolder>(R.layout.item_popup_position, data) {

    override fun convert(holder: BaseViewHolder, item: PopupTitleSubTitleBean) {
        holder.setIsRecyclable(false)  //禁止复用

        holder.setText(R.id.tv_industry_name, item.title)
            .setGone(R.id.tv_industry_name, item.title.checkEmpty())

        val gridView = holder.getView<GridView>(R.id.grid_view)
        val adapter = PositionGridAdapter(item.positions)
        gridView.adapter = adapter
        gridView.setOnItemClickListener { adapterView, view, index, long ->
            val bean = item.positions[index]
            bean.isSelected = !bean.isSelected
            adapter.notifyDataSetChanged()
        }
    }

}