From 4670585e7a474d878c823df6de1846980b5c65d3 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 4 Feb 2014 22:58:29 +0100 Subject: [PATCH] reworked edit account dialog. advanced options are now gone. tls option available instead --- gen/de/gultsch/chat/R.java | 55 ++++++------- res/layout/edit_account_dialog.xml | 86 +++----------------- src/de/gultsch/chat/ui/EditAccount.java | 80 ++++++------------ src/de/gultsch/chat/xmpp/XmppConnection.java | 3 + 4 files changed, 63 insertions(+), 161 deletions(-) diff --git a/gen/de/gultsch/chat/R.java b/gen/de/gultsch/chat/R.java index 112e0de06..555148f92 100644 --- a/gen/de/gultsch/chat/R.java +++ b/gen/de/gultsch/chat/R.java @@ -41,25 +41,22 @@ public final class R { } public static final class id { public static final int account_confirm_password_desc=0x7f0a0011; - public static final int account_delete=0x7f0a002c; - public static final int account_disable=0x7f0a002d; - public static final int account_enable=0x7f0a002e; + public static final int account_delete=0x7f0a0025; + public static final int account_disable=0x7f0a0026; + public static final int account_enable=0x7f0a0027; public static final int account_jid=0x7f0a0000; - public static final int account_list=0x7f0a0021; - public static final int account_password=0x7f0a000f; + public static final int account_list=0x7f0a001a; + public static final int account_password=0x7f0a000e; public static final int account_password_confirm2=0x7f0a0012; - public static final int account_server=0x7f0a0017; - public static final int account_show_advanced=0x7f0a0013; public static final int account_status=0x7f0a0002; - public static final int account_username=0x7f0a000d; - public static final int action_accounts=0x7f0a0029; - public static final int action_add=0x7f0a0025; - public static final int action_add_account=0x7f0a002b; - public static final int action_archive=0x7f0a0028; - public static final int action_details=0x7f0a0027; - public static final int action_security=0x7f0a0026; - public static final int action_settings=0x7f0a002a; - public static final int advanced_options=0x7f0a0014; + public static final int account_usetls=0x7f0a000f; + public static final int action_accounts=0x7f0a0022; + public static final int action_add=0x7f0a001e; + public static final int action_add_account=0x7f0a0024; + public static final int action_archive=0x7f0a0021; + public static final int action_details=0x7f0a0020; + public static final int action_security=0x7f0a001f; + public static final int action_settings=0x7f0a0023; public static final int contactList=0x7f0a0005; public static final int contact_display_name=0x7f0a0007; public static final int contact_jid=0x7f0a0008; @@ -69,24 +66,20 @@ public final class R { public static final int conversation_lastmsg=0x7f0a000b; public static final int conversation_lastupdate=0x7f0a000c; public static final int conversation_name=0x7f0a000a; - public static final int editText3=0x7f0a0019; public static final int edit_account_register_new=0x7f0a0010; - public static final int list=0x7f0a001f; - public static final int message_body=0x7f0a0023; - public static final int message_photo=0x7f0a0022; - public static final int message_time=0x7f0a0024; - public static final int messages_view=0x7f0a001d; + public static final int list=0x7f0a0018; + public static final int message_body=0x7f0a001c; + public static final int message_photo=0x7f0a001b; + public static final int message_time=0x7f0a001d; + public static final int messages_view=0x7f0a0016; public static final int new_conversation_search=0x7f0a0003; - public static final int selected_conversation=0x7f0a0020; - public static final int server_input_layout=0x7f0a0015; - public static final int slidingpanelayout=0x7f0a001e; - public static final int textSendButton=0x7f0a001c; - public static final int textView1=0x7f0a000e; + public static final int selected_conversation=0x7f0a0019; + public static final int slidingpanelayout=0x7f0a0017; + public static final int textSendButton=0x7f0a0015; + public static final int textView1=0x7f0a000d; public static final int textView2=0x7f0a0001; - public static final int textView3=0x7f0a0016; - public static final int textView4=0x7f0a0018; - public static final int textinput=0x7f0a001b; - public static final int textsend=0x7f0a001a; + public static final int textinput=0x7f0a0014; + public static final int textsend=0x7f0a0013; } public static final class layout { public static final int account_row=0x7f030000; diff --git a/res/layout/edit_account_dialog.xml b/res/layout/edit_account_dialog.xml index 2d4de8af6..2b1f95ab5 100644 --- a/res/layout/edit_account_dialog.xml +++ b/res/layout/edit_account_dialog.xml @@ -1,5 +1,4 @@ - - - - + - + + + + + - - - - - - - - - - - - - - - - - - - - diff --git a/src/de/gultsch/chat/ui/EditAccount.java b/src/de/gultsch/chat/ui/EditAccount.java index 4da89b7f8..88aa76f55 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 a72546246..56a0acb0b 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) {