From 2e981e0c7d55a46162ad1ee896278dd16f1e8a43 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Wed, 16 Jul 2014 19:45:48 -0400 Subject: [PATCH] Don't trigger validateFields() except on user input Previously, with settings of Security=SSL and authentication=certificate, attempting to change Security=None would (of course) be blocked. So Security would remain SSL. But the authentication options would then include "Password, transmitted insecurely", whereas the option should have remained as "Normal password" (because the security remained SSL). The problem could have been fixed with a simple shuffling in updatePortFromSecurityType() so that updateAuthPlainTextFromSecurityType() was invoked before mPortView.setText(), but the logic for requiring that ordering was not plain to see. (Although no longer necessary, the shuffling was done as well.) --- .../k9/activity/setup/AccountSetupIncoming.java | 14 ++++++++++++-- .../k9/activity/setup/AccountSetupOutgoing.java | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java b/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java index 47f2b0d30..75757298b 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java @@ -308,8 +308,8 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { - // this indirectly triggers validateFields because the port text is watched updatePortFromSecurityType(); + validateFields(); } @Override @@ -365,6 +365,11 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener } } + /** + * This is invoked only when the user makes changes to a widget, not when + * widgets are changed programmatically. (The logic is simpler when you know + * that this is the last thing called after an input change.) + */ private void validateFields() { AuthType authType = (AuthType) mAuthTypeView.getSelectedItem(); boolean isAuthTypeExternal = AuthType.EXTERNAL.equals(authType); @@ -430,8 +435,13 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener private void updatePortFromSecurityType() { ConnectionSecurity securityType = (ConnectionSecurity) mSecurityTypeView.getSelectedItem(); - mPortView.setText(getDefaultPort(securityType)); updateAuthPlainTextFromSecurityType(securityType); + + // Remove listener so as not to trigger validateFields() which is called + // elsewhere as a result of user interaction. + mPortView.removeTextChangedListener(validationTextWatcher); + mPortView.setText(getDefaultPort(securityType)); + mPortView.addTextChangedListener(validationTextWatcher); } private String getDefaultPort(ConnectionSecurity securityType) { diff --git a/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java b/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java index e075813be..499ef87bc 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java @@ -208,8 +208,8 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { - // this indirectly triggers validateFields because the port text is watched updatePortFromSecurityType(); + validateFields(); } @Override @@ -266,6 +266,11 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, } } + /** + * This is invoked only when the user makes changes to a widget, not when + * widgets are changed programmatically. (The logic is simpler when you know + * that this is the last thing called after an input change.) + */ private void validateFields() { AuthType authType = (AuthType) mAuthTypeView.getSelectedItem(); boolean isAuthTypeExternal = AuthType.EXTERNAL.equals(authType); @@ -333,8 +338,13 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, private void updatePortFromSecurityType() { ConnectionSecurity securityType = (ConnectionSecurity) mSecurityTypeView.getSelectedItem(); - mPortView.setText(getDefaultSmtpPort(securityType)); updateAuthPlainTextFromSecurityType(securityType); + + // Remove listener so as not to trigger validateFields() which is called + // elsewhere as a result of user interaction. + mPortView.removeTextChangedListener(validationTextWatcher); + mPortView.setText(getDefaultSmtpPort(securityType)); + mPortView.addTextChangedListener(validationTextWatcher); } private String getDefaultSmtpPort(ConnectionSecurity securityType) {