<commit_before>package com.smeanox.apps.webcomicreader;

import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.InputType;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.smeanox.apps.webcomicreader.providers.ComicProvider;

import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Stack;

public class ComicActivity extends AppCompatActivity {

	private final String PREFS_CURRENT_COMIC = "currentComic";
	private Comic currentComic;
	private SharedPreferences prefs;

	private ComicProvider provider;

	private Stack<Comic> lastComics;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_comic);
		Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
		setSupportActionBar(toolbar);
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);

		String comicName = getIntent().getStringExtra(MainActivity.EXTRA_COMIC_NAME);

		for (ComicProvider.ComicProviders providers : ComicProvider.ComicProviders.values()) {
			if(getStringByName(this, providers.name() + "MainButton").equals(comicName)){
				try {
					String clazzName = "com.smeanox.apps.webcomicreader.providers.ComicProvider_" + providers.name();
					Class<?> clazz = Class.forName(clazzName);
					Constructor<?> constructor = clazz.getConstructor(Context.class);
					provider = (ComicProvider) constructor.newInstance(this);
				} catch (InstantiationException e) {
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					e.printStackTrace();
				} catch (ClassNotFoundException e) {
					e.printStackTrace();
				} catch (NoSuchMethodException e) {
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					e.printStackTrace();
				}
			}
		}

		getSupportActionBar().setTitle(comicName);

		prefs = getSharedPreferences(provider.getPrefsName(), MODE_PRIVATE);
		currentComic = provider.getComicById(prefs.getInt(PREFS_CURRENT_COMIC, 0));

		lastComics = new Stack<>();

		updateCurrentComic();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.menu_comic, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {<commit_msg>Save last comics stack on rotation<commit_after>package com.smeanox.apps.webcomicreader;

import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.InputType;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.smeanox.apps.webcomicreader.providers.ComicProvider;

import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Stack;

public class ComicActivity extends AppCompatActivity {

	private final String PREFS_CURRENT_COMIC = "currentComic";
	private final String STATE_LAST_COMICS = "lastComics";
	private Comic currentComic;
	private SharedPreferences prefs;

	private ComicProvider provider;

	private Stack<Comic> lastComics;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_comic);
		Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
		setSupportActionBar(toolbar);
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);

		String comicName = getIntent().getStringExtra(MainActivity.EXTRA_COMIC_NAME);

		for (ComicProvider.ComicProviders providers : ComicProvider.ComicProviders.values()) {
			if(getStringByName(this, providers.name() + "MainButton").equals(comicName)){
				try {
					String clazzName = "com.smeanox.apps.webcomicreader.providers.ComicProvider_" + providers.name();
					Class<?> clazz = Class.forName(clazzName);
					Constructor<?> constructor = clazz.getConstructor(Context.class);
					provider = (ComicProvider) constructor.newInstance(this);
				} catch (InstantiationException e) {
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					e.printStackTrace();
				} catch (ClassNotFoundException e) {
					e.printStackTrace();
				} catch (NoSuchMethodException e) {
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					e.printStackTrace();
				}
			}
		}

		getSupportActionBar().setTitle(comicName);

		prefs = getSharedPreferences(provider.getPrefsName(), MODE_PRIVATE);
		currentComic = provider.getComicById(prefs.getInt(PREFS_CURRENT_COMIC, 0));

		lastComics = new Stack<>();

		if (savedInstanceState != null) {
			int[] last = savedInstanceState.getIntArray(STATE_LAST_COMICS);
			if(last != null) {
					for (int i = last.length - 1; i >= 0; i--) {
					lastComics.push(provider.getComicById(last[i]));
				}
			}
		}

		updateCurrentComic();
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		int size = lastComics.size();
		int[] last = new int[size];
		for (int i = 0; i < size; i++) {
			last[i] = lastComics.pop().getId();
		}
		outState.putIntArray(STATE_LAST_COMICS, last);

		super.onSaveInstanceState(outState);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.menu_comic, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
{'fraction_non_alphanumeric': 0.11011565401531194, 'fraction_numerical': 0.001791822772438508, 'mean_word_length': 5.336429308565531, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3436776', 'n_tokens_mistral': 2053, 'n_tokens_neox': 1822, 'n_words': 351}