From 3c025379d404378fdc9932d60135787aaad5b102 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Sun, 13 Jul 2014 02:41:58 -0400 Subject: [PATCH] Rework validateFields() and updateViewFromAuthType() Previously, it was possible to have "Require sign-in" unchecked and a "Security = None" setting for the outgoing server and still not be able to tap "Next" because of a hidden (and irrelevant) "Authentication = Client certificate" setting. Check that the user has actually chosen a client certificate in AccountSetupOutgoing.validateFields(). Also, there's no need to clear the password and certificate fields when hiding them. The user may accidentally change settings and want to change them back without wiping out the existing settings. --- .../activity/setup/AccountSetupIncoming.java | 31 ++++++++--------- .../activity/setup/AccountSetupOutgoing.java | 33 +++++++++---------- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java b/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java index 9bf1ad334..ea2c1ec2f 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java @@ -328,13 +328,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener AuthType authType = (AuthType) mAuthTypeView.getSelectedItem(); boolean isAuthTypeExternal = AuthType.EXTERNAL.equals(authType); - // if user wants to user external authentication only, then we need to - // hide password field, since it won't be used if (isAuthTypeExternal) { - // clear password field - mPasswordView.removeTextChangedListener(validationTextWatcher); - mPasswordView.setText(""); - mPasswordView.addTextChangedListener(validationTextWatcher); // hide password fields, show client certificate fields mPasswordView.setVisibility(View.GONE); @@ -342,10 +336,6 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener mClientCertificateLabelView.setVisibility(View.VISIBLE); mClientCertificateSpinner.setVisibility(View.VISIBLE); } else { - // clear client certificate - mClientCertificateSpinner.setOnClientCertificateChangedListener(null); - mClientCertificateSpinner.setAlias(null); - mClientCertificateSpinner.setOnClientCertificateChangedListener(clientCertificateChangedListener); // show password fields, hide client certificate fields mPasswordView.setVisibility(View.VISIBLE); @@ -362,14 +352,21 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener ConnectionSecurity connectionSecurity = (ConnectionSecurity) mSecurityTypeView.getSelectedItem(); boolean hasConnectionSecurity = (!connectionSecurity.equals(ConnectionSecurity.NONE)); + boolean hasValidCertificateAlias = mClientCertificateSpinner.getAlias() != null; + boolean hasValidUserName = Utility.requiredFieldValid(mUsernameView); - mNextButton - .setEnabled(Utility.requiredFieldValid(mUsernameView) - && (Utility.requiredFieldValid(mPasswordView) - || (isAuthTypeExternal && mClientCertificateSpinner.getAlias() != null)) - && Utility.domainFieldValid(mServerView) - && Utility.requiredFieldValid(mPortView) - && (!isAuthTypeExternal || hasConnectionSecurity)); + boolean hasValidPasswordSettings = hasValidUserName + && !isAuthTypeExternal + && Utility.requiredFieldValid(mPasswordView); + + boolean hasValidExternalAuthSettings = hasValidUserName + && isAuthTypeExternal + && hasConnectionSecurity + && hasValidCertificateAlias; + + mNextButton.setEnabled(Utility.domainFieldValid(mServerView) + && Utility.requiredFieldValid(mPortView) + && (hasValidPasswordSettings || hasValidExternalAuthSettings)); Utility.setCompoundDrawablesAlpha(mNextButton, mNextButton.isEnabled() ? 255 : 128); } diff --git a/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java b/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java index f5d8b8d2c..f59abf4e9 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java @@ -228,13 +228,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, AuthType authType = (AuthType) mAuthTypeView.getSelectedItem(); boolean isAuthTypeExternal = AuthType.EXTERNAL.equals(authType); - // if user wants to user external authentication only, then we need to - // hide password field, since it won't be used if (isAuthTypeExternal) { - // clear password field - mPasswordView.removeTextChangedListener(validationTextWatcher); - mPasswordView.setText(""); - mPasswordView.addTextChangedListener(validationTextWatcher); // hide password fields, show client certificate fields mPasswordView.setVisibility(View.GONE); @@ -242,10 +236,6 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, mClientCertificateLabelView.setVisibility(View.VISIBLE); mClientCertificateSpinner.setVisibility(View.VISIBLE); } else { - // clear client certificate - mClientCertificateSpinner.setOnClientCertificateChangedListener(null); - mClientCertificateSpinner.setAlias(null); - mClientCertificateSpinner.setOnClientCertificateChangedListener(clientCertificateChangedListener); // show password fields, hide client certificate fields mPasswordView.setVisibility(View.VISIBLE); @@ -262,16 +252,23 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, ConnectionSecurity connectionSecurity = (ConnectionSecurity) mSecurityTypeView.getSelectedItem(); boolean hasConnectionSecurity = (!connectionSecurity.equals(ConnectionSecurity.NONE)); + boolean hasValidCertificateAlias = mClientCertificateSpinner.getAlias() != null; + boolean hasValidUserName = Utility.requiredFieldValid(mUsernameView); + + boolean hasValidPasswordSettings = hasValidUserName + && !isAuthTypeExternal + && Utility.requiredFieldValid(mPasswordView); + + boolean hasValidExternalAuthSettings = hasValidUserName + && isAuthTypeExternal + && hasConnectionSecurity + && hasValidCertificateAlias; mNextButton - .setEnabled(Utility.domainFieldValid(mServerView) - && Utility.requiredFieldValid(mPortView) - && (!mRequireLoginView.isChecked() - || (Utility.requiredFieldValid(mUsernameView) && Utility.requiredFieldValid(mPasswordView)) - || (Utility.requiredFieldValid(mUsernameView) && isAuthTypeExternal) - ) - && (!isAuthTypeExternal || hasConnectionSecurity) - ); + .setEnabled(Utility.domainFieldValid(mServerView) + && Utility.requiredFieldValid(mPortView) + && (!mRequireLoginView.isChecked() + || hasValidPasswordSettings || hasValidExternalAuthSettings)); Utility.setCompoundDrawablesAlpha(mNextButton, mNextButton.isEnabled() ? 255 : 128); }