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_enable">Anschalten</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>

View file

@ -164,5 +164,9 @@
<string name="mgmt_account_disable">Temporarily disable</string>
<string name="mgmt_account_enable">Enable</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>

View file

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