<commit_before>
package com.battlelancer.seriesguide.ui;

import com.battlelancer.seriesguide.R;
import com.battlelancer.seriesguide.SeriesGuideData;
import com.battlelancer.seriesguide.provider.SeriesContract.Episodes;
import com.battlelancer.seriesguide.provider.SeriesContract.Seasons;
import com.viewpagerindicator.TitlePageIndicator;
import com.viewpagerindicator.TitleProvider;

import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.ActionBar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import java.util.ArrayList;
import java.util.List;

public class EpisodeDetailsActivity extends BaseActivity {
    protected static final String TAG = "EpisodeDetailsActivity";

    private EpisodePagerAdapter mAdapter;

    private ViewPager mPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.episode_pager);

        final ActionBar actionBar = getSupportActionBar();
        actionBar.setTitle(getString(R.string.episode));
        actionBar.setDisplayShowTitleEnabled(true);

        List<Episode> episodes = new ArrayList<Episode>();
        String episodeId = getIntent().getExtras().getString(Episodes._ID);
        int startPosition = 0;

        // Lookup season of episode
        Cursor episode = getContentResolver().query(Episodes.buildEpisodeUri(episodeId),
                new String[] {
                    Seasons.REF_SEASON_ID
                }, null, null, null);

        if (episode != null && episode.moveToFirst()) {
            String seasonId = episode.getString(0);

            // lookup episodes of season
            Cursor episodeCursor = getContentResolver().query(
                    Episodes.buildEpisodesOfSeasonUri(seasonId), new String[] {
                            Episodes._ID, Episodes.NUMBER, Episodes.SEASON
                    }, null, null, null);

            if (episodeCursor != null) {
                int i = 0;
                while (episodeCursor.moveToNext()) {
                    Episode ep = new Episode();
                    String curEpisodeId = episodeCursor.getString(0);
                    // look for episode to show initially
                    if (curEpisodeId.equalsIgnoreCase(episodeId)) {
                        startPosition = i;
                    }
                    ep.setId(curEpisodeId);
                    ep.setNumber(episodeCursor.getString(1));
                    ep.setSeason(episodeCursor.getString(2));
                    episodes.add(ep);
                    i++;
                }
            }
        }

        SharedPreferences prefs = PreferenceManager
                .getDefaultSharedPreferences(getApplicationContext());

        mAdapter = new EpisodePagerAdapter(getSupportFragmentManager(), episodes, prefs);

        mPager = (ViewPager) findViewById(R.id.pager);
        mPager.setAdapter(mAdapter);

        TitlePageIndicator indicator = (TitlePageIndicator) findViewById(R.id.indicator);
        indicator.setViewPager(mPager, startPosition);
    }

    public static class EpisodePagerAdapter extends FragmentPagerAdapter implements TitleProvider {

        private List<Episode> mEpisodes;
<commit_msg>Invalidate the options menu on page change so the correct episode gets marked watched.<commit_after>
package com.battlelancer.seriesguide.ui;

import com.battlelancer.seriesguide.R;
import com.battlelancer.seriesguide.SeriesGuideData;
import com.battlelancer.seriesguide.provider.SeriesContract.Episodes;
import com.battlelancer.seriesguide.provider.SeriesContract.Seasons;
import com.viewpagerindicator.TitlePageIndicator;
import com.viewpagerindicator.TitleProvider;

import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.ActionBar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;

import java.util.ArrayList;
import java.util.List;

public class EpisodeDetailsActivity extends BaseActivity {
    protected static final String TAG = "EpisodeDetailsActivity";

    private EpisodePagerAdapter mAdapter;

    private ViewPager mPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.episode_pager);

        final ActionBar actionBar = getSupportActionBar();
        actionBar.setTitle(getString(R.string.episode));
        actionBar.setDisplayShowTitleEnabled(true);

        List<Episode> episodes = new ArrayList<Episode>();
        String episodeId = getIntent().getExtras().getString(Episodes._ID);
        int startPosition = 0;

        // Lookup season of episode
        Cursor episode = getContentResolver().query(Episodes.buildEpisodeUri(episodeId),
                new String[] {
                    Seasons.REF_SEASON_ID
                }, null, null, null);

        if (episode != null && episode.moveToFirst()) {
            String seasonId = episode.getString(0);

            // lookup episodes of season
            Cursor episodeCursor = getContentResolver().query(
                    Episodes.buildEpisodesOfSeasonUri(seasonId), new String[] {
                            Episodes._ID, Episodes.NUMBER, Episodes.SEASON
                    }, null, null, null);

            if (episodeCursor != null) {
                int i = 0;
                while (episodeCursor.moveToNext()) {
                    Episode ep = new Episode();
                    String curEpisodeId = episodeCursor.getString(0);
                    // look for episode to show initially
                    if (curEpisodeId.equalsIgnoreCase(episodeId)) {
                        startPosition = i;
                    }
                    ep.setId(curEpisodeId);
                    ep.setNumber(episodeCursor.getString(1));
                    ep.setSeason(episodeCursor.getString(2));
                    episodes.add(ep);
                    i++;
                }
            }
        }

        SharedPreferences prefs = PreferenceManager
                .getDefaultSharedPreferences(getApplicationContext());

        mAdapter = new EpisodePagerAdapter(getSupportFragmentManager(), episodes, prefs);

        mPager = (ViewPager) findViewById(R.id.pager);
        mPager.setAdapter(mAdapter);

        TitlePageIndicator indicator = (TitlePageIndicator) findViewById(R.id.indicator);
        indicator.setViewPager(mPager, startPosition);
        indicator.setOnPageChangeListener(new OnPageChangeListener() {

            @Override
            public void onPageSelected(int arg0) {
                invalidateOptionsMenu();
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
            }
        });

    }

    public static class EpisodePagerAdapter extends FragmentStatePagerAdapter implements
            TitleProvider {

        private List<Episode> mEpisodes;

{'fraction_non_alphanumeric': 0.08443026193325355, 'fraction_numerical': 0.003722909187608031, 'mean_word_length': 2.4840203798054654, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 46, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2655846', 'n_tokens_mistral': 2026, 'n_tokens_neox': 1909, 'n_words': 383}