reworked edit account dialog. advanced options are now gone. tls option available instead

This commit is contained in:
Daniel Gultsch 2014-02-04 22:58:29 +01:00
parent c01f2cedb6
commit 4670585e7a
4 changed files with 63 additions and 161 deletions

View File

@ -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;

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
@ -12,15 +11,7 @@
android:textSize="14sp"
android:text="Jabber ID:" />
<EditText
android:id="@+id/account_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress"
android:visibility="gone"
android:hint="Username">
</EditText>
<EditText
android:id="@+id/account_jid"
@ -51,7 +42,16 @@
android:hint="Password"
android:fontFamily="sans-serif" />
<CheckBox
android:id="@+id/account_usetls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Use Transport Layer Security (TLS)"
android:checked="true"/>
<CheckBox
android:id="@+id/edit_account_register_new"
android:layout_width="wrap_content"
@ -78,66 +78,4 @@
android:visibility="gone"
android:fontFamily="sans-serif" />
<CheckBox
android:id="@+id/account_show_advanced"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show advanced options" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/advanced_options"
android:visibility="gone">
<LinearLayout
android:id="@+id/server_input_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:paddingTop="8dp"
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Server:"
android:textSize="14sp"/>
<EditText
android:id="@+id/account_server"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Server"
android:inputType="textUri"/>
</LinearLayout>
<LinearLayout
android:layout_alignParentRight="true"
android:layout_width="144dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="@+id/server_input_layout">
<TextView
android:paddingTop="8dp"
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Port:"
android:textSize="14sp"/>
<EditText
android:id="@+id/editText3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Port"
android:inputType="number"
android:text="5222"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>

View File

@ -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();
}

View File

@ -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) {