package com.ccwangluo.accelerator.ui.news

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

class DemoCollectionAdapter(fragment: Fragment, val titles: Array<String>) :
    FragmentStateAdapter(fragment) {


    override fun getItemCount(): Int = titles.size
    var list = mutableListOf<DemoObjectFragment>()

    override fun createFragment(position: Int): Fragment {
        val fragment = DemoObjectFragment()
        fragment.arguments = Bundle().apply {
            // Our object is just an integer :-P
            putInt(ARG_OBJECT, position)
        }
        list.add(fragment)
        return fragment
    }

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

    companion object {
        val ARG_OBJECT = "object"
    }
}
