From 4670585e7a474d878c823df6de1846980b5c65d3 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 4 Feb 2014 22:58:29 +0100 Subject: reworked edit account dialog. advanced options are now gone. tls option available instead --- src/de/gultsch/chat/ui/EditAccount.java | 80 +++++++++------------------- src/de/gultsch/chat/xmpp/XmppConnection.java | 3 ++ 2 files changed, 27 insertions(+), 56 deletions(-) (limited to 'src/de/gultsch') diff --git a/src/de/gultsch/chat/ui/EditAccount.java b/src/de/gultsch/chat/ui/EditAccount.java index 4da89b7f..88aa76f5 100644 --- a/src/de/gultsch/chat/ui/EditAccount.java +++ b/src/de/gultsch/chat/ui/EditAccount.java @@ -43,35 +43,9 @@ public class EditAccount extends DialogFragment { LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.edit_account_dialog, null); final EditText jidText = (EditText) view.findViewById(R.id.account_jid); - final EditText usernameText = (EditText) view - .findViewById(R.id.account_username); - final EditText serverText = (EditText) view - .findViewById(R.id.account_server); - final TextView usernameDesc = (TextView) view - .findViewById(R.id.textView2); - final TextView confirmPwDesc = (TextView) view.findViewById(R.id.account_confirm_password_desc); - CheckBox showAdvanced = (CheckBox) view - .findViewById(R.id.account_show_advanced); - final RelativeLayout advancedOptions = (RelativeLayout) view - .findViewById(R.id.advanced_options); - showAdvanced.setOnCheckedChangeListener(new OnCheckedChangeListener() { - - @Override - public void onCheckedChanged(CompoundButton buttonView, - boolean isChecked) { - if (isChecked) { - advancedOptions.setVisibility(View.VISIBLE); - usernameDesc.setText("Username"); - usernameText.setVisibility(View.VISIBLE); - jidText.setVisibility(View.GONE); - } else { - advancedOptions.setVisibility(View.GONE); - usernameDesc.setText("Jabber ID"); - usernameText.setVisibility(View.GONE); - jidText.setVisibility(View.VISIBLE); - } - } - }); + final TextView confirmPwDesc = (TextView) view + .findViewById(R.id.account_confirm_password_desc); + CheckBox useTLS = (CheckBox) view.findViewById(R.id.account_usetls); final EditText password = (EditText) view .findViewById(R.id.account_password); @@ -87,9 +61,12 @@ public class EditAccount extends DialogFragment { registerAccount.setVisibility(View.GONE); jidText.setText(account.getJid()); password.setText(account.getPassword()); - usernameText.setText(account.getUsername()); - serverText.setText(account.getServer()); okButtonDesc = "Edit"; + if (account.isOptionSet(Account.OPTION_USETLS)) { + useTLS.setChecked(true); + } else { + useTLS.setChecked(false); + } } else { builder.setTitle("Add account"); okButtonDesc = "Add"; @@ -102,7 +79,8 @@ public class EditAccount extends DialogFragment { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { AlertDialog d = (AlertDialog) getDialog(); - Button positiveButton = (Button) d.getButton(Dialog.BUTTON_POSITIVE); + Button positiveButton = (Button) d + .getButton(Dialog.BUTTON_POSITIVE); if (isChecked) { positiveButton.setText("Register"); passwordConfirm.setVisibility(View.VISIBLE); @@ -129,41 +107,31 @@ public class EditAccount extends DialogFragment { positiveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - boolean showAdvanced = ((CheckBox) d.findViewById(R.id.account_show_advanced)).isChecked(); EditText jidEdit = (EditText) d.findViewById(R.id.account_jid); String jid = jidEdit.getText().toString(); - EditText usernameEdit = (EditText) d.findViewById(R.id.account_username); - String username = usernameEdit.getText().toString(); - EditText serverEdit = (EditText) d.findViewById(R.id.account_server); - String server = serverEdit.getText().toString(); - EditText passwordEdit = (EditText) d.findViewById(R.id.account_password); + EditText passwordEdit = (EditText) d + .findViewById(R.id.account_password); String password = passwordEdit.getText().toString(); - if (!showAdvanced) { - if (Validator.isValidJid(jid)) { - String[] parts = jid.split("@"); - username = parts[0]; - server = parts[1]; - } else { - jidEdit.setError("Invalid Jabber ID"); - return; - } + CheckBox useTLS = (CheckBox) d.findViewById(R.id.account_usetls); + String username; + String server; + if (Validator.isValidJid(jid)) { + String[] parts = jid.split("@"); + username = parts[0]; + server = parts[1]; } else { - if (username.length()==0) { - usernameEdit.setError("username is too short"); - return; - } else if (server.length()==0) { - serverEdit.setError("server is too short"); - return; - } + jidEdit.setError("Invalid Jabber ID"); + return; } - if (account!=null) { + if (account != null) { account.setPassword(password); account.setUsername(username); account.setServer(server); } else { account = new Account(username, server, password); } - if (listener!=null) { + account.setOption(Account.OPTION_USETLS, useTLS.isChecked()); + if (listener != null) { listener.onAccountEdited(account); d.dismiss(); } diff --git a/src/de/gultsch/chat/xmpp/XmppConnection.java b/src/de/gultsch/chat/xmpp/XmppConnection.java index a7254624..56a0acb0 100644 --- a/src/de/gultsch/chat/xmpp/XmppConnection.java +++ b/src/de/gultsch/chat/xmpp/XmppConnection.java @@ -86,6 +86,9 @@ public class XmppConnection implements Runnable { } } catch (UnknownHostException e) { account.setStatus(Account.STATUS_SERVER_NOT_FOUND); + if (statusListener!=null) { + statusListener.onStatusChanged(account); + } return; } catch (IOException e) { if (shouldConnect) { -- cgit v1.2.3