package com.gh.gamecenter.forum.home.follow.adapter

import android.annotation.SuppressLint
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.gh.gamecenter.entity.FollowUserEntity
import com.gh.gamecenter.forum.home.follow.fragment.FollowDynamicListFragment

class FollowedViewPagerAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {

    private val dataList = arrayListOf<FollowUserEntity>()

    @SuppressLint("NotifyDataSetChanged")
    fun addData(newData: List<FollowUserEntity>) {
        if (dataList.isEmpty()) {
            dataList.addAll(newData)
            notifyDataSetChanged()
        } else {
            val start = dataList.size
            dataList.addAll(newData)
            notifyItemRangeChanged(start, newData.size)
        }
    }

    override fun getItemCount(): Int = dataList.size

    override fun createFragment(position: Int): Fragment {
        val item = dataList[position]
        return FollowDynamicListFragment.newInstance(item.user.id ?: "", item.bbs.id,item.bbs.type)
    }
}