* Secrets will be added in alphabetical order by description.
*
* All secrets are flushed to persistent storage.
*/
private void saveSecret() {
EditText description = (EditText) findViewById(R.id.list_description);
EditText username = (EditText) findViewById(R.id.list_username);
EditText password = (EditText) findViewById(R.id.list_password);
EditText email = (EditText) findViewById(R.id.list_email);
EditText notes = (EditText) findViewById(R.id.list_notes);
// If all the text views are blank, then don't do anything if we are
// supposed to be adding a secret. Also, if all the views are
// the same as the current secret, don't do anything either.
Secret secret;
String description_text = description.getText().toString();
String username_text = username.getText().toString();
String password_text = password.getText().toString();
String email_text = email.getText().toString();
String note_text = notes.getText().toString();
if (AdapterView.INVALID_POSITION == editingPosition) {
if (0 == description.getText().length() &&
0 == username.getText().length() &&
0 == password.getText().length() &&
0 == email.getText().length() &&
0 == notes.getText().length())
return;
secret = new Secret();
} else {
secret = secretsList.getSecret(editingPosition);
if (description_text.equals(secret.getDescription()) &&
username_text.equals(secret.getUsername()) &&
password_text.equals(secret.getPassword(false)) &&
email_text.equals(secret.getEmail()) &&
note_text.equals(secret.getNote()))
return;
secretsList.remove(editingPosition);
}
secret.setDescription(description.getText().toString());
secret.setUsername(username.getText().toString());
secret.setPassword(password.getText().toString());
secret.setEmail(email.getText().toString());
secret.setNote(notes.getText().toString());
editingPosition = secretsList.insert(secret);
secretsList.notifyDataSetChanged();
}