package com.zxhl.main.page.adapter

import android.animation.ValueAnimator
import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.viewpager.widget.PagerAdapter
import com.airbnb.lottie.LottieAnimationView
import com.bumptech.glide.Glide
import com.zxhl.cms.AppContext
import com.zxhl.cms.net.model.box.GoodList
import com.zxhl.cms.net.model.box.HomeBoxListEntity
import com.zxhl.cms.utils.OnRecycleItemClickListener
import com.zxhl.main.R
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
    }
}