package com.ar.artracestudio.adapter;

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

import com.ar.artracestudio.fragment.CategoryFragment;
import com.ar.artracestudio.fragment.FavoriteFragment;
import com.ar.artracestudio.fragment.ImportFragment;

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

public class MainViewPager2Adapter extends FragmentStateAdapter {

    private List<Fragment> fragmentList;

    public MainViewPager2Adapter(@NonNull FragmentActivity fragmentActivity) {
        super(fragmentActivity);
        // 初始化fragmentList并添加Fragment对象
        fragmentList = new ArrayList<>();
        fragmentList.add(new CategoryFragment());
        fragmentList.add(new ImportFragment());
        fragmentList.add(new FavoriteFragment());
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        // 根据位置返回相应的Fragment
        return fragmentList.get(position);
    }

    @Override
    public int getItemCount() {
        // 返回Fragment列表的大小
        return fragmentList.size();
    }
}
