<commit_before>/**
 * 
 */
package ac.uk.cam.cl.passgroiApp;

import uk.ac.cam.cl.passgori.IPasswordStore;
import uk.ac.cam.cl.passgori.Password;
import uk.ac.cam.cl.passgori.PasswordStoreException;
import ac.uk.cam.cl.passgroiApp.PasswordStoreService.PasswordStorageBinder;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

/**
 * An activity presenting the a password entity.
 * 
 * @author <NAME>
 * 
 */
public class PassgoriPresentPasswordsActivity extends Activity {

	public class DeletePasswordThread extends Thread {

		private final String mPasswordId;

		public DeletePasswordThread(final String passwordId) {
			mPasswordId = passwordId;
		}

		@Override
		public void run() {
			try {
				if (mPasswordStore.removePassword(mPasswordId)) {
					runOnUiThread(new PasswordDeleted());
					// go back!
				} else {
					// update GUI
				}
			} catch (PasswordStoreException e) {
				// TODO Update GUI
				e.printStackTrace();
			}
		}
	}

	public class PasswordDeleted implements Runnable {

		@Override
		public void run() {
			mLoadingDialog.dismiss();
			setResult(1); // on finish ask previous activity to refresh
			finish();
			Toast.makeText(getApplicationContext(), "Password Deleted",
					Toast.LENGTH_LONG);
		}

	}

	private class GetPassword extends Thread {
		@Override
		public void run() {
			try {
				Password password = mPasswordStore.retrivePassword(getIntent()
						.getExtras().getString("passwordId"));

				if (password != null) {
					UpdatePasswordDetails updater = new UpdatePasswordDetails(
							password);
					runOnUiThread(updater);
				} else {
					// Update GUI about failure!!
				}
			} catch (PasswordStoreException e) {
				// TODO Inform GUI
				e.printStackTrace();
			}
		}
	}

	private class UpdatePasswordDetails implements Runnable {

		private final Password mPassword;

		public UpdatePasswordDetails(Password password) {
			mPassword = password;
		}

		@Override
		public void run() {
			mUsernameField.setText(mPassword.getUsername());
			mPasswordField.setText(mPassword.getPassword());
			mNotesField.setText(mPassword.getNotes());

			mUsernameField.setVisibility(View.VISIBLE);
			mPasswordField.setVisibility(View.VISIBLE);
			mNotesField.setVisibility(View.VISIBLE);

			mLoadingDialog.dismiss();
		}

	}

	/**
	 * The TextView corresponding to the password's title.
	 */<commit_msg>added error messages<commit_after>/**
 * 
 */
package ac.uk.cam.cl.passgroiApp;

import uk.ac.cam.cl.passgori.IPasswordStore;
import uk.ac.cam.cl.passgori.Password;
import uk.ac.cam.cl.passgori.PasswordStoreException;
import ac.uk.cam.cl.passgroiApp.PasswordStoreService.PasswordStorageBinder;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

/**
 * An activity presenting the a password entity.
 * 
 * @author <NAME>
 * 
 */
public class PassgoriPresentPasswordsActivity extends Activity {

	public class DeletePasswordThread extends Thread {

		private final String mPasswordId;

		public DeletePasswordThread(final String passwordId) {
			mPasswordId = <PASSWORD>;
		}

		@Override
		public void run() {
			try {
				if (mPasswordStore.removePassword(mPasswordId)) {
					runOnUiThread(new PasswordDeleted());
					// go back!
				} else {
					// update GUI
					runOnUiThread(new FailureNotification(
							"Password unaccessbile"));
				}
			} catch (PasswordStoreException e) {
				runOnUiThread(new FailureNotification(e.getMessage()));

			}
		}
	}

	public class PasswordDeleted implements Runnable {

		@Override
		public void run() {
			mLoadingDialog.dismiss();
			setResult(1); // on finish ask previous activity to refresh
			finish();
			Toast.makeText(getApplicationContext(), "Password Deleted",
					Toast.LENGTH_LONG);
		}

	}

	private class FailureNotification implements Runnable {

		private final String mMessage;

		public FailureNotification(String message) {
			mMessage = message;
		}

		@Override
		public void run() {
			Toast.makeText(getApplicationContext(), mMessage, Toast.LENGTH_LONG);
		}

	}

	private class GetPassword extends Thread {
		@Override
		public void run() {
			try {
				Password password = mPasswordStore.retrivePassword(getIntent()
						.getExtras().getString("passwordId"));

				if (password != null) {
					UpdatePasswordDetails updater = new UpdatePasswordDetails(
							password);
					runOnUiThread(updater);
				} else {
					// Update GUI about failure!!
					runOnUiThread(new FailureNotification(
							"Password Unaccessible"));
				}
			} catch (PasswordStoreException e) {
				runOnUiThread(new FailureNotification(e.getMessage()));

			}
		}
	}

	private class UpdatePasswordDetails implements Runnable {

		private final Password mPassword;

		public UpdatePasswordDetails(Password password) {
			mPassword = password;
		}

		@Override
		public void run() {
			mUsernameField.setText(mPassword.getUsername());
			mPasswordField.setText(mPassword.getPassword());
			mNotesField.setText(mPassword.getNotes());

			mUsernameField.setVisibility(View.VISIBLE);
			mPasswordField.setVisibility(View.VISIBLE);
			mNotesField.setVisibility(View.VISIBLE);

			mLoadingDialog.dismiss();
		}

	}

	/**
	 * The TextView corresponding to the password's title.
	 */
{'fraction_non_alphanumeric': 0.10299059139784947, 'fraction_numerical': 0.0003360215053763441, 'mean_word_length': 3.9941275167785233, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '2146646', 'n_tokens_mistral': 2067, 'n_tokens_neox': 1700, 'n_words': 385}