package com.adealink.weparty.debug

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.adealink.weparty.R

class SwitchTestAccountAdapter(mContext: Context, private var list: ArrayList<String>) :
    RecyclerView.Adapter<SwitchTestAccountAdapter.MyHolder>() {
    private var context: Context? = mContext
    private var itemClickListener: IAccountItemClickListener? =null

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.debug_text_item, parent, false)
        return MyHolder(view)
    }

    override fun getItemCount(): Int = list.size

    override fun onBindViewHolder(holder: MyHolder, position: Int) {
        holder.text.text = list[position]

        // 点击事件
        holder.itemView.setOnClickListener {
            itemClickListener?.onItemClick(position)
        }
    }

    class MyHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
            var text: TextView = itemView.findViewById(R.id.content_tv)
    }

    // 提供set方法
    fun setAccountItemClickListener(itemClickListener: IAccountItemClickListener) {
        this.itemClickListener = itemClickListener
    }

    //自定义接口
    interface IAccountItemClickListener {
        fun onItemClick(position: Int)
    }

}
