package com.yidian.shenghuoquan.newscontent.adapter

import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.yidian.common.utils.ViewHolderUtil.Companion.createItemView
import com.yidian.shenghuoquan.newscontent.R
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.item_update_version_des.*

class UpdateVersionDesAdapter: RecyclerView.Adapter<RecyclerView.ViewHolder>() {
    private val dataList: ArrayList<String> by lazy { ArrayList<String>() }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return ViewHolder(createItemView(parent, R.layout.item_update_version_des))
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        holder as ViewHolder
        holder.setData(dataList[position])
    }

    override fun getItemCount(): Int {
        return dataList.size
    }

    fun update(newData: ArrayList<String>){
        newData.let {
            dataList.clear()
            dataList.addAll(it)
            notifyDataSetChanged()
        }
    }

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), LayoutContainer {
        override val containerView: View
            get() = itemView

        fun setData(des: String) {
            tv_versionDes.text = des
        }
    }
}
