package com.yidian.shenghuoquan.newscontent.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.newscontent.R


class SecondCareerListAdapter : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_career_second_list) {


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

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

  override fun convert(holder: BaseViewHolder, item: String) {
    val position = holder.adapterPosition
    val secondCareer = holder.getView<TextView>(R.id.tv_second_career)
    secondCareer.text = item

    if (selectedIndex == position) {
      secondCareer.setTextColor(ContextCompat.getColor(context, R.color.color_1852F1))
    } else {
      secondCareer.setTextColor(ContextCompat.getColor(context, R.color.color_333333))
    }
  }
}
