From e447257414a5fb89b2ceec3c40599c728565f9fd Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 12 Dec 2014 06:32:24 +0100 Subject: [PATCH] Stop using K9.app where easily possible --- src/com/fsck/k9/Account.java | 4 ++-- src/com/fsck/k9/Preferences.java | 2 +- src/com/fsck/k9/activity/setup/AccountSettings.java | 2 +- src/com/fsck/k9/controller/MessagingController.java | 4 ++-- src/com/fsck/k9/mailstore/LocalStore.java | 4 ++-- src/com/fsck/k9/mailstore/StorageManager.java | 6 +++--- src/com/fsck/k9/mailstore/StoreSchemaDefinition.java | 2 +- src/com/fsck/k9/provider/AttachmentProvider.java | 6 +++--- src/com/fsck/k9/provider/MessageProvider.java | 6 +++--- src/com/fsck/k9/provider/UnreadWidgetProvider.java | 2 +- src/com/fsck/k9/service/StorageGoneReceiver.java | 4 ++-- src/com/fsck/k9/service/StorageReceiver.java | 2 +- 12 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/com/fsck/k9/Account.java b/src/com/fsck/k9/Account.java index e86ee07a1..a1c491ee6 100644 --- a/src/com/fsck/k9/Account.java +++ b/src/com/fsck/k9/Account.java @@ -265,7 +265,7 @@ public class Account implements BaseAccount, StoreConfig { protected Account(Context context) { mUuid = UUID.randomUUID().toString(); - mLocalStorageProviderId = StorageManager.getInstance(K9.app).getDefaultProviderId(); + mLocalStorageProviderId = StorageManager.getInstance(context).getDefaultProviderId(); mAutomaticCheckIntervalMinutes = -1; mIdleRefreshMinutes = 24; mPushPollOnConnect = true; @@ -1701,7 +1701,7 @@ public class Account implements BaseAccount, StoreConfig { if (localStorageProviderId == null) { return true; // defaults to internal memory } - return StorageManager.getInstance(K9.app).isReady(localStorageProviderId); + return StorageManager.getInstance(context).isReady(localStorageProviderId); } public synchronized boolean isEnabled() { diff --git a/src/com/fsck/k9/Preferences.java b/src/com/fsck/k9/Preferences.java index 03a3cd1be..7d03b668e 100644 --- a/src/com/fsck/k9/Preferences.java +++ b/src/com/fsck/k9/Preferences.java @@ -107,7 +107,7 @@ public class Preferences { } public synchronized Account newAccount() { - newAccount = new Account(K9.app); + newAccount = new Account(mContext); accounts.put(newAccount.getUuid(), newAccount); accountsInOrder.add(newAccount); diff --git a/src/com/fsck/k9/activity/setup/AccountSettings.java b/src/com/fsck/k9/activity/setup/AccountSettings.java index c6ee715de..c9127b2d7 100644 --- a/src/com/fsck/k9/activity/setup/AccountSettings.java +++ b/src/com/fsck/k9/activity/setup/AccountSettings.java @@ -470,7 +470,7 @@ public class AccountSettings extends K9PreferenceActivity { mLocalStorageProvider = (ListPreference) findPreference(PREFERENCE_LOCAL_STORAGE_PROVIDER); { final Map providers; - providers = StorageManager.getInstance(K9.app).getAvailableProviders(); + providers = StorageManager.getInstance(this).getAvailableProviders(); int i = 0; final String[] providerLabels = new String[providers.size()]; final String[] providerIds = new String[providers.size()]; diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index 189a0681e..643e41d4b 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -365,7 +365,7 @@ public class MessagingController implements Runnable { private MessagingController(Context context) { - this.context = context.getApplicationContext(); + this.context = context; mThread = new Thread(this); mThread.setName("MessagingController"); mThread.start(); @@ -376,7 +376,7 @@ public class MessagingController implements Runnable { public synchronized static MessagingController getInstance(Context context) { if (inst == null) { - inst = new MessagingController(context); + inst = new MessagingController(context.getApplicationContext()); } return inst; } diff --git a/src/com/fsck/k9/mailstore/LocalStore.java b/src/com/fsck/k9/mailstore/LocalStore.java index 349e9188d..41b97e742 100644 --- a/src/com/fsck/k9/mailstore/LocalStore.java +++ b/src/com/fsck/k9/mailstore/LocalStore.java @@ -177,7 +177,7 @@ public class LocalStore extends Store implements Serializable { * @throws UnavailableStorageException * if not {@link StorageProvider#isReady(Context)} */ - public static LocalStore getInstance(Account account, Application application) + public static LocalStore getInstance(Account account, Context context) throws MessagingException { String accountUuid = account.getUuid(); @@ -196,7 +196,7 @@ public class LocalStore extends Store implements Serializable { if (store == null) { // Creating a LocalStore instance will create or upgrade the database if // necessary. This could take some time. - store = new LocalStore(account, application); + store = new LocalStore(account, context); sLocalStores.put(accountUuid, store); } diff --git a/src/com/fsck/k9/mailstore/StorageManager.java b/src/com/fsck/k9/mailstore/StorageManager.java index 2fbc3a981..1086aff41 100644 --- a/src/com/fsck/k9/mailstore/StorageManager.java +++ b/src/com/fsck/k9/mailstore/StorageManager.java @@ -496,7 +496,7 @@ public class StorageManager { public static synchronized StorageManager getInstance(final Context context) { if (instance == null) { - instance = new StorageManager(context); + instance = new StorageManager(context.getApplicationContext()); } return instance; } @@ -661,7 +661,7 @@ public class StorageManager { sync.unmounting = false; sync.writeLock.unlock(); - K9.setServicesEnabled(K9.app); + K9.setServicesEnabled(context); } /** @@ -687,7 +687,7 @@ public class StorageManager { } // XXX we should reset mail service ONLY if there are accounts using the storage (this is not done in a regular listener because it has to be invoked afterward) - K9.setServicesEnabled(K9.app); + K9.setServicesEnabled(context); } /** diff --git a/src/com/fsck/k9/mailstore/StoreSchemaDefinition.java b/src/com/fsck/k9/mailstore/StoreSchemaDefinition.java index 4148ba2ce..39bed6b3e 100644 --- a/src/com/fsck/k9/mailstore/StoreSchemaDefinition.java +++ b/src/com/fsck/k9/mailstore/StoreSchemaDefinition.java @@ -304,7 +304,7 @@ class StoreSchemaDefinition implements LockableDatabase.SchemaDefinition { } // Check if old (pre v3.800) localized outbox folder exists - String localizedOutbox = K9.app.getString(R.string.special_mailbox_name_outbox); + String localizedOutbox = localStore.context.getString(R.string.special_mailbox_name_outbox); LocalFolder obsoleteOutbox = new LocalFolder(this.localStore, localizedOutbox); if (obsoleteOutbox.exists()) { // Get all messages from the localized outbox ... diff --git a/src/com/fsck/k9/provider/AttachmentProvider.java b/src/com/fsck/k9/provider/AttachmentProvider.java index 6516f60ef..d59de5592 100644 --- a/src/com/fsck/k9/provider/AttachmentProvider.java +++ b/src/com/fsck/k9/provider/AttachmentProvider.java @@ -215,7 +215,7 @@ public class AttachmentProvider extends ContentProvider { final AttachmentInfo attachmentInfo; try { final Account account = Preferences.getPreferences(getContext()).getAccount(dbName); - attachmentInfo = LocalStore.getInstance(account, K9.app).getAttachmentInfo(id); + attachmentInfo = LocalStore.getInstance(account, getContext()).getAttachmentInfo(id); } catch (MessagingException e) { Log.e(K9.LOG_TAG, "Unable to retrieve attachment info from local store for ID: " + id, e); return null; @@ -269,7 +269,7 @@ public class AttachmentProvider extends ContentProvider { final Account account = Preferences.getPreferences(getContext()).getAccount(dbName); try { - final LocalStore localStore = LocalStore.getInstance(account, K9.app); + final LocalStore localStore = LocalStore.getInstance(account, getContext()); AttachmentInfo attachmentInfo = localStore.getAttachmentInfo(id); if (FORMAT_VIEW.equals(format) && mimeType != null) { @@ -289,7 +289,7 @@ public class AttachmentProvider extends ContentProvider { private File getFile(String dbName, String id) throws FileNotFoundException { Account account = Preferences.getPreferences(getContext()).getAccount(dbName); - File attachmentsDir = StorageManager.getInstance(K9.app).getAttachmentDirectory(dbName, + File attachmentsDir = StorageManager.getInstance(getContext()).getAttachmentDirectory(dbName, account.getLocalStorageProviderId()); File file = new File(attachmentsDir, id); diff --git a/src/com/fsck/k9/provider/MessageProvider.java b/src/com/fsck/k9/provider/MessageProvider.java index 4508edf1b..2917eab0b 100644 --- a/src/com/fsck/k9/provider/MessageProvider.java +++ b/src/com/fsck/k9/provider/MessageProvider.java @@ -303,7 +303,7 @@ public class MessageProvider extends ContentProvider { // new code for integrated inbox, only execute this once as it will be processed afterwards via the listener final SearchAccount integratedInboxAccount = SearchAccount.createUnifiedInboxAccount(getContext()); - final MessagingController msgController = MessagingController.getInstance(K9.app); + final MessagingController msgController = MessagingController.getInstance(getContext()); msgController.searchLocalMessages(integratedInboxAccount.getRelatedSearch(), new MesssageInfoHolderRetrieverListener(queue)); @@ -1041,7 +1041,7 @@ public class MessageProvider extends ContentProvider { // get localstore parameter LocalMessage msg = null; try { - LocalFolder lf = LocalStore.getInstance(myAccount, K9.app).getFolder(folderName); + LocalFolder lf = LocalStore.getInstance(myAccount, getContext()).getFolder(folderName); int msgCount = lf.getMessageCount(); if (K9.DEBUG) { Log.d(K9.LOG_TAG, "folder msg count = " + msgCount); @@ -1053,7 +1053,7 @@ public class MessageProvider extends ContentProvider { // launch command to delete the message if ((myAccount != null) && (msg != null)) { - MessagingController controller = MessagingController.getInstance(K9.app); + MessagingController controller = MessagingController.getInstance(getContext()); controller.deleteMessages(Collections.singletonList(msg), null); } diff --git a/src/com/fsck/k9/provider/UnreadWidgetProvider.java b/src/com/fsck/k9/provider/UnreadWidgetProvider.java index aba2211c5..f46091f62 100644 --- a/src/com/fsck/k9/provider/UnreadWidgetProvider.java +++ b/src/com/fsck/k9/provider/UnreadWidgetProvider.java @@ -68,7 +68,7 @@ public class UnreadWidgetProvider extends AppWidgetProvider { if (searchAccount != null) { account = searchAccount; - MessagingController controller = MessagingController.getInstance(K9.app); + MessagingController controller = MessagingController.getInstance(context); stats = controller.getSearchAccountStatsSynchronous(searchAccount, null); clickIntent = MessageList.intentDisplaySearch(context, searchAccount.getRelatedSearch(), false, true, true); diff --git a/src/com/fsck/k9/service/StorageGoneReceiver.java b/src/com/fsck/k9/service/StorageGoneReceiver.java index 592656f9d..26be4da34 100644 --- a/src/com/fsck/k9/service/StorageGoneReceiver.java +++ b/src/com/fsck/k9/service/StorageGoneReceiver.java @@ -35,9 +35,9 @@ public class StorageGoneReceiver extends BroadcastReceiver { final String path = uri.getPath(); if (Intent.ACTION_MEDIA_EJECT.equals(action)) { - StorageManager.getInstance(K9.app).onBeforeUnmount(path); + StorageManager.getInstance(context).onBeforeUnmount(path); } else if (Intent.ACTION_MEDIA_UNMOUNTED.equals(action)) { - StorageManager.getInstance(K9.app).onAfterUnmount(path); + StorageManager.getInstance(context).onAfterUnmount(path); } } diff --git a/src/com/fsck/k9/service/StorageReceiver.java b/src/com/fsck/k9/service/StorageReceiver.java index abf36dd13..0d34fbb94 100644 --- a/src/com/fsck/k9/service/StorageReceiver.java +++ b/src/com/fsck/k9/service/StorageReceiver.java @@ -30,7 +30,7 @@ public class StorageReceiver extends BroadcastReceiver { final String path = uri.getPath(); if (Intent.ACTION_MEDIA_MOUNTED.equals(action)) { - StorageManager.getInstance(K9.app).onMount(path, + StorageManager.getInstance(context).onMount(path, intent.getBooleanExtra("read-only", true)); } }