Merge pull request #5699 from k9mail/StorageManager_cleanup
Remove unused functionality from StorageManager and StorageProvider
This commit is contained in:
commit
fc253f7fae
8 changed files with 10 additions and 81 deletions
|
@ -6,9 +6,6 @@ interface CoreResourceProvider {
|
|||
fun defaultSignature(): String
|
||||
fun defaultIdentityDescription(): String
|
||||
|
||||
fun internalStorageProviderName(): String
|
||||
fun externalStorageProviderName(): String
|
||||
|
||||
fun contactDisplayNamePrefix(): String
|
||||
fun contactUnknownSender(): String
|
||||
fun contactUnknownRecipient(): String
|
||||
|
|
|
@ -6,12 +6,11 @@ import java.util.Arrays;
|
|||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
|
||||
import com.fsck.k9.CoreResourceProvider;
|
||||
import com.fsck.k9.DI;
|
||||
|
||||
/**
|
||||
* Manager for different {@link StorageProvider} -classes that abstract access
|
||||
|
@ -56,14 +55,6 @@ public class StorageManager {
|
|||
*/
|
||||
void init(Context context);
|
||||
|
||||
/**
|
||||
* @param context
|
||||
* Never <code>null</code>.
|
||||
* @return A user displayable, localized name for this provider. Never
|
||||
* <code>null</code>.
|
||||
*/
|
||||
String getName(Context context);
|
||||
|
||||
/**
|
||||
* Some implementations may not be able to return valid File handles
|
||||
* because the device doesn't provide the denoted storage. You can check
|
||||
|
@ -120,12 +111,6 @@ public class StorageManager {
|
|||
public static class InternalStorageProvider implements StorageProvider {
|
||||
public static final String ID = "InternalStorage";
|
||||
|
||||
private final CoreResourceProvider resourceProvider;
|
||||
|
||||
public InternalStorageProvider(CoreResourceProvider resourceProvider) {
|
||||
this.resourceProvider = resourceProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return ID;
|
||||
|
@ -135,11 +120,6 @@ public class StorageManager {
|
|||
public void init(Context context) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(Context context) {
|
||||
return resourceProvider.internalStorageProviderName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported(Context context) {
|
||||
return true;
|
||||
|
@ -178,18 +158,12 @@ public class StorageManager {
|
|||
public static class ExternalStorageProvider implements StorageProvider {
|
||||
public static final String ID = "ExternalStorage";
|
||||
|
||||
private final CoreResourceProvider resourceProvider;
|
||||
|
||||
/**
|
||||
* Chosen base directory.
|
||||
*/
|
||||
private File mApplicationDirectory;
|
||||
|
||||
|
||||
public ExternalStorageProvider(CoreResourceProvider resourceProvider) {
|
||||
this.resourceProvider = resourceProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return ID;
|
||||
|
@ -200,11 +174,6 @@ public class StorageManager {
|
|||
mApplicationDirectory = context.getExternalFilesDir(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(Context context) {
|
||||
return resourceProvider.externalStorageProviderName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported(Context context) {
|
||||
return true;
|
||||
|
@ -233,8 +202,7 @@ public class StorageManager {
|
|||
public static synchronized StorageManager getInstance(final Context context) {
|
||||
if (instance == null) {
|
||||
Context applicationContext = context.getApplicationContext();
|
||||
CoreResourceProvider resourceProvider = DI.get(CoreResourceProvider.class);
|
||||
instance = new StorageManager(applicationContext, resourceProvider);
|
||||
instance = new StorageManager(applicationContext);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
@ -245,7 +213,7 @@ public class StorageManager {
|
|||
* @throws NullPointerException
|
||||
* If <tt>context</tt> is <code>null</code>.
|
||||
*/
|
||||
protected StorageManager(final Context context, CoreResourceProvider resourceProvider) throws NullPointerException {
|
||||
protected StorageManager(final Context context) throws NullPointerException {
|
||||
if (context == null) {
|
||||
throw new NullPointerException("No Context given");
|
||||
}
|
||||
|
@ -262,8 +230,9 @@ public class StorageManager {
|
|||
* be considered as the default provider !!!
|
||||
*/
|
||||
final List<StorageProvider> allProviders = Arrays.asList(
|
||||
new InternalStorageProvider(resourceProvider),
|
||||
new ExternalStorageProvider(resourceProvider));
|
||||
new InternalStorageProvider(),
|
||||
new ExternalStorageProvider()
|
||||
);
|
||||
for (final StorageProvider provider : allProviders) {
|
||||
// check for provider compatibility
|
||||
if (provider.isSupported(context)) {
|
||||
|
@ -319,17 +288,7 @@ public class StorageManager {
|
|||
return provider.getAttachmentDirectory(context, dbName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A map of available providers names, indexed by their ID. Never
|
||||
* <code>null</code>.
|
||||
* @see StorageManager
|
||||
* @see StorageProvider#isSupported(Context)
|
||||
*/
|
||||
public Map<String, String> getAvailableProviders() {
|
||||
final Map<String, String> result = new LinkedHashMap<>();
|
||||
for (final Map.Entry<String, StorageProvider> entry : mProviders.entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue().getName(context));
|
||||
}
|
||||
return result;
|
||||
public Set<String> getAvailableProviders() {
|
||||
return mProviders.keySet();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -413,8 +413,8 @@ public class AccountSettingsDescriptions {
|
|||
@Override
|
||||
public String fromString(String value) {
|
||||
StorageManager storageManager = StorageManager.getInstance(context);
|
||||
Map<String, String> providers = storageManager.getAvailableProviders();
|
||||
if (providers.containsKey(value)) {
|
||||
Set<String> providers = storageManager.getAvailableProviders();
|
||||
if (providers.contains(value)) {
|
||||
return value;
|
||||
}
|
||||
throw new RuntimeException("Validation failed");
|
||||
|
|
|
@ -7,14 +7,6 @@ class TestCoreResourceProvider : CoreResourceProvider {
|
|||
|
||||
override fun defaultIdentityDescription() = "initial identity"
|
||||
|
||||
override fun internalStorageProviderName(): String {
|
||||
throw UnsupportedOperationException("not implemented")
|
||||
}
|
||||
|
||||
override fun externalStorageProviderName(): String {
|
||||
throw UnsupportedOperationException("not implemented")
|
||||
}
|
||||
|
||||
override fun contactDisplayNamePrefix() = "To:"
|
||||
override fun contactUnknownSender() = "<Unknown Sender>"
|
||||
override fun contactUnknownRecipient() = "<Unknown Recipient>"
|
||||
|
|
|
@ -9,12 +9,6 @@ class K9CoreResourceProvider(private val context: Context) : CoreResourceProvide
|
|||
override fun defaultSignature(): String = context.getString(R.string.default_signature)
|
||||
override fun defaultIdentityDescription(): String = context.getString(R.string.default_identity_description)
|
||||
|
||||
override fun internalStorageProviderName(): String =
|
||||
context.getString(R.string.local_storage_provider_internal_label)
|
||||
|
||||
override fun externalStorageProviderName(): String =
|
||||
context.getString(R.string.local_storage_provider_external_label)
|
||||
|
||||
override fun contactDisplayNamePrefix(): String = context.getString(R.string.message_to_label)
|
||||
override fun contactUnknownSender(): String = context.getString(R.string.unknown_sender)
|
||||
override fun contactUnknownRecipient(): String = context.getString(R.string.unknown_recipient)
|
||||
|
|
|
@ -9,12 +9,6 @@ class K9CoreResourceProvider(private val context: Context) : CoreResourceProvide
|
|||
override fun defaultSignature(): String = context.getString(R.string.default_signature)
|
||||
override fun defaultIdentityDescription(): String = context.getString(R.string.default_identity_description)
|
||||
|
||||
override fun internalStorageProviderName(): String =
|
||||
context.getString(R.string.local_storage_provider_internal_label)
|
||||
|
||||
override fun externalStorageProviderName(): String =
|
||||
context.getString(R.string.local_storage_provider_external_label)
|
||||
|
||||
override fun contactDisplayNamePrefix(): String = context.getString(R.string.message_to_label)
|
||||
override fun contactUnknownSender(): String = context.getString(R.string.unknown_sender)
|
||||
override fun contactUnknownRecipient(): String = context.getString(R.string.unknown_recipient)
|
||||
|
|
|
@ -406,9 +406,6 @@ Please submit bug reports, contribute new features and ask questions at
|
|||
<string name="account_setup_incoming_wifi_label">Wi-Fi</string>
|
||||
<string name="account_setup_incoming_other_label">Other</string>
|
||||
|
||||
<string name="local_storage_provider_external_label">External storage (SD card)</string>
|
||||
<string name="local_storage_provider_internal_label">Regular internal storage</string>
|
||||
|
||||
<string name="account_setup_expunge_policy_label">Erase deleted messages on server</string>
|
||||
<string name="account_setup_expunge_policy_immediately">Immediately</string>
|
||||
<string name="account_setup_expunge_policy_on_poll">When polling</string>
|
||||
|
|
|
@ -7,10 +7,6 @@ class TestCoreResourceProvider : CoreResourceProvider {
|
|||
|
||||
override fun defaultIdentityDescription() = throw UnsupportedOperationException("not implemented")
|
||||
|
||||
override fun internalStorageProviderName() = throw UnsupportedOperationException("not implemented")
|
||||
|
||||
override fun externalStorageProviderName() = throw UnsupportedOperationException("not implemented")
|
||||
|
||||
override fun contactDisplayNamePrefix() = throw UnsupportedOperationException("not implemented")
|
||||
override fun contactUnknownSender() = throw UnsupportedOperationException("not implemented")
|
||||
override fun contactUnknownRecipient() = throw UnsupportedOperationException("not implemented")
|
||||
|
|
Loading…
Reference in a new issue