package com.zxbw.modulemain.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.viewpager.widget.PagerAdapter
import com.bumptech.glide.Glide
import com.zxbw.modulemain.R
import com.zxhl.cms.AppContext
import java.util.ArrayList

/**
 * @author (wangXuewei)
 * @datetime 2022-05-26 22:30 GMT+8
 * @detail :
 */
class DetailBannerAdapter : PagerAdapter {

    private var mViewList: List<String> = ArrayList()

    constructor(
        mList: List<String>
    ) : super() {
        mViewList = mList //构造方法，参数是我们的页卡，这样比较方便。
    }


    override fun isViewFromObject(p0: View, p1: Any): Boolean {
        return p0 == p1
    }


    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val data = mViewList[position]
        val view = LayoutInflater.from(AppContext.get()).inflate(R.layout.item_layout_detail_banner, null)
        val bg = view.findViewById<ImageView>(R.id.id_img_detail_banner_bg)
        if(data.startsWith("//img")){
            Glide.with(AppContext.get()).load("https:"+data).into(bg)
        }else{
            Glide.with(AppContext.get()).load(data).into(bg)
        }
        container.addView(view)// 添加页卡
        return view
    }

    override fun getItemPosition(`object`: Any): Int {
        return super.getItemPosition(`object`)
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {

        container.removeView(`object` as View)
    }

    override fun getCount(): Int {

        return mViewList.size
    }

}