package com.cooleshow.teacher.adapter;

import java.util.ArrayList;

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

/**
 * Author by pq, Date on 2022/5/6.
 */
public class HomePagerAdapter extends FragmentStateAdapter {
    private ArrayList<Fragment> mFragments;

    public HomePagerAdapter(@NonNull Fragment fragment) {
        super(fragment);
    }

    public HomePagerAdapter(@NonNull FragmentActivity fragmentActivity) {
        super(fragmentActivity);
    }

    public void setData(ArrayList<Fragment> fragments) {
        this.mFragments = fragments;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return mFragments.get(position);
    }

    @Override
    public int getItemCount() {
        return mFragments != null ? mFragments.size() : 0;
    }
}
