package com.develop.setting.init.adapter

import android.widget.ImageView
import android.widget.RelativeLayout
import androidx.appcompat.widget.AppCompatTextView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.develop.common.utils.ConfigUtils
import com.develop.setting.R


class LanguageAdapterV3 :
    BaseQuickAdapter<ConfigUtils.Lang, BaseViewHolder>(R.layout.item_language_view2) {
    private var selectedPosition = 0
    override fun convert(holder: BaseViewHolder, item: ConfigUtils.Lang) {
        val ivIcon = holder.getView<ImageView>(R.id.ic_icon)
        val tvTitle = holder.getView<AppCompatTextView>(R.id.tv_title)
        val cardView = holder.getView<RelativeLayout>(R.id.content_layout)
        if (selectedPosition == holder.adapterPosition) {
            tvTitle.setTextColor(context.resources.getColor(R.color.color_fff))
            cardView.setBackgroundResource(R.drawable.shape_60px000000_corners)
        } else {
            tvTitle.setTextColor(context.resources.getColor(R.color.color_000000))
            cardView.setBackgroundResource(R.drawable.shape_60px000000_stroke)
        }
        Glide.with(context).load(context.resources.getIdentifier(item.icon,"drawable","com.develop.foodcooking")).into(ivIcon)

        tvTitle.text = item.showName

    }


    fun updateSelectedPosition(adapterPosition: Int) {
        val tempPosition = selectedPosition
        selectedPosition = adapterPosition
        notifyItemChanged(tempPosition)
        notifyItemChanged(selectedPosition)
    }
}