package com.mgaetan89.showsrage.adapter;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.mgaetan89.showsrage.Constants;
import com.mgaetan89.showsrage.R;
import com.mgaetan89.showsrage.fragment.EpisodeDetailFragment;

import java.util.Collections;
import java.util.List;

public class EpisodePagerAdapter extends FragmentStatePagerAdapter {
	@NonNull
	private final Fragment fragment;

	@NonNull
	private List<Integer> episodes = Collections.emptyList();

	public EpisodePagerAdapter(FragmentManager fragmentManager, @NonNull Fragment fragment, @Nullable List<Integer> episodes) {
		super(fragmentManager);

		this.fragment = fragment;

		if (episodes == null) {
			this.episodes = Collections.emptyList();
		} else {
			this.episodes = episodes;
		}
	}

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

	@Override
	public Fragment getItem(int position) {
		FragmentActivity activity = this.fragment.getActivity();
		Bundle arguments = new Bundle();
		arguments.putInt(Constants.Bundle.EPISODE_NUMBER, this.episodes.get(position));

		if (activity != null) {
			arguments.putAll(activity.getIntent().getExtras());
		}

		EpisodeDetailFragment fragment = new EpisodeDetailFragment();
		fragment.setArguments(arguments);

		return fragment;
	}

	@Override
	public CharSequence getPageTitle(int position) {
		Integer episode = this.episodes.get(position);

		return this.fragment.getString(R.string.episode_name_short, episode);
	}
}

@@ -1238,90 +1238,8 @@
 e();
-%0A%09%09arguments.putInt(Constants.Bundle.EPISODE_NUMBER, this.episodes.get(position));
 %0A%0A%09%09
@@ -1322,16 +1322,99 @@
 );%0A%09%09%7D%0A%0A
+%09%09arguments.putInt(Constants.Bundle.EPISODE_NUMBER, this.episodes.get(position));%0A%0A
 %09%09Episod

Fix #19: Navigation between episodes is broken