package com.vpn.fastestvpnservice.adapters import android.content.Context import android.graphics.Color import android.os.Build import android.view.View import android.widget.ImageView import android.widget.TextView import androidx.cardview.widget.CardView import com.chad.library.adapter.base.BaseQuickAdapter import com.chad.library.adapter.base.BaseViewHolder import com.vpn.fastestvpnservice.R import com.vpn.fastestvpnservice.beans.Server import com.vpn.fastestvpnservice.beans.SettingsData import com.vpn.fastestvpnservice.utils.Utils class SettingsAdapter: BaseQuickAdapter { var context: Context constructor(context: Context, layoutResId: Int, data: ArrayList?) : super( layoutResId, data ) { this.context = context } override fun convert(helper: BaseViewHolder?, item: SettingsData?) { var ivIcon = helper?.getView(R.id.ivIconItem) var tvName = helper?.getView(R.id.item_name) var card_bg = helper?.getView(R.id.card_bg) helper?.itemView?.isFocusable = true helper?.itemView?.isFocusableInTouchMode = false ivIcon?.setImageDrawable( Utils.getCountryFlag(context, item?.iconItem.toString()) ) tvName?.text = item?.iconName helper?.itemView?.onFocusChangeListener = View.OnFocusChangeListener { view, b -> if (b) { card_bg?.background = context.resources.getDrawable(R.drawable.itemserver_background_tv) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { tvName?.setTextColor(context.getColor(R.color.app_blue_color)) } } else { card_bg?.setBackgroundColor(Color.parseColor("#06143B")) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { tvName?.setTextColor(context.getColor(R.color.white)) } } } } }