package com.sheep.gamegroup.view.adapter;

import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import java.util.ArrayList;
import java.util.List;
/**
 * Created by realicing on 2018/11/12.
 * realicing@sina.com
 */
public class TitleFragmentListAdapter2 extends FragmentStatePagerAdapter {
    private List<Object> mListFragment = new ArrayList<>();
    private List<Object> mTitles = new ArrayList<>();

    public TitleFragmentListAdapter2(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 (Fragment) mListFragment.get(position);
    }

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

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

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

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