<commit_before>package de.bitdroid.flooding.alarms;

import android.os.Bundle;

import de.bitdroid.flooding.R;
import de.bitdroid.flooding.dataselection.BaseRiverSelectionFragment;
import de.bitdroid.flooding.dataselection.BaseStationSelectionFragment;
import de.bitdroid.flooding.dataselection.Extras;
import de.bitdroid.flooding.map.BaseMapFragment;
import de.bitdroid.flooding.map.Station;
import de.bitdroid.flooding.utils.BaseActivity;


public class NewAlarmActivity extends BaseActivity implements Extras {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
		setContentView(R.layout.simple_fragment_container);

		// show all rivers fragment
		getActionBar().setTitle(R.string.alarms_new_title_river);
		getSupportFragmentManager()
				.beginTransaction()
				.replace(R.id.frame, new RiverSelectionFragment())
				.commit();
    }


	private void showStationFragment(String waterName) {
		getActionBar().setTitle(getString(R.string.alarms_new_title_station));
		getSupportFragmentManager()
				.beginTransaction()
				.replace(R.id.frame, StationSelectionFragment.newInstance(waterName))
				.addToBackStack(null)
				.commit();
	}


	private void showMapFragment(String waterName) {
		getActionBar().setTitle(getString(R.string.alarms_new_title_station));
		getSupportFragmentManager()
				.beginTransaction()
				.replace(R.id.frame, MapFragment.newInstance(waterName))
				.addToBackStack(null)
				.commit();
	}


	private void showLevelFragment(String waterName, String stationName) {
		getActionBar().setTitle(getString(R.string.alarms_new_title_level));
		getSupportFragmentManager()
				.beginTransaction()
				.replace(R.id.frame, SelectLevelFragment.newInstance(waterName, stationName))
				.addToBackStack(null)
				.commit();
	}


	@Override
	protected void showExitAnimation() { }



	public static final class RiverSelectionFragment extends BaseRiverSelectionFragment {

		@Override
		protected void onItemClicked(River river) {
			((NewAlarmActivity) getActivity()).showStationFragment(river.getRiverName());
		}

		@Override
		protected void onMapClicked() {
			((NewAlarmActivity) getActivity()).showMapFragment(null);
		}
<commit_msg>alarms: fixed losing current fragment on config change in NewAlarmActivity<commit_after>package de.bitdroid.flooding.alarms;

import android.os.Bundle;
import android.support.v4.app.Fragment;

import de.bitdroid.flooding.R;
import de.bitdroid.flooding.dataselection.BaseRiverSelectionFragment;
import de.bitdroid.flooding.dataselection.BaseStationSelectionFragment;
import de.bitdroid.flooding.dataselection.Extras;
import de.bitdroid.flooding.map.BaseMapFragment;
import de.bitdroid.flooding.map.Station;
import de.bitdroid.flooding.utils.BaseActivity;


public class NewAlarmActivity extends BaseActivity implements Extras {

	private static final String
			STATE_FRAGMENT = "currentFragment",
			STATE_TITLE = "title";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
		setContentView(R.layout.simple_fragment_container);

		Fragment fragment;
		if (savedInstanceState != null) {
			fragment = getSupportFragmentManager().getFragment(savedInstanceState, STATE_FRAGMENT);
			getActionBar().setTitle(savedInstanceState.getString(STATE_TITLE));
		} else {
			fragment = new RiverSelectionFragment();
			getActionBar().setTitle(R.string.alarms_new_title_river);
		}

		// show all rivers fragment
		getSupportFragmentManager()
				.beginTransaction()
				.replace(R.id.frame, fragment)
				.commit();
    }


	private void showStationFragment(String waterName) {
		getActionBar().setTitle(getString(R.string.alarms_new_title_station));
		getSupportFragmentManager()
				.beginTransaction()
				.replace(R.id.frame,  StationSelectionFragment.newInstance(waterName))
				.addToBackStack(null)
				.commit();
	}


	private void showMapFragment(String waterName) {
		getActionBar().setTitle(getString(R.string.alarms_new_title_station));
		getSupportFragmentManager()
				.beginTransaction()
				.replace(R.id.frame,  MapFragment.newInstance(waterName))
				.addToBackStack(null)
				.commit();
	}


	private void showLevelFragment(String waterName, String stationName) {
		getActionBar().setTitle(getString(R.string.alarms_new_title_level));
		getSupportFragmentManager()
				.beginTransaction()
				.replace(R.id.frame, SelectLevelFragment.newInstance(waterName, stationName))
				.addToBackStack(null)
				.commit();
	}


	@Override
	public void onSaveInstanceState(Bundle state) {
		super.onSaveInstanceState(state);
		Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.frame);
		getSupportFragmentManager().putFragment(state, STATE_FRAGMENT, currentFragment);
		state.putString(STATE_TITLE, getActionBar().getTitle().toString());
	}


	@Override
	protected void showExitAnimation() { }



	public static final class RiverSelectionFragment extends BaseRiverSelectionFragment {

		@Override
		protected void onItemClicked(River river) {
			((NewAlarmActivity) getActivity()).showStationFragment(river.getRiverName());
		}

		@Override
		protected void onMapClicked() {
			((NewAlarmActivity) getActivity()).showMapFragment(null);
		}

{'fraction_non_alphanumeric': 0.10390848427073403, 'fraction_numerical': 0.00019065776930409913, 'mean_word_length': 5.533001245330013, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5396363', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1542, 'n_words': 251}