From 6af48bd262dbf8b29af877e7bc9c59c6ded00e5c Mon Sep 17 00:00:00 2001 From: cketti Date: Sun, 21 Oct 2012 20:04:53 +0200 Subject: [PATCH] Restore TCP port value in incoming/outgoing server settings screens Special thanks to zjw for the detailed analysis of this bug: https://github.com/k9mail/k-9/pull/193 --- .../activity/setup/AccountSetupIncoming.java | 33 ++++++++++------- .../activity/setup/AccountSetupOutgoing.java | 35 +++++++++++-------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java b/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java index d51482793..23fa80406 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java @@ -160,18 +160,6 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener authTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mAuthTypeView.setAdapter(authTypesAdapter); - /* - * Updates the port when the user changes the security type. This allows - * us to show a reasonable default which the user can change. - */ - mSecurityTypeView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - public void onItemSelected(AdapterView parent, View view, int position, long id) { - updatePortFromSecurityType(); - } - - public void onNothingSelected(AdapterView parent) { /* unused */ } - }); - /* * Calls validateFields() which enables or disables the Next button * based on the fields' validity. @@ -294,12 +282,33 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener throw new Exception("Unknown account type: " + mAccount.getStoreUri()); } + // Select currently configured security type for (int i = 0; i < CONNECTION_SECURITY_TYPES.length; i++) { if (CONNECTION_SECURITY_TYPES[i] == settings.connectionSecurity) { SpinnerOption.setSpinnerOptionValue(mSecurityTypeView, i); } } + /* + * Updates the port when the user changes the security type. This allows + * us to show a reasonable default which the user can change. + * + * Note: It's important that we set the listener *after* an initial option has been + * selected by the code above. Otherwise the listener might be called after + * onCreate() has been processed and the current port value set later in this + * method is overridden with the default port for the selected security type. + */ + mSecurityTypeView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, + long id) { + updatePortFromSecurityType(); + } + + @Override + public void onNothingSelected(AdapterView parent) { /* unused */ } + }); + mCompressionMobile.setChecked(mAccount.useCompression(Account.TYPE_MOBILE)); mCompressionWifi.setChecked(mAccount.useCompression(Account.TYPE_WIFI)); mCompressionOther.setChecked(mAccount.useCompression(Account.TYPE_OTHER)); diff --git a/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java b/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java index 5ae1f823b..15f1c9bb4 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java @@ -137,19 +137,6 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, authTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mAuthTypeView.setAdapter(authTypesAdapter); - /* - * Updates the port when the user changes the security type. This allows - * us to show a reasonable default which the user can change. - */ - mSecurityTypeView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - public void onItemSelected(AdapterView parent, View view, int position, long id) { - updatePortFromSecurityType(); - } - - public void onNothingSelected(AdapterView parent) { - } - }); - /* * Calls validateFields() which enables or disables the Next button * based on the fields' validity. @@ -223,13 +210,33 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, } } - + // Select currently configured security type for (int i = 0; i < smtpSchemes.length; i++) { if (smtpSchemes[i].equals(uri.getScheme())) { SpinnerOption.setSpinnerOptionValue(mSecurityTypeView, i); } } + /* + * Updates the port when the user changes the security type. This allows + * us to show a reasonable default which the user can change. + * + * Note: It's important that we set the listener *after* an initial option has been + * selected by the code above. Otherwise the listener might be called after + * onCreate() has been processed and the current port value set later in this + * method is overridden with the default port for the selected security type. + */ + mSecurityTypeView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, + long id) { + updatePortFromSecurityType(); + } + + @Override + public void onNothingSelected(AdapterView parent) { /* unused */ } + }); + if (uri.getHost() != null) { mServerView.setText(uri.getHost()); }