cleaned up edit account dialog a little

This commit is contained in:
Daniel Gultsch 2014-05-18 11:49:44 +02:00
parent 0cdd74417f
commit 7fc7201abb
3 changed files with 21 additions and 20 deletions

View File

@ -164,5 +164,9 @@
<string name="mgmt_account_disable">Vorübergehend abschalten</string> <string name="mgmt_account_disable">Vorübergehend abschalten</string>
<string name="mgmt_account_enable">Anschalten</string> <string name="mgmt_account_enable">Anschalten</string>
<string name="attach_record_voice">Sprache aufzeichnen</string> <string name="attach_record_voice">Sprache aufzeichnen</string>
<string name="account_settings">Kontoeinstellungen</string>
<string name="save">Speichern</string>
<string name="passwords_do_not_match">Passwörter stimmen nicht überein</string>
<string name="invalid_jid">Ungültige Jabber ID</string>
</resources> </resources>

View File

@ -164,5 +164,9 @@
<string name="mgmt_account_disable">Temporarily disable</string> <string name="mgmt_account_disable">Temporarily disable</string>
<string name="mgmt_account_enable">Enable</string> <string name="mgmt_account_enable">Enable</string>
<string name="attach_record_voice">Record voice</string> <string name="attach_record_voice">Record voice</string>
<string name="account_settings">Account Settings</string>
<string name="save">Save</string>
<string name="passwords_do_not_match">Passwords do not match</string>
<string name="invalid_jid">This is not a valid Jabber ID</string>
</resources> </resources>

View File

@ -51,27 +51,19 @@ public class EditAccount extends DialogFragment {
final CheckBox registerAccount = (CheckBox) view final CheckBox registerAccount = (CheckBox) view
.findViewById(R.id.edit_account_register_new); .findViewById(R.id.edit_account_register_new);
final String okButtonDesc;
if (account != null) { if (account != null) {
jidText.setText(account.getJid()); jidText.setText(account.getJid());
password.setText(account.getPassword()); password.setText(account.getPassword());
Log.d("xmppService","mein debugger. account != null");
if (account.isOptionSet(Account.OPTION_REGISTER)) { if (account.isOptionSet(Account.OPTION_REGISTER)) {
registerAccount.setChecked(true); registerAccount.setChecked(true);
builder.setTitle(getString(R.string.register_account));
okButtonDesc = "Register";
passwordConfirm.setVisibility(View.VISIBLE); passwordConfirm.setVisibility(View.VISIBLE);
passwordConfirm.setText(account.getPassword()); passwordConfirm.setText(account.getPassword());
} else { } else {
registerAccount.setVisibility(View.GONE); registerAccount.setVisibility(View.GONE);
builder.setTitle("Edit account");
okButtonDesc = "Edit";
} }
} else {
builder.setTitle("Add account");
okButtonDesc = "Add";
} }
builder.setTitle(R.string.account_settings);
registerAccount registerAccount
.setOnCheckedChangeListener(new OnCheckedChangeListener() { .setOnCheckedChangeListener(new OnCheckedChangeListener() {
@ -79,26 +71,19 @@ public class EditAccount extends DialogFragment {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) { boolean isChecked) {
AlertDialog d = (AlertDialog) getDialog();
Button positiveButton = (Button) d
.getButton(Dialog.BUTTON_POSITIVE);
if (isChecked) { if (isChecked) {
d.setTitle(getString(R.string.register_account));
positiveButton.setText("Register");
passwordConfirm.setVisibility(View.VISIBLE); passwordConfirm.setVisibility(View.VISIBLE);
confirmPwDesc.setVisibility(View.VISIBLE); confirmPwDesc.setVisibility(View.VISIBLE);
} else { } else {
d.setTitle("Add account");
passwordConfirm.setVisibility(View.GONE); passwordConfirm.setVisibility(View.GONE);
positiveButton.setText("Add");
confirmPwDesc.setVisibility(View.GONE); confirmPwDesc.setVisibility(View.GONE);
} }
} }
}); });
builder.setView(view); builder.setView(view);
builder.setNeutralButton("Cancel", null); builder.setNeutralButton(R.string.cancel, null);
builder.setPositiveButton(okButtonDesc, null); builder.setPositiveButton(R.string.save, null);
return builder.create(); return builder.create();
} }
@ -114,7 +99,9 @@ public class EditAccount extends DialogFragment {
String jid = jidEdit.getText().toString(); String jid = jidEdit.getText().toString();
EditText passwordEdit = (EditText) d EditText passwordEdit = (EditText) d
.findViewById(R.id.account_password); .findViewById(R.id.account_password);
EditText passwordConfirmEdit = (EditText) d.findViewById(R.id.account_password_confirm2);
String password = passwordEdit.getText().toString(); String password = passwordEdit.getText().toString();
String passwordConfirm = passwordConfirmEdit.getText().toString();
CheckBox register = (CheckBox) d.findViewById(R.id.edit_account_register_new); CheckBox register = (CheckBox) d.findViewById(R.id.edit_account_register_new);
String username; String username;
String server; String server;
@ -123,9 +110,15 @@ public class EditAccount extends DialogFragment {
username = parts[0]; username = parts[0];
server = parts[1]; server = parts[1];
} else { } else {
jidEdit.setError("Invalid Jabber ID"); jidEdit.setError(getString(R.string.invalid_jid));
return; return;
} }
if (register.isChecked()) {
if (!passwordConfirm.equals(password)) {
passwordConfirmEdit.setError(getString(R.string.passwords_do_not_match));
return;
}
}
if (account != null) { if (account != null) {
account.setPassword(password); account.setPassword(password);
account.setUsername(username); account.setUsername(username);