package com.zztrapp.zztrapp.utilcode.mUtil;

import android.util.SparseArray;

import androidx.fragment.app.Fragment;

import com.zztrapp.zztrapp.ui.currency.CurrencyFragment;
import com.zztrapp.zztrapp.ui.index.IndexFragment;
import com.zztrapp.zztrapp.ui.map.MapFragment;
import com.zztrapp.zztrapp.ui.mine.MineFragment;


/**
 * Describe FragmentFactory
 * Created by Bby on 2022/6/21
 * Email bby0856@163.com
 */

public class FragmentFactory {
    private static final int FRAGMENT_ONE = 0;
    private static final int FRAGMENT_TWO = 1;
    private static final int FRAGMENT_THREE = 2;
    private static final int FRAGMENT_FOUR = 3;
    private static SparseArray<Fragment> fragments = new SparseArray<>();

    public static Fragment createFragment(int index) {

        Fragment fragment = fragments.get(index);
        if (fragment == null) {
            switch (index) {
                case FRAGMENT_ONE:
                    fragment = new IndexFragment();
                    break;
                case FRAGMENT_TWO:
                    fragment = new MapFragment();
                    break;
                case FRAGMENT_THREE:
                    fragment = new CurrencyFragment();
                    break;
                case FRAGMENT_FOUR:
                    fragment = new MineFragment();
                    break;
            }
            fragments.put(index, fragment);
        }
        return fragment;
    }
}
