package com.ccwangluo.accelerator.ui.news

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter

class NewsCollectionAdapter(fragment: Fragment, val titles: Array<String>,val gameId: Int) :
    FragmentStateAdapter(fragment) {
    var list = mutableListOf<NewsObjectFragment>()

    init {
        for (i in 0..5) {
            val fragment = NewsObjectFragment()
            fragment.arguments = Bundle().apply {
                // Our object is just an integer :-P
                putInt(ARG_OBJECT, i)
                putInt(GAME_ID,gameId)
            }
            list.add(fragment)
        }
    }

    override fun getItemCount(): Int = titles.size
    override fun createFragment(position: Int): Fragment {
        return list.get(position)
    }

    fun refresh(index: Int) {
        if (index < list.size) {
            list.get(index).refresh()
        }
    }

    companion object {
        val ARG_OBJECT = "object"
        val GAME_ID = "GAME_ID"
    }
}
