package org.keyscience.fragments;

import android.support.annotation.NonNull;
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;

public class SectionsStatePagerAdapter extends FragmentStatePagerAdapter {

    private static SectionsStatePagerAdapter sectionsStatePagerAdapter;
    private final List<Fragment> mFragmentList = new ArrayList<>();
    private final List<String> fragmentTitleList = new ArrayList<>();

    private SectionsStatePagerAdapter(FragmentManager fm) {
        super(fm);
    }

    public static SectionsStatePagerAdapter getInstanceSectionsStatePagerAdapter(FragmentManager fragmentManager) {
        if (sectionsStatePagerAdapter == null) {
            sectionsStatePagerAdapter = new SectionsStatePagerAdapter(fragmentManager);
        }
        return sectionsStatePagerAdapter;
    }

    public static SectionsStatePagerAdapter getInstanceSectionsStatePagerAdapter() {
        return sectionsStatePagerAdapter;
    }

    public void addFragment(Fragment fm, String title) {
        mFragmentList.add(fm);
        fragmentTitleList.add(title);
    }

    @Override
    public Fragment getItem(int i) {
        return mFragmentList.get(i);
    }


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


    public String getFragmentName(int i) {
        return fragmentTitleList.get(i);
    }

    public void clean() {
        mFragmentList.clear();
        fragmentTitleList.clear();
    }

}
