package com.yidian.shenghuoquan.bmanagercenter.adapter

import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.yidian.shenghuoquan.bmanagercenter.R


/**
 * 选择职业数据适配器
 */
class FirstCareerListAdapter : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_career_first_list) {

  //记录当前选中的条目索引
  private var selectedIndex = 0

  fun setSelectedIndex(position: Int) {
    selectedIndex = position
    notifyDataSetChanged()
  }

  override fun convert(holder: BaseViewHolder, item: String) {
    val position = holder.adapterPosition
    val firstCareer = holder.getView<TextView>(R.id.tv_first_career)
    firstCareer.text = item
    if (selectedIndex == position) {
      holder.itemView.setBackgroundColor(ContextCompat.getColor(context, R.color.white))
      firstCareer.setTextColor(ContextCompat.getColor(context, R.color.color_1852F1))
    } else {
      holder.itemView.setBackgroundColor(ContextCompat.getColor(context, R.color.color_FFF2F2F2))
      firstCareer.setTextColor(ContextCompat.getColor(context, R.color.color_333333))
    }
  }
}
