package com.guadou.cs_cptservices.adapter

import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.guadou.lib_baselib.engine.extLoad
import com.guadou.lib_baselib.engine.extLoadGif
import com.guadou.lib_baselib.ext.checkExtEmpty
import com.youth.banner.adapter.BannerAdapter

/**
 * Banner库2.0版本 全局的默认的适配器
 */
class BannerGlobalAdapter : BannerAdapter<String?, BannerGlobalAdapter.ImageHolder> {

    var mPlaceHolderRes = 0

    constructor(datas: List<String?>) : super(datas)

    constructor(datas: List<String?>, placeHolderRes: Int) : super(datas) {
        mPlaceHolderRes = placeHolderRes
    }

    override fun onCreateHolder(parent: ViewGroup, viewType: Int): ImageHolder {
        val imageView = ImageView(parent.context)
        val layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
        imageView.layoutParams = layoutParams
        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
        return ImageHolder(imageView)
    }

    override fun onBindView(holder: ImageHolder?, data: String?, position: Int, size: Int) {
        //如果是GIF使用GIF库加载
        data.checkExtEmpty({
            if (!it.endsWith(".gif")) {
                holder?.mImageView?.extLoad(data, mPlaceHolderRes)
            } else {
                holder?.mImageView?.extLoadGif(data, mPlaceHolderRes)
            }
        }
        )
    }


    class ImageHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        var mImageView: ImageView = itemView as ImageView

    }


}