package com.cooleshow.student.adapter;

import android.view.ViewGroup;

import com.cooleshow.base.ui.fragment.BaseMVPFragment;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager2.adapter.FragmentStateAdapter;

/**
 * 创建日期：2022/5/26 17:30
 *
 * @author Ryan
 * 类说明：
 */
public class HomeBottomPageAdapter extends FragmentStatePagerAdapter {

    // Tabs对应的fragment集合
    private List<Fragment> fragments;

    public HomeBottomPageAdapter(FragmentManager fm, List<Fragment> fragments) {
        super(fm);
        this.fragments = fragments;
    }


    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments == null ? 0 : fragments.size();
    }

    @Override
    public int getItemPosition(@NonNull Object object) {
        return PagerAdapter.POSITION_NONE;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        Fragment fragment = null;
        try {
            fragment = (Fragment) super.instantiateItem(container, position);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return fragment;
    }
}
