package com.zxbw.modulemain.box.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 com.zxhl.cms.net.model.box.GoodList
import java.util.*

class TopPagerAdapter : PagerAdapter {


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

    constructor(
        mList: List<GoodList>
    ) : 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_goods_top, null)
        val bg = view.findViewById<ImageView>(R.id.id_img_main)
       // val lottie = view.findViewById<LottieAnimationView>(R.id.id_lottie_daoguang)
        Glide.with(AppContext.get()).load(data?.mainImage).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
    }
}