Remove RemoteStoreManager
This commit is contained in:
parent
5fe780a828
commit
e4b6175c45
11 changed files with 81 additions and 74 deletions
|
@ -2,7 +2,11 @@ package com.fsck.k9.backend
|
|||
|
||||
import com.fsck.k9.Account
|
||||
import com.fsck.k9.backend.api.Backend
|
||||
import com.fsck.k9.mail.ServerSettings
|
||||
|
||||
interface BackendFactory {
|
||||
fun createBackend(account: Account): Backend
|
||||
|
||||
fun decodeStoreUri(storeUri: String): ServerSettings
|
||||
fun createStoreUri(serverSettings: ServerSettings): String
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.fsck.k9.backend
|
|||
|
||||
import com.fsck.k9.Account
|
||||
import com.fsck.k9.backend.api.Backend
|
||||
import com.fsck.k9.mail.ServerSettings
|
||||
import java.util.Locale
|
||||
|
||||
class BackendManager(private val backendFactories: Map<String, BackendFactory>) {
|
||||
private val backendCache = mutableMapOf<String, Backend>()
|
||||
|
@ -29,4 +31,25 @@ class BackendManager(private val backendFactories: Map<String, BackendFactory>)
|
|||
|
||||
throw IllegalArgumentException("Unsupported account type")
|
||||
}
|
||||
|
||||
fun decodeStoreUri(storeUri: String): ServerSettings {
|
||||
backendFactories.forEach { (storeUriPrefix, backendFactory) ->
|
||||
if (storeUri.startsWith(storeUriPrefix)) {
|
||||
return backendFactory.decodeStoreUri(storeUri)
|
||||
}
|
||||
}
|
||||
|
||||
throw IllegalArgumentException("Unsupported storeUri type")
|
||||
}
|
||||
|
||||
fun createStoreUri(serverSettings: ServerSettings): String {
|
||||
backendFactories.forEach { (storeUriPrefix, backendFactory) ->
|
||||
val type = serverSettings.type.name.toLowerCase(Locale.ROOT)
|
||||
if (type.startsWith(storeUriPrefix)) {
|
||||
return backendFactory.createStoreUri(serverSettings)
|
||||
}
|
||||
}
|
||||
|
||||
throw IllegalArgumentException("Unsupported storeUri type")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.fsck.k9.Account
|
|||
import com.fsck.k9.Preferences
|
||||
import com.fsck.k9.backend.api.Backend
|
||||
import com.fsck.k9.backend.imap.ImapBackend
|
||||
import com.fsck.k9.mail.ServerSettings
|
||||
import com.fsck.k9.mail.oauth.OAuth2TokenProvider
|
||||
import com.fsck.k9.mail.power.PowerManager
|
||||
import com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory
|
||||
|
@ -41,4 +42,12 @@ class ImapBackendFactory(
|
|||
val oauth2TokenProvider: OAuth2TokenProvider? = null
|
||||
return SmtpTransport(account, DefaultTrustedSocketFactory(context), oauth2TokenProvider)
|
||||
}
|
||||
|
||||
override fun decodeStoreUri(storeUri: String): ServerSettings {
|
||||
return ImapStore.decodeUri(storeUri)
|
||||
}
|
||||
|
||||
override fun createStoreUri(serverSettings: ServerSettings): String {
|
||||
return ImapStore.createUri(serverSettings)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.fsck.k9.Account
|
|||
import com.fsck.k9.Preferences
|
||||
import com.fsck.k9.backend.api.Backend
|
||||
import com.fsck.k9.backend.pop3.Pop3Backend
|
||||
import com.fsck.k9.mail.ServerSettings
|
||||
import com.fsck.k9.mail.oauth.OAuth2TokenProvider
|
||||
import com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory
|
||||
import com.fsck.k9.mail.store.pop3.Pop3Store
|
||||
|
@ -29,4 +30,12 @@ class Pop3BackendFactory(private val context: Context, private val preferences:
|
|||
val oauth2TokenProvider: OAuth2TokenProvider? = null
|
||||
return SmtpTransport(account, DefaultTrustedSocketFactory(context), oauth2TokenProvider)
|
||||
}
|
||||
|
||||
override fun decodeStoreUri(storeUri: String): ServerSettings {
|
||||
return Pop3Store.decodeUri(storeUri)
|
||||
}
|
||||
|
||||
override fun createStoreUri(serverSettings: ServerSettings): String {
|
||||
return Pop3Store.createUri(serverSettings)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.fsck.k9.Account
|
|||
import com.fsck.k9.Preferences
|
||||
import com.fsck.k9.backend.api.Backend
|
||||
import com.fsck.k9.backend.webdav.WebDavBackend
|
||||
import com.fsck.k9.mail.ServerSettings
|
||||
import com.fsck.k9.mail.store.webdav.WebDavStore
|
||||
import com.fsck.k9.mail.transport.WebDavTransport
|
||||
import com.fsck.k9.mailstore.K9BackendStorage
|
||||
|
@ -21,4 +22,12 @@ class WebDavBackendFactory(private val preferences: Preferences) : BackendFactor
|
|||
private fun createWebDavStore(account: Account): WebDavStore {
|
||||
return WebDavStore(account)
|
||||
}
|
||||
|
||||
override fun decodeStoreUri(storeUri: String): ServerSettings {
|
||||
return WebDavStore.decodeUri(storeUri)
|
||||
}
|
||||
|
||||
override fun createStoreUri(serverSettings: ServerSettings): String {
|
||||
return WebDavStore.createUri(serverSettings)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
package com.fsck.k9.mail.store;
|
||||
|
||||
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.ServerSettings.Type;
|
||||
import com.fsck.k9.mail.store.imap.ImapStore;
|
||||
import com.fsck.k9.mail.store.pop3.Pop3Store;
|
||||
import com.fsck.k9.mail.store.webdav.WebDavStore;
|
||||
|
||||
|
||||
public abstract class RemoteStoreManager {
|
||||
/**
|
||||
* Decodes the contents of store-specific URIs and puts them into a {@link ServerSettings}
|
||||
* object.
|
||||
*
|
||||
* @param uri
|
||||
* the store-specific URI to decode
|
||||
*
|
||||
* @return A {@link ServerSettings} object holding the settings contained in the URI.
|
||||
*
|
||||
* @see ImapStore#decodeUri(String)
|
||||
* @see Pop3Store#decodeUri(String)
|
||||
* @see WebDavStore#decodeUri(String)
|
||||
*/
|
||||
public static ServerSettings decodeStoreUri(String uri) {
|
||||
if (uri.startsWith("imap")) {
|
||||
return ImapStore.decodeUri(uri);
|
||||
} else if (uri.startsWith("pop3")) {
|
||||
return Pop3Store.decodeUri(uri);
|
||||
} else if (uri.startsWith("webdav")) {
|
||||
return WebDavStore.decodeUri(uri);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not a valid store URI");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a store URI from the information supplied in the {@link ServerSettings} object.
|
||||
*
|
||||
* @param server
|
||||
* The {@link ServerSettings} object that holds the server settings.
|
||||
*
|
||||
* @return A store URI that holds the same information as the {@code server} parameter.
|
||||
*
|
||||
* @see ImapStore#createUri(ServerSettings)
|
||||
* @see Pop3Store#createUri(ServerSettings)
|
||||
* @see WebDavStore#createUri(ServerSettings)
|
||||
*/
|
||||
public static String createStoreUri(ServerSettings server) {
|
||||
if (Type.IMAP == server.type) {
|
||||
return ImapStore.createUri(server);
|
||||
} else if (Type.POP3 == server.type) {
|
||||
return Pop3Store.createUri(server);
|
||||
} else if (Type.WebDAV == server.type) {
|
||||
return WebDavStore.createUri(server);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not a valid store URI");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,11 +23,12 @@ import android.os.Environment;
|
|||
import android.util.Xml;
|
||||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.DI;
|
||||
import com.fsck.k9.Preferences;
|
||||
import com.fsck.k9.backend.BackendManager;
|
||||
import com.fsck.k9.helper.FileHelper;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.TransportUris;
|
||||
import com.fsck.k9.mail.store.RemoteStoreManager;
|
||||
import com.fsck.k9.preferences.Settings.InvalidSettingValueException;
|
||||
import com.fsck.k9.preferences.Settings.SettingsDescription;
|
||||
import org.xmlpull.v1.XmlSerializer;
|
||||
|
@ -234,7 +235,8 @@ public class SettingsExporter {
|
|||
}
|
||||
|
||||
// Write incoming server settings
|
||||
ServerSettings incoming = RemoteStoreManager.decodeStoreUri(account.getStoreUri());
|
||||
BackendManager backendManager = DI.get(BackendManager.class);
|
||||
ServerSettings incoming = backendManager.decodeStoreUri(account.getStoreUri());
|
||||
serializer.startTag(null, INCOMING_SERVER_ELEMENT);
|
||||
serializer.attribute(null, TYPE_ATTRIBUTE, incoming.type.name());
|
||||
|
||||
|
|
|
@ -19,15 +19,16 @@ import android.text.TextUtils;
|
|||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.Core;
|
||||
import com.fsck.k9.DI;
|
||||
import com.fsck.k9.Identity;
|
||||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.Preferences;
|
||||
import com.fsck.k9.backend.BackendManager;
|
||||
import com.fsck.k9.mail.AuthType;
|
||||
import com.fsck.k9.mail.ConnectionSecurity;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.TransportUris;
|
||||
import com.fsck.k9.mail.filter.Base64;
|
||||
import com.fsck.k9.mail.store.RemoteStoreManager;
|
||||
import com.fsck.k9.preferences.Settings.InvalidSettingValueException;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
@ -347,7 +348,8 @@ public class SettingsImporter {
|
|||
|
||||
// Write incoming server settings (storeUri)
|
||||
ServerSettings incoming = new ImportedServerSettings(account.incoming);
|
||||
String storeUri = RemoteStoreManager.createStoreUri(incoming);
|
||||
BackendManager backendManager = DI.get(BackendManager.class);
|
||||
String storeUri = backendManager.createStoreUri(incoming);
|
||||
putString(editor, accountKeyPrefix + Account.STORE_URI_KEY, Base64.encode(storeUri));
|
||||
|
||||
// Mark account as disabled if the AuthType isn't EXTERNAL and the
|
||||
|
|
|
@ -66,6 +66,7 @@ import com.fsck.k9.DI;
|
|||
import com.fsck.k9.FontSizes;
|
||||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.Preferences;
|
||||
import com.fsck.k9.backend.BackendManager;
|
||||
import com.fsck.k9.ui.R;
|
||||
import com.fsck.k9.activity.compose.MessageActions;
|
||||
import com.fsck.k9.activity.misc.ExtendedAsyncTask;
|
||||
|
@ -77,7 +78,6 @@ import com.fsck.k9.ui.helper.SizeFormatter;
|
|||
import com.fsck.k9.mail.AuthType;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.TransportUris;
|
||||
import com.fsck.k9.mail.store.RemoteStoreManager;
|
||||
import com.fsck.k9.mailstore.StorageManager;
|
||||
import com.fsck.k9.preferences.SettingsExporter;
|
||||
import com.fsck.k9.preferences.SettingsImportExportException;
|
||||
|
@ -687,6 +687,8 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
|||
* Ask the user for the incoming/outgoing server passwords.
|
||||
*/
|
||||
private static class PasswordPromptDialog implements NonConfigurationInstance, TextWatcher {
|
||||
private final BackendManager backendManager = DI.get(BackendManager.class);
|
||||
|
||||
private AlertDialog mDialog;
|
||||
private EditText mIncomingPasswordView;
|
||||
private EditText mOutgoingPasswordView;
|
||||
|
@ -747,7 +749,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
|||
}
|
||||
|
||||
private void show(final Accounts activity, boolean restore) {
|
||||
ServerSettings incoming = RemoteStoreManager.decodeStoreUri(mAccount.getStoreUri());
|
||||
ServerSettings incoming = backendManager.decodeStoreUri(mAccount.getStoreUri());
|
||||
ServerSettings outgoing = TransportUris.decodeTransportUri(mAccount.getTransportUri());
|
||||
|
||||
/*
|
||||
|
@ -933,6 +935,8 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
|||
* Set the incoming/outgoing server password in the background.
|
||||
*/
|
||||
private static class SetPasswordsAsyncTask extends ExtendedAsyncTask<Void, Void, Void> {
|
||||
private final BackendManager backendManager = DI.get(BackendManager.class);
|
||||
|
||||
private Account mAccount;
|
||||
private String mIncomingPassword;
|
||||
private String mOutgoingPassword;
|
||||
|
@ -965,9 +969,9 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
|||
if (mIncomingPassword != null) {
|
||||
// Set incoming server password
|
||||
String storeUri = mAccount.getStoreUri();
|
||||
ServerSettings incoming = RemoteStoreManager.decodeStoreUri(storeUri);
|
||||
ServerSettings incoming = backendManager.decodeStoreUri(storeUri);
|
||||
ServerSettings newIncoming = incoming.newPassword(mIncomingPassword);
|
||||
String newStoreUri = RemoteStoreManager.createStoreUri(newIncoming);
|
||||
String newStoreUri = backendManager.createStoreUri(newIncoming);
|
||||
mAccount.setStoreUri(newStoreUri);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,8 +26,10 @@ import android.widget.EditText;
|
|||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.Core;
|
||||
import com.fsck.k9.DI;
|
||||
import com.fsck.k9.EmailAddressValidator;
|
||||
import com.fsck.k9.Preferences;
|
||||
import com.fsck.k9.backend.BackendManager;
|
||||
import com.fsck.k9.ui.R;
|
||||
import com.fsck.k9.account.AccountCreator;
|
||||
import com.fsck.k9.activity.K9Activity;
|
||||
|
@ -38,7 +40,6 @@ import com.fsck.k9.mail.AuthType;
|
|||
import com.fsck.k9.mail.ConnectionSecurity;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.TransportUris;
|
||||
import com.fsck.k9.mail.store.RemoteStoreManager;
|
||||
import com.fsck.k9.view.ClientCertificateSpinner;
|
||||
import com.fsck.k9.view.ClientCertificateSpinner.OnClientCertificateChangedListener;
|
||||
import timber.log.Timber;
|
||||
|
@ -59,6 +60,9 @@ public class AccountSetupBasics extends K9Activity
|
|||
private final static String STATE_KEY_CHECKED_INCOMING =
|
||||
"com.fsck.k9.AccountSetupBasics.checkedIncoming";
|
||||
|
||||
|
||||
private final BackendManager backendManager = DI.get(BackendManager.class);
|
||||
|
||||
private EditText mEmailView;
|
||||
private EditText mPasswordView;
|
||||
private CheckBox mClientCertificateCheckBox;
|
||||
|
@ -320,7 +324,7 @@ public class AccountSetupBasics extends K9Activity
|
|||
mAccount.setStoreUri(incomingUri.toString());
|
||||
mAccount.setTransportUri(outgoingUri.toString());
|
||||
|
||||
ServerSettings incomingSettings = RemoteStoreManager.decodeStoreUri(incomingUri.toString());
|
||||
ServerSettings incomingSettings = backendManager.decodeStoreUri(incomingUri.toString());
|
||||
mAccount.setDeletePolicy(AccountCreator.getDefaultDeletePolicy(incomingSettings.type));
|
||||
|
||||
// Check incoming here. Then check outgoing in onActivityResult()
|
||||
|
@ -409,7 +413,7 @@ public class AccountSetupBasics extends K9Activity
|
|||
ConnectionSecurity.SSL_TLS_REQUIRED, authenticationType, email, password, clientCertificateAlias);
|
||||
ServerSettings transportServer = new ServerSettings(ServerSettings.Type.SMTP, "mail." + domain, -1,
|
||||
ConnectionSecurity.SSL_TLS_REQUIRED, authenticationType, email, password, clientCertificateAlias);
|
||||
String storeUri = RemoteStoreManager.createStoreUri(storeServer);
|
||||
String storeUri = backendManager.createStoreUri(storeServer);
|
||||
String transportUri = TransportUris.createTransportUri(transportServer);
|
||||
mAccount.setStoreUri(storeUri);
|
||||
mAccount.setTransportUri(transportUri);
|
||||
|
|
|
@ -31,6 +31,7 @@ import com.fsck.k9.Account;
|
|||
import com.fsck.k9.Account.FolderMode;
|
||||
import com.fsck.k9.DI;
|
||||
import com.fsck.k9.Preferences;
|
||||
import com.fsck.k9.backend.BackendManager;
|
||||
import com.fsck.k9.ui.R;
|
||||
import com.fsck.k9.account.AccountCreator;
|
||||
import com.fsck.k9.activity.K9Activity;
|
||||
|
@ -44,7 +45,6 @@ import com.fsck.k9.mail.NetworkType;
|
|||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.ServerSettings.Type;
|
||||
import com.fsck.k9.mail.TransportUris;
|
||||
import com.fsck.k9.mail.store.RemoteStoreManager;
|
||||
import com.fsck.k9.mail.store.imap.ImapStoreSettings;
|
||||
import com.fsck.k9.mail.store.webdav.WebDavStoreSettings;
|
||||
import com.fsck.k9.service.MailService;
|
||||
|
@ -59,6 +59,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||
private static final String STATE_AUTH_TYPE_POSITION = "authTypePosition";
|
||||
|
||||
private final MessagingController messagingController = DI.get(MessagingController.class);
|
||||
private final BackendManager backendManager = DI.get(BackendManager.class);
|
||||
|
||||
private Type mStoreType;
|
||||
private EditText mUsernameView;
|
||||
|
@ -178,7 +179,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||
boolean editSettings = Intent.ACTION_EDIT.equals(getIntent().getAction());
|
||||
|
||||
try {
|
||||
ServerSettings settings = RemoteStoreManager.decodeStoreUri(mAccount.getStoreUri());
|
||||
ServerSettings settings = backendManager.decodeStoreUri(mAccount.getStoreUri());
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
// The first item is selected if settings.authenticationType is null or is not in mAuthTypeAdapter
|
||||
|
@ -591,7 +592,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
|||
ServerSettings settings = new ServerSettings(mStoreType, host, port,
|
||||
connectionSecurity, authType, username, password, clientCertificateAlias, extra);
|
||||
|
||||
mAccount.setStoreUri(RemoteStoreManager.createStoreUri(settings));
|
||||
mAccount.setStoreUri(backendManager.createStoreUri(settings));
|
||||
|
||||
mAccount.setCompression(NetworkType.MOBILE, mCompressionMobile.isChecked());
|
||||
mAccount.setCompression(NetworkType.WIFI, mCompressionWifi.isChecked());
|
||||
|
|
Loading…
Reference in a new issue