package com.base.pdfviewerscannerwhite.ui.appprocess

import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.base.pdfviewerscannerwhite.R
import com.base.pdfviewerscannerwhite.bean.AppBean
import com.base.pdfviewerscannerwhite.databinding.ItemAppProcessBinding
import com.base.pdfviewerscannerwhite.utils.XmlEx.inflate
import com.chad.library.adapter4.BaseQuickAdapter

class AppBeanAdapter : BaseQuickAdapter<AppBean, AppBeanAdapter.AppHolder>() {
    inner class AppHolder(view: View) : RecyclerView.ViewHolder(view)

    var stopAction: ((pkg: String) -> Unit)? = null
    override fun onBindViewHolder(holder: AppHolder, position: Int, item: AppBean?) {
        if (item == null) return

        val binding = ItemAppProcessBinding.bind(holder.itemView)
        binding.iv.setImageDrawable(item.icon)
        binding.tvName.text = item.name
        binding.tvStop.setOnClickListener {
            stopAction?.invoke(item.packageName)
        }
    }

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