package com.sheep.gamegroup.view.adapter;

import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

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

/**
 * 礼包 fragment adapter
 * Created by Administrator on 2017/12/15.
 */

public class TitleFragmentListAdapter extends FragmentPagerAdapter {
    private List<Fragment> mListFragment = new ArrayList<>();
    private List<Object> mTitles = new ArrayList<>();

    public TitleFragmentListAdapter(FragmentManager fragmentManager) {
        super(fragmentManager);
    }

    public void add(Fragment fragment, String title) {
        mListFragment.add(fragment);
        mTitles.add(title);
    }
    public void add(Fragment fragment, String title, int index) {
        mListFragment.add(index, fragment);
        mTitles.add(index, title);
    }

    public void clearData(){
        mListFragment.clear();
        mTitles.clear();
    }

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

    @Override
    public int getCount() {
        return mListFragment.size();
    }

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

    @Override
    public CharSequence getPageTitle(int position) {
        return (CharSequence) mTitles.get(position);
    }

    @Override
    public Parcelable saveState() {
        return null;
    }
}
