<commit_before>package org.duckdns.raven.ttscallresponder.ui.responseTemplates;

import org.duckdns.raven.ttscallresponder.R;
import org.duckdns.raven.ttscallresponder.dataAccess.CalendarAccess;
import org.duckdns.raven.ttscallresponder.dataAccess.SettingsManager;
import org.duckdns.raven.ttscallresponder.domain.responseTemplate.PersistentResponseTemplateList;
import org.duckdns.raven.ttscallresponder.domain.responseTemplate.ResponseTemplate;
import org.duckdns.raven.ttscallresponder.domain.userData.TtsParameterCalendar;
import org.duckdns.raven.ttscallresponder.ui.activities.ActivityModifyableList;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * This {@link Activity} provides an editor window for adding a new
 * {@link ResponseTemplate} or modifying an existing one. This activity accesses
 * the {@link ResponseTemplate}s directly via the DAO (being
 * {@link PersistentResponseTemplateList}).<br>
 * <br>
 * Extras:
 * <ul>
 * <li>Name: {@link ActivityModifyableList#INTENT_KEY_EDIT_ITEM}</li>
 * <li>Type: Integer</li>
 * <li>Meaning: The ID of the {@link ResponseTemplate} to edit</li>
 * <li>Default: -1, means "create a new template"</li>
 * </ul>
 * 
 * FIXME: License
 * 
 * @author <NAME>
 * 
 */
public class ActivityResponseTemplateEditor extends Activity {
	private static final String TAG = "ActivityPreparedResponseEditor";

	private CalendarAccess calendarAccess = null;
	private UserCalendarListAdapter userCalendarListAdapter = null;

	private EditText title = null;
	private EditText text = null;
	private LinearLayout calendarChooser = null;
	private TextView labelCalendarName = null;
	private View viewCalendarColor = null;

	private ResponseTemplate responseTemplate = null;

	/* Helper for labeling the "Choose calendar" button */

	private void labelSelectCalendarButton() {
		TtsParameterCalendar calendar = this.calendarAccess.getCalendarById(this.responseTemplate.getCalendarId());

		if (calendar == null) {
			this.labelCalendarName.setText("No calendar");
			this.viewCalendarColor.setBackgroundColor(SettingsManager.COLOR_NO_ITEM_CHOSEN);
		} else {
			this.labelCalendarName.setText(calendar.getName());
			this.viewCalendarColor.setBackgroundColor(calendar.getColor());
		}
	}

	/* Helper for building the calendar list dialog */

	private void showCalendarSelector() {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setSingleChoiceItems(this.userCalendarListAdapter, 0, new DialogInterface.OnClickListener() {
			// Retrieve the id when the calendar is selected
			@Override
			public void onClick(DialogInterface dialog, int which) {
				long calendarId = ActivityResponseTemplateEditor.this.userCalendarListAdapter.getItemId(which);
				ActivityResponseTemplateEditor.this.responseTemplate.setCalendarId(calendarId);
				Log.d(ActivityResponseTemplateEditor.TAG, "Setting calendarId to: " + calendarId);
				ActivityResponseTemplateEditor.this.labelSelectCalendarButton();
				dialog.dismiss();
			}
		})

		// Dismiss dialog on "Cancel" button
				.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int whichButton) {
						dialog.dismiss();
					}
				});
		builder.show();
	}

	/* ----- Lifecycle ----- */

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		Log.i(ActivityResponseTemplateEditor.TAG, "Enter on Create");

		super.onCreate(savedInstanceState);

		this.setContentView(R.layout.activity_response_template_editor);

		// Instanciate objects which persist onPause/onResume
		this.calendarAccess = new CalendarAccess(this);
		this.userCalendarListAdapter = new UserCalendarListAdapter(this);

		// Gain access to the UI elements
		this.title = (EditText) this.findViewById(R.id.editText_responseTemplateTitle);
		this.text = (EditText) this.findViewById(R.id.editText_responseTemplateText);<commit_msg>[Cleanup] Removed that ugly indent on showing the calendar chooser dialog.<commit_after>package org.duckdns.raven.ttscallresponder.ui.responseTemplates;

import org.duckdns.raven.ttscallresponder.R;
import org.duckdns.raven.ttscallresponder.dataAccess.CalendarAccess;
import org.duckdns.raven.ttscallresponder.dataAccess.SettingsManager;
import org.duckdns.raven.ttscallresponder.domain.responseTemplate.PersistentResponseTemplateList;
import org.duckdns.raven.ttscallresponder.domain.responseTemplate.ResponseTemplate;
import org.duckdns.raven.ttscallresponder.domain.userData.TtsParameterCalendar;
import org.duckdns.raven.ttscallresponder.ui.activities.ActivityModifyableList;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * This {@link Activity} provides an editor window for adding a new
 * {@link ResponseTemplate} or modifying an existing one. This activity accesses
 * the {@link ResponseTemplate}s directly via the DAO (being
 * {@link PersistentResponseTemplateList}).<br>
 * <br>
 * Extras:
 * <ul>
 * <li>Name: {@link ActivityModifyableList#INTENT_KEY_EDIT_ITEM}</li>
 * <li>Type: Integer</li>
 * <li>Meaning: The ID of the {@link ResponseTemplate} to edit</li>
 * <li>Default: -1, means "create a new template"</li>
 * </ul>
 * 
 * FIXME: License
 * 
 * @author <NAME>
 * 
 */
public class ActivityResponseTemplateEditor extends Activity {
	private static final String TAG = "ActivityPreparedResponseEditor";

	private CalendarAccess calendarAccess = null;
	private UserCalendarListAdapter userCalendarListAdapter = null;

	private EditText title = null;
	private EditText text = null;
	private LinearLayout calendarChooser = null;
	private TextView labelCalendarName = null;
	private View viewCalendarColor = null;

	private ResponseTemplate responseTemplate = null;

	/* Helper for labeling the "Choose calendar" button */

	private void labelSelectCalendarButton() {
		TtsParameterCalendar calendar = this.calendarAccess.getCalendarById(this.responseTemplate.getCalendarId());

		if (calendar == null) {
			this.labelCalendarName.setText("No calendar");
			this.viewCalendarColor.setBackgroundColor(SettingsManager.COLOR_NO_ITEM_CHOSEN);
		} else {
			this.labelCalendarName.setText(calendar.getName());
			this.viewCalendarColor.setBackgroundColor(calendar.getColor());
		}
	}

	/* Helper for building the calendar list dialog */

	private void showCalendarSelector() {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);

		// Retrieve the id when the calendar is selected
		builder.setSingleChoiceItems(this.userCalendarListAdapter, 0, new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				long calendarId = ActivityResponseTemplateEditor.this.userCalendarListAdapter.getItemId(which);
				ActivityResponseTemplateEditor.this.responseTemplate.setCalendarId(calendarId);
				Log.d(ActivityResponseTemplateEditor.TAG, "Setting calendarId to: " + calendarId);
				ActivityResponseTemplateEditor.this.labelSelectCalendarButton();
				dialog.dismiss();
			}
		});

		// Dismiss dialog on "Cancel" button
		builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int whichButton) {
						dialog.dismiss();
					}
				});

		// Show the dialog
		builder.show();
	}

	/* ----- Lifecycle ----- */

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		Log.i(ActivityResponseTemplateEditor.TAG, "Enter on Create");

		super.onCreate(savedInstanceState);

		this.setContentView(R.layout.activity_response_template_editor);

		// Instanciate objects which persist onPause/onResume
		this.calendarAccess = new CalendarAccess(this);
		this.userCalendarListAdapter = new UserCalendarListAdapter(this);

		// Gain access to the UI elements
		this.title = (EditText) this.findViewById(R.id.editText_responseTemplateTitle);
		this.text = (EditText) this.findViewById(R.id.editText_responseTemplateText);
{'fraction_non_alphanumeric': 0.09960437514545031, 'fraction_numerical': 0.00046544100535257155, 'mean_word_length': 5.491691842900302, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '381739', 'n_tokens_mistral': 2616, 'n_tokens_neox': 2385, 'n_words': 538}