mirror of
https://github.com/moparisthebest/k-9
synced 2025-02-25 07:01:50 -05:00
Decouple AuthType / ConnectionSecurity from main app
This commit is contained in:
parent
9c7776d289
commit
51bc464449
@ -79,7 +79,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
private CheckBox mCompressionWifi;
|
private CheckBox mCompressionWifi;
|
||||||
private CheckBox mCompressionOther;
|
private CheckBox mCompressionOther;
|
||||||
private CheckBox mSubscribedFoldersOnly;
|
private CheckBox mSubscribedFoldersOnly;
|
||||||
private ArrayAdapter<AuthType> mAuthTypeAdapter;
|
private AuthTypeAdapter mAuthTypeAdapter;
|
||||||
private String mDefaultPort = "";
|
private String mDefaultPort = "";
|
||||||
private String mDefaultSslPort = "";
|
private String mDefaultSslPort = "";
|
||||||
private ConnectionSecurity[] mConnectionSecurityChoices = ConnectionSecurity.values();
|
private ConnectionSecurity[] mConnectionSecurityChoices = ConnectionSecurity.values();
|
||||||
@ -142,7 +142,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mAuthTypeAdapter = AuthType.getArrayAdapter(this);
|
mAuthTypeAdapter = AuthTypeAdapter.get(this);
|
||||||
mAuthTypeView.setAdapter(mAuthTypeAdapter);
|
mAuthTypeView.setAdapter(mAuthTypeAdapter);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -168,7 +168,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
// The first item is selected if settings.authenticationType is null or is not in mAuthTypeAdapter
|
// The first item is selected if settings.authenticationType is null or is not in mAuthTypeAdapter
|
||||||
mCurrentAuthTypeViewPosition = mAuthTypeAdapter.getPosition(settings.authenticationType);
|
mCurrentAuthTypeViewPosition = mAuthTypeAdapter.getAuthPosition(settings.authenticationType);
|
||||||
} else {
|
} else {
|
||||||
mCurrentAuthTypeViewPosition = savedInstanceState.getInt(STATE_AUTH_TYPE_POSITION);
|
mCurrentAuthTypeViewPosition = savedInstanceState.getInt(STATE_AUTH_TYPE_POSITION);
|
||||||
}
|
}
|
||||||
@ -257,13 +257,13 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Note that mConnectionSecurityChoices is configured above based on server type
|
// Note that mConnectionSecurityChoices is configured above based on server type
|
||||||
ArrayAdapter<ConnectionSecurity> securityTypesAdapter =
|
ConnectionSecurityAdapter securityTypesAdapter =
|
||||||
ConnectionSecurity.getArrayAdapter(this, mConnectionSecurityChoices);
|
ConnectionSecurityAdapter.get(this, mConnectionSecurityChoices);
|
||||||
mSecurityTypeView.setAdapter(securityTypesAdapter);
|
mSecurityTypeView.setAdapter(securityTypesAdapter);
|
||||||
|
|
||||||
// Select currently configured security type
|
// Select currently configured security type
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
mCurrentSecurityTypeViewPosition = securityTypesAdapter.getPosition(settings.connectionSecurity);
|
mCurrentSecurityTypeViewPosition = securityTypesAdapter.getConnectionSecurityPosition(settings.connectionSecurity);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -347,7 +347,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
|
|
||||||
updateViewFromAuthType();
|
updateViewFromAuthType();
|
||||||
validateFields();
|
validateFields();
|
||||||
AuthType selection = (AuthType) mAuthTypeView.getSelectedItem();
|
AuthType selection = getSelectedAuthType();
|
||||||
|
|
||||||
// Have the user select (or confirm) the client certificate
|
// Have the user select (or confirm) the client certificate
|
||||||
if (AuthType.EXTERNAL == selection) {
|
if (AuthType.EXTERNAL == selection) {
|
||||||
@ -395,7 +395,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
* Shows/hides password field and client certificate spinner
|
* Shows/hides password field and client certificate spinner
|
||||||
*/
|
*/
|
||||||
private void updateViewFromAuthType() {
|
private void updateViewFromAuthType() {
|
||||||
AuthType authType = (AuthType) mAuthTypeView.getSelectedItem();
|
AuthType authType = getSelectedAuthType();
|
||||||
boolean isAuthTypeExternal = (AuthType.EXTERNAL == authType);
|
boolean isAuthTypeExternal = (AuthType.EXTERNAL == authType);
|
||||||
|
|
||||||
if (isAuthTypeExternal) {
|
if (isAuthTypeExternal) {
|
||||||
@ -421,10 +421,10 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
* that this is the last thing called after an input change.)
|
* that this is the last thing called after an input change.)
|
||||||
*/
|
*/
|
||||||
private void validateFields() {
|
private void validateFields() {
|
||||||
AuthType authType = (AuthType) mAuthTypeView.getSelectedItem();
|
AuthType authType = getSelectedAuthType();
|
||||||
boolean isAuthTypeExternal = (AuthType.EXTERNAL == authType);
|
boolean isAuthTypeExternal = (AuthType.EXTERNAL == authType);
|
||||||
|
|
||||||
ConnectionSecurity connectionSecurity = (ConnectionSecurity) mSecurityTypeView.getSelectedItem();
|
ConnectionSecurity connectionSecurity = getSelectedSecurity();
|
||||||
boolean hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE);
|
boolean hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE);
|
||||||
|
|
||||||
if (isAuthTypeExternal && !hasConnectionSecurity) {
|
if (isAuthTypeExternal && !hasConnectionSecurity) {
|
||||||
@ -448,16 +448,16 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
mSecurityTypeView.setOnItemSelectedListener(null);
|
mSecurityTypeView.setOnItemSelectedListener(null);
|
||||||
mSecurityTypeView.setSelection(mCurrentSecurityTypeViewPosition, false);
|
mSecurityTypeView.setSelection(mCurrentSecurityTypeViewPosition, false);
|
||||||
mSecurityTypeView.setOnItemSelectedListener(onItemSelectedListener);
|
mSecurityTypeView.setOnItemSelectedListener(onItemSelectedListener);
|
||||||
updateAuthPlainTextFromSecurityType((ConnectionSecurity) mSecurityTypeView.getSelectedItem());
|
updateAuthPlainTextFromSecurityType(getSelectedSecurity());
|
||||||
|
|
||||||
mPortView.removeTextChangedListener(validationTextWatcher);
|
mPortView.removeTextChangedListener(validationTextWatcher);
|
||||||
mPortView.setText(mCurrentPortViewSetting);
|
mPortView.setText(mCurrentPortViewSetting);
|
||||||
mPortView.addTextChangedListener(validationTextWatcher);
|
mPortView.addTextChangedListener(validationTextWatcher);
|
||||||
|
|
||||||
authType = (AuthType) mAuthTypeView.getSelectedItem();
|
authType = getSelectedAuthType();
|
||||||
isAuthTypeExternal = (AuthType.EXTERNAL == authType);
|
isAuthTypeExternal = (AuthType.EXTERNAL == authType);
|
||||||
|
|
||||||
connectionSecurity = (ConnectionSecurity) mSecurityTypeView.getSelectedItem();
|
connectionSecurity = getSelectedSecurity();
|
||||||
hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE);
|
hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE);
|
||||||
} else {
|
} else {
|
||||||
mCurrentAuthTypeViewPosition = mAuthTypeView.getSelectedItemPosition();
|
mCurrentAuthTypeViewPosition = mAuthTypeView.getSelectedItemPosition();
|
||||||
@ -484,7 +484,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updatePortFromSecurityType() {
|
private void updatePortFromSecurityType() {
|
||||||
ConnectionSecurity securityType = (ConnectionSecurity) mSecurityTypeView.getSelectedItem();
|
ConnectionSecurity securityType = getSelectedSecurity();
|
||||||
updateAuthPlainTextFromSecurityType(securityType);
|
updateAuthPlainTextFromSecurityType(securityType);
|
||||||
|
|
||||||
// Remove listener so as not to trigger validateFields() which is called
|
// Remove listener so as not to trigger validateFields() which is called
|
||||||
@ -512,13 +512,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateAuthPlainTextFromSecurityType(ConnectionSecurity securityType) {
|
private void updateAuthPlainTextFromSecurityType(ConnectionSecurity securityType) {
|
||||||
switch (securityType) {
|
mAuthTypeAdapter.useInsecureText(securityType == ConnectionSecurity.NONE);
|
||||||
case NONE:
|
|
||||||
AuthType.PLAIN.useInsecureText(true, mAuthTypeAdapter);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
AuthType.PLAIN.useInsecureText(false, mAuthTypeAdapter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -547,7 +541,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
|
|
||||||
String password = null;
|
String password = null;
|
||||||
String clientCertificateAlias = null;
|
String clientCertificateAlias = null;
|
||||||
AuthType authType = (AuthType) mAuthTypeView.getSelectedItem();
|
AuthType authType = getSelectedAuthType();
|
||||||
if (AuthType.EXTERNAL == authType) {
|
if (AuthType.EXTERNAL == authType) {
|
||||||
clientCertificateAlias = mClientCertificateSpinner.getAlias();
|
clientCertificateAlias = mClientCertificateSpinner.getAlias();
|
||||||
} else {
|
} else {
|
||||||
@ -575,13 +569,13 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
|
|
||||||
protected void onNext() {
|
protected void onNext() {
|
||||||
try {
|
try {
|
||||||
ConnectionSecurity connectionSecurity = (ConnectionSecurity) mSecurityTypeView.getSelectedItem();
|
ConnectionSecurity connectionSecurity = getSelectedSecurity();
|
||||||
|
|
||||||
String username = mUsernameView.getText().toString();
|
String username = mUsernameView.getText().toString();
|
||||||
String password = null;
|
String password = null;
|
||||||
String clientCertificateAlias = null;
|
String clientCertificateAlias = null;
|
||||||
|
|
||||||
AuthType authType = (AuthType) mAuthTypeView.getSelectedItem();
|
AuthType authType = getSelectedAuthType();
|
||||||
if (authType == AuthType.EXTERNAL) {
|
if (authType == AuthType.EXTERNAL) {
|
||||||
clientCertificateAlias = mClientCertificateSpinner.getAlias();
|
clientCertificateAlias = mClientCertificateSpinner.getAlias();
|
||||||
} else {
|
} else {
|
||||||
@ -645,6 +639,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
toast.show();
|
toast.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calls validateFields() which enables or disables the Next button
|
* Calls validateFields() which enables or disables the Next button
|
||||||
* based on the fields' validity.
|
* based on the fields' validity.
|
||||||
@ -669,4 +664,14 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||||||
validateFields();
|
validateFields();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private AuthType getSelectedAuthType() {
|
||||||
|
AuthTypeHolder holder = (AuthTypeHolder) mAuthTypeView.getSelectedItem();
|
||||||
|
return holder.authType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ConnectionSecurity getSelectedSecurity() {
|
||||||
|
ConnectionSecurityHolder holder = (ConnectionSecurityHolder) mSecurityTypeView.getSelectedItem();
|
||||||
|
return holder.connectionSecurity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
private int mCurrentSecurityTypeViewPosition;
|
private int mCurrentSecurityTypeViewPosition;
|
||||||
private Spinner mAuthTypeView;
|
private Spinner mAuthTypeView;
|
||||||
private int mCurrentAuthTypeViewPosition;
|
private int mCurrentAuthTypeViewPosition;
|
||||||
private ArrayAdapter<AuthType> mAuthTypeAdapter;
|
private AuthTypeAdapter mAuthTypeAdapter;
|
||||||
private Button mNextButton;
|
private Button mNextButton;
|
||||||
private Account mAccount;
|
private Account mAccount;
|
||||||
private boolean mMakeDefault;
|
private boolean mMakeDefault;
|
||||||
@ -112,9 +112,9 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
|
|
||||||
mNextButton.setOnClickListener(this);
|
mNextButton.setOnClickListener(this);
|
||||||
|
|
||||||
mSecurityTypeView.setAdapter(ConnectionSecurity.getArrayAdapter(this));
|
mSecurityTypeView.setAdapter(ConnectionSecurityAdapter.get(this));
|
||||||
|
|
||||||
mAuthTypeAdapter = AuthType.getArrayAdapter(this);
|
mAuthTypeAdapter = AuthTypeAdapter.get(this);
|
||||||
mAuthTypeView.setAdapter(mAuthTypeAdapter);
|
mAuthTypeView.setAdapter(mAuthTypeAdapter);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -143,7 +143,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
// The first item is selected if settings.authenticationType is null or is not in mAuthTypeAdapter
|
// The first item is selected if settings.authenticationType is null or is not in mAuthTypeAdapter
|
||||||
mCurrentAuthTypeViewPosition = mAuthTypeAdapter.getPosition(settings.authenticationType);
|
mCurrentAuthTypeViewPosition = mAuthTypeAdapter.getAuthPosition(settings.authenticationType);
|
||||||
} else {
|
} else {
|
||||||
mCurrentAuthTypeViewPosition = savedInstanceState.getInt(STATE_AUTH_TYPE_POSITION);
|
mCurrentAuthTypeViewPosition = savedInstanceState.getInt(STATE_AUTH_TYPE_POSITION);
|
||||||
}
|
}
|
||||||
@ -229,8 +229,8 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
if (mCurrentSecurityTypeViewPosition != position) {
|
if (mCurrentSecurityTypeViewPosition != position) {
|
||||||
updatePortFromSecurityType();
|
updatePortFromSecurityType();
|
||||||
|
|
||||||
boolean isInsecure = (ConnectionSecurity.NONE == mSecurityTypeView.getSelectedItem());
|
boolean isInsecure = (ConnectionSecurity.NONE == getSelectedSecurity());
|
||||||
boolean isAuthExternal = (AuthType.EXTERNAL == mAuthTypeView.getSelectedItem());
|
boolean isAuthExternal = (AuthType.EXTERNAL == getSelectedAuthType());
|
||||||
boolean loginNotRequired = !mRequireLoginView.isChecked();
|
boolean loginNotRequired = !mRequireLoginView.isChecked();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -246,7 +246,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
if (isInsecure && isAuthExternal && loginNotRequired) {
|
if (isInsecure && isAuthExternal && loginNotRequired) {
|
||||||
OnItemSelectedListener onItemSelectedListener = mAuthTypeView.getOnItemSelectedListener();
|
OnItemSelectedListener onItemSelectedListener = mAuthTypeView.getOnItemSelectedListener();
|
||||||
mAuthTypeView.setOnItemSelectedListener(null);
|
mAuthTypeView.setOnItemSelectedListener(null);
|
||||||
mCurrentAuthTypeViewPosition = mAuthTypeAdapter.getPosition(AuthType.PLAIN);
|
mCurrentAuthTypeViewPosition = mAuthTypeAdapter.getAuthPosition(AuthType.PLAIN);
|
||||||
mAuthTypeView.setSelection(mCurrentAuthTypeViewPosition, false);
|
mAuthTypeView.setSelection(mCurrentAuthTypeViewPosition, false);
|
||||||
mAuthTypeView.setOnItemSelectedListener(onItemSelectedListener);
|
mAuthTypeView.setOnItemSelectedListener(onItemSelectedListener);
|
||||||
updateViewFromAuthType();
|
updateViewFromAuthType();
|
||||||
@ -270,7 +270,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
|
|
||||||
updateViewFromAuthType();
|
updateViewFromAuthType();
|
||||||
validateFields();
|
validateFields();
|
||||||
AuthType selection = (AuthType) mAuthTypeView.getSelectedItem();
|
AuthType selection = getSelectedAuthType();
|
||||||
|
|
||||||
// Have the user select (or confirm) the client certificate
|
// Have the user select (or confirm) the client certificate
|
||||||
if (AuthType.EXTERNAL == selection) {
|
if (AuthType.EXTERNAL == selection) {
|
||||||
@ -330,7 +330,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
* Shows/hides password field and client certificate spinner
|
* Shows/hides password field and client certificate spinner
|
||||||
*/
|
*/
|
||||||
private void updateViewFromAuthType() {
|
private void updateViewFromAuthType() {
|
||||||
AuthType authType = (AuthType) mAuthTypeView.getSelectedItem();
|
AuthType authType = getSelectedAuthType();
|
||||||
boolean isAuthTypeExternal = (AuthType.EXTERNAL == authType);
|
boolean isAuthTypeExternal = (AuthType.EXTERNAL == authType);
|
||||||
|
|
||||||
if (isAuthTypeExternal) {
|
if (isAuthTypeExternal) {
|
||||||
@ -356,10 +356,10 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
* that this is the last thing called after an input change.)
|
* that this is the last thing called after an input change.)
|
||||||
*/
|
*/
|
||||||
private void validateFields() {
|
private void validateFields() {
|
||||||
AuthType authType = (AuthType) mAuthTypeView.getSelectedItem();
|
AuthType authType = getSelectedAuthType();
|
||||||
boolean isAuthTypeExternal = (AuthType.EXTERNAL == authType);
|
boolean isAuthTypeExternal = (AuthType.EXTERNAL == authType);
|
||||||
|
|
||||||
ConnectionSecurity connectionSecurity = (ConnectionSecurity) mSecurityTypeView.getSelectedItem();
|
ConnectionSecurity connectionSecurity = getSelectedSecurity();
|
||||||
boolean hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE);
|
boolean hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE);
|
||||||
|
|
||||||
if (isAuthTypeExternal && !hasConnectionSecurity) {
|
if (isAuthTypeExternal && !hasConnectionSecurity) {
|
||||||
@ -383,16 +383,16 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
mSecurityTypeView.setOnItemSelectedListener(null);
|
mSecurityTypeView.setOnItemSelectedListener(null);
|
||||||
mSecurityTypeView.setSelection(mCurrentSecurityTypeViewPosition, false);
|
mSecurityTypeView.setSelection(mCurrentSecurityTypeViewPosition, false);
|
||||||
mSecurityTypeView.setOnItemSelectedListener(onItemSelectedListener);
|
mSecurityTypeView.setOnItemSelectedListener(onItemSelectedListener);
|
||||||
updateAuthPlainTextFromSecurityType((ConnectionSecurity) mSecurityTypeView.getSelectedItem());
|
updateAuthPlainTextFromSecurityType(getSelectedSecurity());
|
||||||
|
|
||||||
mPortView.removeTextChangedListener(validationTextWatcher);
|
mPortView.removeTextChangedListener(validationTextWatcher);
|
||||||
mPortView.setText(mCurrentPortViewSetting);
|
mPortView.setText(mCurrentPortViewSetting);
|
||||||
mPortView.addTextChangedListener(validationTextWatcher);
|
mPortView.addTextChangedListener(validationTextWatcher);
|
||||||
|
|
||||||
authType = (AuthType) mAuthTypeView.getSelectedItem();
|
authType = getSelectedAuthType();
|
||||||
isAuthTypeExternal = (AuthType.EXTERNAL == authType);
|
isAuthTypeExternal = (AuthType.EXTERNAL == authType);
|
||||||
|
|
||||||
connectionSecurity = (ConnectionSecurity) mSecurityTypeView.getSelectedItem();
|
connectionSecurity = getSelectedSecurity();
|
||||||
hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE);
|
hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE);
|
||||||
} else {
|
} else {
|
||||||
mCurrentAuthTypeViewPosition = mAuthTypeView.getSelectedItemPosition();
|
mCurrentAuthTypeViewPosition = mAuthTypeView.getSelectedItemPosition();
|
||||||
@ -421,7 +421,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updatePortFromSecurityType() {
|
private void updatePortFromSecurityType() {
|
||||||
ConnectionSecurity securityType = (ConnectionSecurity) mSecurityTypeView.getSelectedItem();
|
ConnectionSecurity securityType = getSelectedSecurity();
|
||||||
updateAuthPlainTextFromSecurityType(securityType);
|
updateAuthPlainTextFromSecurityType(securityType);
|
||||||
|
|
||||||
// Remove listener so as not to trigger validateFields() which is called
|
// Remove listener so as not to trigger validateFields() which is called
|
||||||
@ -449,13 +449,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateAuthPlainTextFromSecurityType(ConnectionSecurity securityType) {
|
private void updateAuthPlainTextFromSecurityType(ConnectionSecurity securityType) {
|
||||||
switch (securityType) {
|
mAuthTypeAdapter.useInsecureText(securityType == ConnectionSecurity.NONE);
|
||||||
case NONE:
|
|
||||||
AuthType.PLAIN.useInsecureText(true, mAuthTypeAdapter);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
AuthType.PLAIN.useInsecureText(false, mAuthTypeAdapter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -472,7 +466,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void onNext() {
|
protected void onNext() {
|
||||||
ConnectionSecurity securityType = (ConnectionSecurity) mSecurityTypeView.getSelectedItem();
|
ConnectionSecurity securityType = getSelectedSecurity();
|
||||||
String uri;
|
String uri;
|
||||||
String username = null;
|
String username = null;
|
||||||
String password = null;
|
String password = null;
|
||||||
@ -481,7 +475,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
if (mRequireLoginView.isChecked()) {
|
if (mRequireLoginView.isChecked()) {
|
||||||
username = mUsernameView.getText().toString();
|
username = mUsernameView.getText().toString();
|
||||||
|
|
||||||
authType = (AuthType) mAuthTypeView.getSelectedItem();
|
authType = getSelectedAuthType();
|
||||||
if (AuthType.EXTERNAL == authType) {
|
if (AuthType.EXTERNAL == authType) {
|
||||||
clientCertificateAlias = mClientCertificateSpinner.getAlias();
|
clientCertificateAlias = mClientCertificateSpinner.getAlias();
|
||||||
} else {
|
} else {
|
||||||
@ -511,6 +505,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
mRequireLoginSettingsView.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
mRequireLoginSettingsView.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||||
validateFields();
|
validateFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void failure(Exception use) {
|
private void failure(Exception use) {
|
||||||
Log.e(K9.LOG_TAG, "Failure", use);
|
Log.e(K9.LOG_TAG, "Failure", use);
|
||||||
String toastText = getString(R.string.account_setup_bad_uri, use.getMessage());
|
String toastText = getString(R.string.account_setup_bad_uri, use.getMessage());
|
||||||
@ -541,4 +536,14 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
validateFields();
|
validateFields();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private AuthType getSelectedAuthType() {
|
||||||
|
AuthTypeHolder holder = (AuthTypeHolder) mAuthTypeView.getSelectedItem();
|
||||||
|
return holder.authType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ConnectionSecurity getSelectedSecurity() {
|
||||||
|
ConnectionSecurityHolder holder = (ConnectionSecurityHolder) mSecurityTypeView.getSelectedItem();
|
||||||
|
return holder.connectionSecurity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
52
src/com/fsck/k9/activity/setup/AuthTypeAdapter.java
Normal file
52
src/com/fsck/k9/activity/setup/AuthTypeAdapter.java
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package com.fsck.k9.activity.setup;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
|
||||||
|
import com.fsck.k9.mail.AuthType;
|
||||||
|
|
||||||
|
|
||||||
|
class AuthTypeAdapter extends ArrayAdapter<AuthTypeHolder> {
|
||||||
|
public AuthTypeAdapter(Context context, int simple_spinner_item, AuthTypeHolder[] holders) {
|
||||||
|
super(context, simple_spinner_item, holders);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AuthTypeAdapter get(Context context) {
|
||||||
|
AuthType[] authTypes = new AuthType[]{AuthType.PLAIN, AuthType.CRAM_MD5, AuthType.EXTERNAL};
|
||||||
|
AuthTypeHolder[] holders = new AuthTypeHolder[authTypes.length];
|
||||||
|
for (int i = 0; i < authTypes.length; i++) {
|
||||||
|
holders[i] = new AuthTypeHolder(authTypes[i], context.getResources());
|
||||||
|
}
|
||||||
|
AuthTypeAdapter authTypesAdapter = new AuthTypeAdapter(context,
|
||||||
|
android.R.layout.simple_spinner_item, holders);
|
||||||
|
authTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
return authTypesAdapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to select an appropriate localized text label for the
|
||||||
|
* {@code AuthType.PLAIN} option presented to users.
|
||||||
|
*
|
||||||
|
* @param insecure
|
||||||
|
* <p>
|
||||||
|
* A value of {@code true} will use "Normal password".
|
||||||
|
* <p>
|
||||||
|
* A value of {@code false} will use
|
||||||
|
* "Password, transmitted insecurely"
|
||||||
|
*/
|
||||||
|
public void useInsecureText(boolean insecure) {
|
||||||
|
for (int i=0; i<getCount(); i++) {
|
||||||
|
getItem(i).setInsecure(insecure);
|
||||||
|
}
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAuthPosition(AuthType authenticationType) {
|
||||||
|
for (int i=0; i<getCount(); i++) {
|
||||||
|
if (getItem(i).authType == authenticationType) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
51
src/com/fsck/k9/activity/setup/AuthTypeHolder.java
Normal file
51
src/com/fsck/k9/activity/setup/AuthTypeHolder.java
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package com.fsck.k9.activity.setup;
|
||||||
|
|
||||||
|
import android.content.res.Resources;
|
||||||
|
|
||||||
|
import com.fsck.k9.R;
|
||||||
|
import com.fsck.k9.mail.AuthType;
|
||||||
|
|
||||||
|
class AuthTypeHolder {
|
||||||
|
final AuthType authType;
|
||||||
|
private final Resources resources;
|
||||||
|
private boolean insecure;
|
||||||
|
|
||||||
|
public AuthTypeHolder(AuthType authType, Resources resources) {
|
||||||
|
this.authType = authType;
|
||||||
|
this.resources = resources;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInsecure(boolean insecure) {
|
||||||
|
this.insecure = insecure;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final int resourceId = resourceId();
|
||||||
|
if (resourceId == 0) {
|
||||||
|
return authType.name();
|
||||||
|
} else {
|
||||||
|
return resources.getString(resourceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int resourceId() {
|
||||||
|
switch (authType) {
|
||||||
|
case PLAIN:
|
||||||
|
if (insecure) {
|
||||||
|
return R.string.account_setup_auth_type_insecure_password;
|
||||||
|
} else {
|
||||||
|
return R.string.account_setup_auth_type_normal_password;
|
||||||
|
}
|
||||||
|
case CRAM_MD5:
|
||||||
|
return R.string.account_setup_auth_type_encrypted_password;
|
||||||
|
case EXTERNAL:
|
||||||
|
return R.string.account_setup_auth_type_tls_client_certificate;
|
||||||
|
|
||||||
|
case AUTOMATIC:
|
||||||
|
case LOGIN:
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.fsck.k9.activity.setup;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
|
||||||
|
import com.fsck.k9.mail.ConnectionSecurity;
|
||||||
|
|
||||||
|
|
||||||
|
class ConnectionSecurityAdapter extends ArrayAdapter<ConnectionSecurityHolder> {
|
||||||
|
public ConnectionSecurityAdapter(Context context, int resource, ConnectionSecurityHolder[] securityTypes) {
|
||||||
|
super(context, resource, securityTypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConnectionSecurityAdapter get(Context context) {
|
||||||
|
return get(context, ConnectionSecurity.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConnectionSecurityAdapter get(Context context,
|
||||||
|
ConnectionSecurity[] items) {
|
||||||
|
ConnectionSecurityHolder[] holders = new ConnectionSecurityHolder[items.length];
|
||||||
|
for (int i = 0; i < items.length; i++) {
|
||||||
|
holders[i] = new ConnectionSecurityHolder(items[i], context.getResources());
|
||||||
|
}
|
||||||
|
ConnectionSecurityAdapter securityTypesAdapter = new ConnectionSecurityAdapter(context,
|
||||||
|
android.R.layout.simple_spinner_item, holders);
|
||||||
|
securityTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
return securityTypesAdapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getConnectionSecurityPosition(ConnectionSecurity connectionSecurity) {
|
||||||
|
for (int i=0; i<getCount(); i++) {
|
||||||
|
if (getItem(i).connectionSecurity == connectionSecurity) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
34
src/com/fsck/k9/activity/setup/ConnectionSecurityHolder.java
Normal file
34
src/com/fsck/k9/activity/setup/ConnectionSecurityHolder.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package com.fsck.k9.activity.setup;
|
||||||
|
|
||||||
|
import android.content.res.Resources;
|
||||||
|
|
||||||
|
import com.fsck.k9.R;
|
||||||
|
import com.fsck.k9.mail.ConnectionSecurity;
|
||||||
|
|
||||||
|
class ConnectionSecurityHolder {
|
||||||
|
final ConnectionSecurity connectionSecurity;
|
||||||
|
private final Resources resources;
|
||||||
|
|
||||||
|
public ConnectionSecurityHolder(ConnectionSecurity connectionSecurity, Resources resources) {
|
||||||
|
this.connectionSecurity = connectionSecurity;
|
||||||
|
this.resources = resources;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
final int resourceId = resourceId();
|
||||||
|
if (resourceId == 0) {
|
||||||
|
return connectionSecurity.name();
|
||||||
|
} else {
|
||||||
|
return resources.getString(resourceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int resourceId() {
|
||||||
|
switch (connectionSecurity) {
|
||||||
|
case NONE: return R.string.account_setup_incoming_security_none_label;
|
||||||
|
case STARTTLS_REQUIRED: return R.string.account_setup_incoming_security_tls_label;
|
||||||
|
case SSL_TLS_REQUIRED: return R.string.account_setup_incoming_security_ssl_label;
|
||||||
|
default: return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,5 @@
|
|||||||
package com.fsck.k9.mail;
|
package com.fsck.k9.mail;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import com.fsck.k9.K9;
|
|
||||||
import com.fsck.k9.R;
|
|
||||||
|
|
||||||
public enum AuthType {
|
public enum AuthType {
|
||||||
/*
|
/*
|
||||||
* The names of these authentication types are saved as strings when
|
* The names of these authentication types are saved as strings when
|
||||||
@ -17,23 +12,9 @@ public enum AuthType {
|
|||||||
* their original names have been retained for backward compatibility with
|
* their original names have been retained for backward compatibility with
|
||||||
* user settings.
|
* user settings.
|
||||||
*/
|
*/
|
||||||
|
PLAIN,
|
||||||
PLAIN(R.string.account_setup_auth_type_normal_password){
|
CRAM_MD5,
|
||||||
|
EXTERNAL,
|
||||||
@Override
|
|
||||||
public void useInsecureText(boolean insecure, ArrayAdapter<AuthType> authTypesAdapter) {
|
|
||||||
if (insecure) {
|
|
||||||
mResourceId = R.string.account_setup_auth_type_insecure_password;
|
|
||||||
} else {
|
|
||||||
mResourceId = R.string.account_setup_auth_type_normal_password;
|
|
||||||
}
|
|
||||||
authTypesAdapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
CRAM_MD5(R.string.account_setup_auth_type_encrypted_password),
|
|
||||||
|
|
||||||
EXTERNAL(R.string.account_setup_auth_type_tls_client_certificate),
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The following are obsolete authentication settings that were used with
|
* The following are obsolete authentication settings that were used with
|
||||||
@ -41,45 +22,6 @@ public enum AuthType {
|
|||||||
* still exist in a user's settings from a previous version or may be found
|
* still exist in a user's settings from a previous version or may be found
|
||||||
* when importing settings.
|
* when importing settings.
|
||||||
*/
|
*/
|
||||||
AUTOMATIC(0),
|
AUTOMATIC,
|
||||||
|
LOGIN
|
||||||
LOGIN(0);
|
|
||||||
|
|
||||||
static public ArrayAdapter<AuthType> getArrayAdapter(Context context) {
|
|
||||||
AuthType[] authTypes = new AuthType[]{PLAIN, CRAM_MD5, EXTERNAL};
|
|
||||||
ArrayAdapter<AuthType> authTypesAdapter = new ArrayAdapter<AuthType>(context,
|
|
||||||
android.R.layout.simple_spinner_item, authTypes);
|
|
||||||
authTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
||||||
return authTypesAdapter;
|
|
||||||
}
|
|
||||||
|
|
||||||
int mResourceId;
|
|
||||||
|
|
||||||
private AuthType(int id) {
|
|
||||||
mResourceId = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to select an appropriate localized text label for the
|
|
||||||
* {@code AuthType.PLAIN} option presented to users.
|
|
||||||
*
|
|
||||||
* @param insecure
|
|
||||||
* <p>
|
|
||||||
* A value of {@code true} will use "Normal password".
|
|
||||||
* <p>
|
|
||||||
* A value of {@code false} will use
|
|
||||||
* "Password, transmitted insecurely"
|
|
||||||
*/
|
|
||||||
public void useInsecureText(boolean insecure, ArrayAdapter<AuthType> authTypesAdapter) {
|
|
||||||
// Do nothing. Overridden in AuthType.PLAIN
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
if (mResourceId == 0) {
|
|
||||||
return name();
|
|
||||||
} else {
|
|
||||||
return K9.app.getString(mResourceId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,35 +1,7 @@
|
|||||||
package com.fsck.k9.mail;
|
package com.fsck.k9.mail;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
|
|
||||||
import com.fsck.k9.K9;
|
|
||||||
import com.fsck.k9.R;
|
|
||||||
|
|
||||||
public enum ConnectionSecurity {
|
public enum ConnectionSecurity {
|
||||||
NONE(R.string.account_setup_incoming_security_none_label),
|
NONE,
|
||||||
STARTTLS_REQUIRED(R.string.account_setup_incoming_security_tls_label),
|
STARTTLS_REQUIRED,
|
||||||
SSL_TLS_REQUIRED(R.string.account_setup_incoming_security_ssl_label);
|
SSL_TLS_REQUIRED
|
||||||
|
|
||||||
static public ArrayAdapter<ConnectionSecurity> getArrayAdapter(Context context) {
|
|
||||||
return getArrayAdapter(context, ConnectionSecurity.values());
|
|
||||||
}
|
|
||||||
|
|
||||||
static public ArrayAdapter<ConnectionSecurity> getArrayAdapter(Context context, ConnectionSecurity[] securityTypes) {
|
|
||||||
ArrayAdapter<ConnectionSecurity> securityTypesAdapter = new ArrayAdapter<ConnectionSecurity>(context,
|
|
||||||
android.R.layout.simple_spinner_item, securityTypes);
|
|
||||||
securityTypesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
||||||
return securityTypesAdapter;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final int mResourceId;
|
|
||||||
|
|
||||||
private ConnectionSecurity(int id) {
|
|
||||||
mResourceId = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return K9.app.getString(mResourceId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user