package com.base.locationsharewhite.ui.main

import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.base.locationsharewhite.R
import com.base.locationsharewhite.bean.ViewerBean
import com.base.locationsharewhite.databinding.ItemViewerBinding
import com.base.locationsharewhite.ui.views.XmlEx.inflate
import com.chad.library.adapter4.BaseQuickAdapter

class ViewerAdapter : BaseQuickAdapter<ViewerBean, ViewerAdapter.ViewerViewHolder>() {

    inner class ViewerViewHolder(view: View) : ViewHolder(view)

    override fun onBindViewHolder(holder: ViewerViewHolder, position: Int, item: ViewerBean?) {
        item ?: return
        val binding = ItemViewerBinding.bind(holder.itemView)
        runCatching { binding.tvNameLetters.text = item.nickName.substring(0, 1) }
        binding.tvNameCode.text = item.nickName
        binding.tvTime.text = "time"
        binding.tvSwitch.isChecked = item.status == 1
    }

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): ViewerViewHolder {
        return ViewerViewHolder(R.layout.item_viewer.inflate(parent))
    }
}