package com.zj365.health.weight.vp2

import android.util.SparseArray
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentManager
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.zj365.health.fragment.BaseSleepStatisticFrag
import com.zj365.health.fragment.SleepFrag
import com.zj365.health.fragment.SleepStaticDayFrag

class MyAdapter (var fragmentParent : SleepFrag, var list :List<Fragment>, var fragmentActivity: FragmentActivity, var childmanagerFragment:FragmentManager) : FragmentStateAdapter(childmanagerFragment,fragmentActivity.lifecycle) {
    private val fragmentTags = SparseArray<String>()

    override fun getItemCount(): Int = list.size

    override fun createFragment(position: Int): Fragment {
        val fragment = list[position]
        if (fragment is SleepStaticDayFrag) {
            fragment.parentFragment =fragmentParent
        } else if ( fragment is BaseSleepStatisticFrag<*>){
            fragment.parentFragment = fragmentParent
        }
        return fragment
    }

}