mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 13:12:25 -05:00
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.
This commit is contained in:
parent
008891a375
commit
3c025379d4
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user