package com.example.wallpapermagazine.adapter.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

import com.example.wallpapermagazine.LoveDAO.FavoriteImage;
import com.example.wallpapermagazine.fragment.PreviewFragment;

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

public class MyPagerAdapter extends FragmentStatePagerAdapter {
    private List<FavoriteImage> names; // 存储数据列表
    private List<PreviewFragment> fragmentList; // 存储 Fragment 列表

    public MyPagerAdapter(FragmentManager fm, List<FavoriteImage> dataList) {
        super(fm);
        this.names = dataList;
        fragmentList = new ArrayList<>();
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        PreviewFragment fragment = PreviewFragment.newInstance(names.get(position).getImageUrl());
        fragmentList.add(fragment);
        return fragment;
    }
    @Override
    public int getCount() {
        return fragmentList.size();
    }
}
