package com.ydl.confide.home.widget.adapter

import android.content.Context
import android.support.v4.view.PagerAdapter
import android.view.View
import android.view.ViewGroup

/**
 * @author yuanwai
 * @描述:倾诉首页--最佳倾听榜单适配器
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2018/9/21
 */
class RecommendExpertAdapter(var mContext : Context,var dataList : List<View>) : PagerAdapter(){

    private var datas : List<View>? = null

    init {
        init()
        (datas as ArrayList).addAll(dataList)
    }

    private fun init(){
        if (null == datas){
            datas = ArrayList()
        }else{
            (datas as ArrayList).clear()
        }
    }

    fun updataItems(dataList: List<View>){
        init()
        (this.datas as ArrayList).addAll(dataList)
        notifyDataSetChanged()
    }

    override fun isViewFromObject(view: View?, `object`: Any?): Boolean {
        return view == `object`
    }

    override fun getCount(): Int {
        return datas!!.size
    }

    override fun instantiateItem(container: ViewGroup?, position: Int): Any {
        var view =datas!![position]
        container!!.addView(view)
        return view
    }

    override fun destroyItem(container: ViewGroup?, position: Int, `object`: Any?) {
        container!!.removeView(datas!![position])
    }
}