package com.xty.base.vp2

import android.util.SparseArray
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.adapter.FragmentViewHolder

class VpAdapter (var list :List<Fragment>, var fragmentActivity: FragmentActivity) : FragmentStateAdapter(fragmentActivity) {
    private val fragmentTags = SparseArray<String>()

    override fun getItemCount(): Int = list.size

    override fun createFragment(position: Int): Fragment {
        val fragment = list[position]
//        val tag = fragmentTags[position]
//        if (tag != null) {
//            val fragmentByTag = fragmentActivity.supportFragmentManager.findFragmentByTag(tag)
//            if (fragmentByTag != null) {
//                return fragmentByTag
//            }
//        }
        return fragment
    }

//    override fun getItemId(position: Int): Long {
//        return list[position].hashCode().toLong()
//    }
//
//    override fun onBindViewHolder(holder: FragmentViewHolder, position: Int, payloads: MutableList<Any>) {
//        super.onBindViewHolder(holder, position, payloads)
//        fragmentTags.put(position, holder.itemId.toString())
//    }
}