package org.deke.risk.riskahead.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

import org.deke.risk.riskahead.fragment.SubscriptionItemFragment;

/**
 *
 * (C) Copyright 2016 RiskAhead (http://www.riskahead.net)
 * Developer & Contributor: Dennis Thießen (dennis.thiessen@riskahead.net)
 * Date of Release: 10.02.2016
 *
 */
public class SubscriptionsPagerAdapter extends FragmentStatePagerAdapter {
    private int mNumOfTabs;

    private SubscriptionItemFragment frag1;
    private SubscriptionItemFragment frag2;

    public SubscriptionsPagerAdapter(FragmentManager fm, int NumOfTabs) {
        super(fm, FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
        this.mNumOfTabs = NumOfTabs;
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        Fragment returnFragment = new Fragment();

            switch (position) {
                case 0:
                    if(frag1 == null) frag1 = new SubscriptionItemFragment();
                    returnFragment = frag1;
                    break;
                case 1:
                    if(frag2 == null) frag2 = new SubscriptionItemFragment();
                    returnFragment = frag2;
                    break;
            }

        return returnFragment;
    }

    @Override
    public int getCount() {
        return mNumOfTabs;
    }
}