package com.base.scanqrclear.luma

import android.animation.ObjectAnimator
import android.view.LayoutInflater
import android.view.ViewGroup
import com.base.scanqrclear.databinding.ItemCleanResultBinding

class CleanResultAdapter(
    val data: List<FunctionBean>
) : BaseAdapter<FunctionBean, ItemCleanResultBinding>(data) {

    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup
    ): ItemCleanResultBinding {
        return ItemCleanResultBinding.inflate(layoutInflater, parent, false)
    }

    override fun bind(
        holder: BaseViewHolder<ItemCleanResultBinding>,
        position: Int,
        item: FunctionBean
    ) {
        holder.binding.ivImage.setImageResource(item.icon)
        holder.binding.tvName.setText(item.name)
        holder.binding.tvContent.setText(item.content)
        holder.binding.tvCleanNow.setText(item.text)
        holder.binding.tvCleanNow.setOnClickListener {
            callback?.onClicked(it, position, item)
        }

        val translationX = holder.itemView.context.resources.displayMetrics.widthPixels.toFloat()
        holder.itemView.translationX = -translationX
        ObjectAnimator.ofFloat(holder.itemView, "translationX", -translationX, 0f).apply {
            duration = 1000
            startDelay = (position + 1) * 300L
            start()
        }
    }
}