package com.rdiot.yx485.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.ArrayList;
import java.util.List;

public class MainHomePagerAdapter extends FragmentStateAdapter {
    private final List<Fragment> mFragments = new ArrayList<>();

    public MainHomePagerAdapter(FragmentActivity fm, List<Fragment> fragments) {
        super(fm);
        mFragments.clear();
        mFragments.addAll(fragments);
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        if (position >= mFragments.size()) {
            return new Fragment();
        }
        return mFragments.get(position);
    }

    @Override
    public int getItemCount() {
        return mFragments.size();
    }
}
