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

import static de.bitdroid.flooding.pegelonline.PegelOnlineSource.COLUMN_LEVEL_TYPE;
import static de.bitdroid.flooding.pegelonline.PegelOnlineSource.COLUMN_STATION_NAME;
import static de.bitdroid.flooding.pegelonline.PegelOnlineSource.COLUMN_WATER_NAME;

import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import de.bitdroid.flooding.R;
import de.bitdroid.flooding.pegelonline.PegelOnlineSource;
import de.bitdroid.flooding.utils.Log;
import de.bitdroid.flooding.utils.StringUtils;

public final class StationSelectionFragment extends DataSelectionFragment<String> implements Extras {

	private static final int LOADER_ID = 45;
	
	private static final String
		EXTRA_ACTIVITY_ALL_STATIONS = "EXTRA_ACTIVITY_ALL_STATIONS",
		EXTRA_SHOW_ALL_STATIONS_ENTRY = "EXTRA_SHOW_ALL_STATIONS_ENTRY";


	public static StationSelectionFragment newInstance(
			Class<?> activitySingleStation,
			int animEnter, 
			int animExit, 
			String riverName,
			Class<?> activityAllStations,
			boolean showAllStationsEntry) {

		StationSelectionFragment fragment = new StationSelectionFragment();
		Bundle extras = getDefaultExtras(activitySingleStation, animEnter, animExit);
		extras.putString(EXTRA_WATER_NAME, riverName);
		extras.putString(EXTRA_ACTIVITY_ALL_STATIONS, activityAllStations.getName());
		extras.putBoolean(EXTRA_SHOW_ALL_STATIONS_ENTRY, showAllStationsEntry);
		fragment.setArguments(extras);
		return fragment;
	}


	@Override
	protected ArrayAdapter<String> getAdapter() {
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(
				getActivity().getApplicationContext(), 
				android.R.layout.simple_list_item_1,
				android.R.id.text1) {

			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				String station = getItem(position);
				View view = super.getView(position, convertView, parent);

				TextView text1 = (TextView) view.findViewById(android.R.id.text1);
				text1.setText(StringUtils.toProperCase(station));

				return view;
			}
		};

		addExtraEntries(adapter);
		return adapter;
	}


	@Override
	protected Intent getActivityIntent(Class<?> singleStationActivity, String station) {
		Bundle extras = new Bundle();
		extras.putString(EXTRA_WATER_NAME, getArguments().getString(EXTRA_WATER_NAME));

		if (station.equals(getActivity().getString(R.string.data_station_all))) {
			try {
				Class<?> allStationsActivity = Class.forName(getArguments().getString(EXTRA_ACTIVITY_ALL_STATIONS));
				Intent intent = new Intent(
						getActivity().getApplicationContext(),
						allStationsActivity);
				intent.putExtras(extras);
				return intent;
			} catch (ClassNotFoundException cnfe) {
				Log.error("failed to get activity", cnfe);
				return null;
			}

		} else {
			extras.putString(EXTRA_STATION_NAME, station);
			Intent intent = new Intent(
					getActivity().getApplicationContext(),
					singleStationActivity);
			intent.putExtras(extras);
			return intent;
		}
	}


	@Override
	protected int getLoaderId() {
		return LOADER_ID;
	}


	@Override
	protected Loader<Cursor> getLoader() {
		return new CursorLoader(
				getActivity().getApplicationContext(),
				PegelOnlineSource.INSTANCE.toUri(),
				new String[] { COLUMN_STATION_NAME },
				COLUMN_WATER_NAME + "=? AND " + COLUMN_LEVEL_TYPE + "=?", 
				new String[] { getArguments().getString(EXTRA_WATER_NAME), "W" }, 
				null);
	}


	@Override
	protected void onLoadFinished(Cursor cursor, ArrayAdapter<String> listAdapter) {
		int waterIdx = cursor.getColumnIndex(COLUMN_STATION_NAME);

		List<String> stations = new LinkedList<String>();

		if (cursor.getCount() > 0) {
			cursor.moveToFirst();
			do {
				stations.add(cursor.getString(waterIdx));
			} while (cursor.moveToNext());
		}
		
		listAdapter.clear();
		listAdapter.addAll(stations);
		listAdapter.sort(new Comparator<String>() {
			@Override
			public int compare(String e1, String e2) {
				return e1.compareTo(e2);
			}
		});
		addExtraEntries(listAdapter);
		listAdapter.getFilter().filter("");
	}


	private void addExtraEntries(ArrayAdapter<String> adapter) {
		boolean showAllStationsEntry = getArguments().getBoolean(
				EXTRA_SHOW_ALL_STATIONS_ENTRY, 
				false);
		if (showAllStationsEntry) 
			adapter.insert(getActivity().getString(R.string.data_station_all), 0);

	}

}<commit_msg>dataselection: highlight all stations entry<commit_after>package de.bitdroid.flooding.dataselection;

import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

import de.bitdroid.flooding.R;
import de.bitdroid.flooding.pegelonline.PegelOnlineSource;
import de.bitdroid.flooding.utils.Log;
import de.bitdroid.flooding.utils.StringUtils;

import static de.bitdroid.flooding.pegelonline.PegelOnlineSource.COLUMN_LEVEL_TYPE;
import static de.bitdroid.flooding.pegelonline.PegelOnlineSource.COLUMN_STATION_NAME;
import static de.bitdroid.flooding.pegelonline.PegelOnlineSource.COLUMN_WATER_NAME;

public final class StationSelectionFragment extends DataSelectionFragment<String> implements Extras {

	private static final int LOADER_ID = 45;
	
	private static final String
		EXTRA_ACTIVITY_ALL_STATIONS = "EXTRA_ACTIVITY_ALL_STATIONS",
		EXTRA_SHOW_ALL_STATIONS_ENTRY = "EXTRA_SHOW_ALL_STATIONS_ENTRY";


	public static StationSelectionFragment newInstance(
			Class<?> activitySingleStation,
			int animEnter, 
			int animExit, 
			String riverName,
			Class<?> activityAllStations,
			boolean showAllStationsEntry) {

		StationSelectionFragment fragment = new StationSelectionFragment();
		Bundle extras = getDefaultExtras(activitySingleStation, animEnter, animExit);
		extras.putString(EXTRA_WATER_NAME, riverName);
		extras.putString(EXTRA_ACTIVITY_ALL_STATIONS, activityAllStations.getName());
		extras.putBoolean(EXTRA_SHOW_ALL_STATIONS_ENTRY, showAllStationsEntry);
		fragment.setArguments(extras);
		return fragment;
	}


	@Override
	protected ArrayAdapter<String> getAdapter() {
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(
				getActivity().getApplicationContext(), 
				android.R.layout.simple_list_item_1,
				android.R.id.text1) {

			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				String station = getItem(position);
				View view = super.getView(position, convertView, parent);

				TextView text1 = (TextView) view.findViewById(android.R.id.text1);
				text1.setText(StringUtils.toProperCase(station));

				// if all stations entry --> highlight
				if (isShowingAllEntries() && station.equals(getString(R.string.data_station_all))) {
					text1.setTextColor(getResources().getColor(R.color.blue));
				} else {
					text1.setTextColor(getResources().getColor(R.color.white));
				}

				return view;
			}
		};

		addExtraEntries(adapter);
		return adapter;
	}


	@Override
	protected Intent getActivityIntent(Class<?> singleStationActivity, String station) {
		Bundle extras = new Bundle();
		extras.putString(EXTRA_WATER_NAME, getArguments().getString(EXTRA_WATER_NAME));

		if (station.equals(getActivity().getString(R.string.data_station_all))) {
			try {
				Class<?> allStationsActivity = Class.forName(getArguments().getString(EXTRA_ACTIVITY_ALL_STATIONS));
				Intent intent = new Intent(
						getActivity().getApplicationContext(),
						allStationsActivity);
				intent.putExtras(extras);
				return intent;
			} catch (ClassNotFoundException cnfe) {
				Log.error("failed to get activity", cnfe);
				return null;
			}

		} else {
			extras.putString(EXTRA_STATION_NAME, station);
			Intent intent = new Intent(
					getActivity().getApplicationContext(),
					singleStationActivity);
			intent.putExtras(extras);
			return intent;
		}
	}


	@Override
	protected int getLoaderId() {
		return LOADER_ID;
	}


	@Override
	protected Loader<Cursor> getLoader() {
		return new CursorLoader(
				getActivity().getApplicationContext(),
				PegelOnlineSource.INSTANCE.toUri(),
				new String[] { COLUMN_STATION_NAME },
				COLUMN_WATER_NAME + "=? AND " + COLUMN_LEVEL_TYPE + "=?", 
				new String[] { getArguments().getString(EXTRA_WATER_NAME), "W" }, 
				null);
	}


	@Override
	protected void onLoadFinished(Cursor cursor, ArrayAdapter<String> listAdapter) {
		int waterIdx = cursor.getColumnIndex(COLUMN_STATION_NAME);

		List<String> stations = new LinkedList<String>();

		if (cursor.getCount() > 0) {
			cursor.moveToFirst();
			do {
				stations.add(cursor.getString(waterIdx));
			} while (cursor.moveToNext());
		}
		
		listAdapter.clear();
		listAdapter.addAll(stations);
		listAdapter.sort(new Comparator<String>() {
			@Override
			public int compare(String e1, String e2) {
				return e1.compareTo(e2);
			}
		});
		addExtraEntries(listAdapter);
		listAdapter.getFilter().filter("");
	}


	private void addExtraEntries(ArrayAdapter<String> adapter) {
		if (isShowingAllEntries()) adapter.insert(getActivity().getString(R.string.data_station_all), 0);

	}


	private boolean isShowingAllEntries() {
		return getArguments().getBoolean(EXTRA_SHOW_ALL_STATIONS_ENTRY, false);
	}

}
{'fraction_non_alphanumeric': 0.10658112582781457, 'fraction_numerical': 0.0033112582781456954, 'mean_word_length': 5.16390306122449, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 34, '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': '5047330', 'n_tokens_mistral': 3470, 'n_tokens_neox': 3033, 'n_words': 542}