package org.keyscience.SingletonPattern;

import org.keyscience.fragments.SectionsStatePagerAdapter;

import java.util.HashMap;

public class SingletonFragmentList {

    private static SingletonFragmentList instance;
    private HashMap<String, Integer> fragmentMap;

    private SingletonFragmentList() {
        fragmentMap = new HashMap<>();
        addChildActivities();
    }

    public static SingletonFragmentList getInstance() {
        if (instance == null) {
            instance = new SingletonFragmentList();
        }
        return instance;
    }

    public int getFragmentPosition(String fragmentName) {
        return fragmentMap.get(fragmentName);
    }

    private void addChildActivities() {
        SectionsStatePagerAdapter sectionsStatePagerAdapter = SectionsStatePagerAdapter.getInstanceSectionsStatePagerAdapter();
        for (int i = 0; i < sectionsStatePagerAdapter.getCount(); i++) {
            fragmentMap.put(sectionsStatePagerAdapter.getFragmentName(i), i);
        }
    }
}
