package com.swago.room.adapter

import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.swago.baseswago.model.live.RoomConfig
import com.swago.loadUrl
import com.youth.banner.adapter.BannerAdapter

class BannerViewAdapter(data:List<RoomConfig.BannersBean>) :  BannerAdapter<RoomConfig.BannersBean, BannerViewAdapter.BannerViewHolder>(data){

    class BannerViewHolder(var imageView: ImageView) : RecyclerView.ViewHolder(
        imageView
    )

    override fun onCreateHolder(parent: ViewGroup, viewType: Int): BannerViewHolder {
        val imageView = ImageView(parent.context)
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
        return BannerViewHolder(imageView)
    }

    override fun onBindView(
        holder: BannerViewHolder?,
        data: RoomConfig.BannersBean,
        position: Int,
        size: Int
    ) {
        holder?.let {
            it.imageView.loadUrl(holder.imageView.context,data.rotation_img_url)
        }
    }
}