SettingsAdapter.kt 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package com.vpn.fastestvpnservice.adapters
  2. import android.content.Context
  3. import android.graphics.Color
  4. import android.os.Build
  5. import android.view.View
  6. import android.widget.ImageView
  7. import android.widget.TextView
  8. import androidx.cardview.widget.CardView
  9. import com.chad.library.adapter.base.BaseQuickAdapter
  10. import com.chad.library.adapter.base.BaseViewHolder
  11. import com.vpn.fastestvpnservice.R
  12. import com.vpn.fastestvpnservice.beans.Server
  13. import com.vpn.fastestvpnservice.beans.SettingsData
  14. import com.vpn.fastestvpnservice.utils.Utils
  15. class SettingsAdapter: BaseQuickAdapter<SettingsData, BaseViewHolder> {
  16. var context: Context
  17. constructor(context: Context, layoutResId: Int, data: ArrayList<SettingsData>?) : super(
  18. layoutResId, data
  19. ) {
  20. this.context = context
  21. }
  22. override fun convert(helper: BaseViewHolder?, item: SettingsData?) {
  23. var ivIcon = helper?.getView<ImageView>(R.id.ivIconItem)
  24. var tvName = helper?.getView<TextView>(R.id.item_name)
  25. var card_bg = helper?.getView<CardView>(R.id.card_bg)
  26. helper?.itemView?.isFocusable = true
  27. helper?.itemView?.isFocusableInTouchMode = false
  28. ivIcon?.setImageDrawable(
  29. Utils.getCountryFlag(context, item?.iconItem.toString())
  30. )
  31. tvName?.text = item?.iconName
  32. helper?.itemView?.onFocusChangeListener = View.OnFocusChangeListener { view, b ->
  33. if (b) {
  34. card_bg?.background =
  35. context.resources.getDrawable(R.drawable.itemserver_background_tv)
  36. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
  37. tvName?.setTextColor(context.getColor(R.color.app_blue_color))
  38. }
  39. } else {
  40. card_bg?.setBackgroundColor(Color.parseColor("#06143B"))
  41. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
  42. tvName?.setTextColor(context.getColor(R.color.white))
  43. }
  44. }
  45. }
  46. }
  47. }