package com.base.browserwhite.ui.adapter

import android.graphics.drawable.Drawable
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.base.browserwhite.databinding.ItemNewsBinding
import com.base.browserwhite.utils.KotlinExt.toFormatTime
import com.base.browserwhite.utils.LogEx
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import com.chad.library.adapter4.loadState.LoadState
import com.chad.library.adapter4.loadState.LoadStateAdapter

//class NewsAdapter2: LoadStateAdapter<NewsAdapter2.NewsViewHolder>() {
//    inner class NewsViewHolder(view: View) : RecyclerView.ViewHolder(view)
//
//    override fun onBindViewHolder(holder: NewsViewHolder, loadState: LoadState) {
//        val binding = ItemNewsBinding.bind(holder.itemView)
//        val bean = beanList[holder.position]
//        val context = holder.itemView.context
//        Glide.with(context).load(bean.orgImgPath).listener(object : RequestListener<Drawable> {
//            override fun onLoadFailed(
//                e: GlideException?,
//                model: Any?,
//                target: Target<Drawable>,
//                isFirstResource: Boolean
//            ): Boolean {
//                LogEx.logDebug(TAG, "onLoadFailed $log")
////                beanList.remove(bean)
//                return true
//            }
//
//            override fun onResourceReady(
//                resource: Drawable,
//                model: Any,
//                target: Target<Drawable>?,
//                dataSource: DataSource,
//                isFirstResource: Boolean
//            ): Boolean {
//                return false
//            }
//
//        }).centerCrop().into(binding.ivMedia)
//        binding.tvTittle.text = bean.headline
//        runCatching {
//            Glide.with(context).load(bean.mediaIcon).into(binding.ivIcon)
//        }
//        binding.tvMediaName.text = bean.mediaName
//        binding.tvPublishTime.text = bean.publishTime.toFormatTime()
//        bean.isBind = true
//    }
//
//    override fun onCreateViewHolder(parent: ViewGroup, loadState: LoadState): NewsViewHolder {
//        TODO("Not yet implemented")
//    }
//}