diff --git a/src/com/fsck/k9/Preferences.java b/src/com/fsck/k9/Preferences.java index 2def52c9b..ca7abf204 100644 --- a/src/com/fsck/k9/Preferences.java +++ b/src/com/fsck/k9/Preferences.java @@ -90,7 +90,7 @@ public class Preferences { Account[] allAccounts = getAccounts(); Collection retval = new ArrayList(accounts.size()); for (Account account : allAccounts) { - if (account.isAvailable(mContext)) { + if (account.isEnabled() && account.isAvailable(mContext)) { retval.add(account); } } @@ -98,23 +98,6 @@ public class Preferences { return retval; } - /** - * Returns all enabled accounts. - * - * @return All accounts with {@link Account#isEnabled()} - */ - public List getEnabledAccounts() { - Account[] allAccounts = getAccounts(); - List enabledAccounts = new ArrayList(); - for (Account account : allAccounts) { - if (account.isEnabled()) { - enabledAccounts.add(account); - } - } - - return enabledAccounts; - } - public synchronized Account getAccount(String uuid) { if (accounts == null) { loadAccounts(); diff --git a/src/com/fsck/k9/activity/ChooseAccount.java b/src/com/fsck/k9/activity/ChooseAccount.java index 6b04f6b76..0c1c0041c 100644 --- a/src/com/fsck/k9/activity/ChooseAccount.java +++ b/src/com/fsck/k9/activity/ChooseAccount.java @@ -28,6 +28,7 @@ import java.util.List; * @see K9ExpandableListActivity */ public class ChooseAccount extends K9ExpandableListActivity { + private static final Account[] EMPTY_ACCOUNT_ARRAY = new Account[0]; /** * {@link Intent} extended data name for storing {@link Account#getUuid() @@ -50,7 +51,7 @@ public class ChooseAccount extends K9ExpandableListActivity { final ExpandableListView expandableListView = getExpandableListView(); expandableListView.setItemsCanFocus(false); - final ExpandableListAdapter adapter = createAdapter(); + final IdentitiesAdapter adapter = createAdapter(); setListAdapter(adapter); expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { @@ -77,7 +78,7 @@ public class ChooseAccount extends K9ExpandableListActivity { final Bundle extras = getIntent().getExtras(); final String uuid = extras.getString(EXTRA_ACCOUNT); if (uuid != null) { - final Account[] accounts = Preferences.getPreferences(this).getAccounts(); + final Account[] accounts = adapter.getAccounts(); final int length = accounts.length; for (int i = 0; i < length; i++) { final Account account = accounts[i]; @@ -106,7 +107,7 @@ public class ChooseAccount extends K9ExpandableListActivity { } } - private ExpandableListAdapter createAdapter() { + private IdentitiesAdapter createAdapter() { return new IdentitiesAdapter(this, getLayoutInflater()); } @@ -123,10 +124,13 @@ public class ChooseAccount extends K9ExpandableListActivity { private Context mContext; private LayoutInflater mLayoutInflater; + private Account[] mAccounts; public IdentitiesAdapter(final Context context, final LayoutInflater layoutInflater) { mContext = context; mLayoutInflater = layoutInflater; + Preferences prefs = Preferences.getPreferences(mContext); + mAccounts = prefs.getAvailableAccounts().toArray(EMPTY_ACCOUNT_ARRAY); } @Override @@ -233,7 +237,7 @@ public class ChooseAccount extends K9ExpandableListActivity { } private Account[] getAccounts() { - return Preferences.getPreferences(mContext).getAccounts(); + return mAccounts; } } } diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index 8b188c298..42708de8d 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -650,15 +650,10 @@ public class MessagingController implements Runnable { accountUuidsSet.addAll(Arrays.asList(accountUuids)); } final Preferences prefs = Preferences.getPreferences(mApplication.getApplicationContext()); - Account[] accounts = prefs.getAccounts(); List foldersToSearch = null; boolean displayableOnly = false; boolean noSpecialFolders = true; - for (final Account account : accounts) { - if (!account.isAvailable(mApplication)) { - Log.d(K9.LOG_TAG, "searchLocalMessagesSynchronous() ignores account that is not available"); - continue; - } + for (final Account account : prefs.getAvailableAccounts()) { if (accountUuids != null && !accountUuidsSet.contains(account.getUuid())) { continue; } @@ -2837,8 +2832,7 @@ public class MessagingController implements Runnable { public void sendPendingMessages(MessagingListener listener) { final Preferences prefs = Preferences.getPreferences(mApplication.getApplicationContext()); - Account[] accounts = prefs.getAccounts(); - for (Account account : accounts) { + for (Account account : prefs.getAvailableAccounts()) { sendPendingMessages(account, listener); } } @@ -3596,13 +3590,12 @@ public class MessagingController implements Runnable { Log.i(K9.LOG_TAG, "Starting mail check"); Preferences prefs = Preferences.getPreferences(context); - Account[] accounts; + Collection accounts; if (account != null) { - accounts = new Account[] { - account - }; + accounts = new ArrayList(1); + accounts.add(account); } else { - accounts = prefs.getAccounts(); + accounts = prefs.getAvailableAccounts(); } for (final Account account : accounts) { diff --git a/src/com/fsck/k9/service/MailService.java b/src/com/fsck/k9/service/MailService.java index e8e3fc1a2..df3058bb2 100644 --- a/src/com/fsck/k9/service/MailService.java +++ b/src/com/fsck/k9/service/MailService.java @@ -146,7 +146,7 @@ public class MailService extends CoreService { } else if (ACTION_RESET.equals(intent.getAction())) { if (K9.DEBUG) Log.v(K9.LOG_TAG, "***** MailService *****: reschedule"); - rescheduleAll(hasConnectivity, doBackground, startId); + rescheduleAll(hasConnectivity, doBackground, startId); } else if (ACTION_RESTART_PUSHERS.equals(intent.getAction())) { if (K9.DEBUG) Log.v(K9.LOG_TAG, "***** MailService *****: restarting pushers"); @@ -228,7 +228,7 @@ public class MailService extends CoreService { } - for (Account account : prefs.getAccounts()) { + for (Account account : prefs.getAvailableAccounts()) { if (account.getAutomaticCheckIntervalMinutes() != -1 && account.getFolderSyncMode() != FolderMode.NONE && (account.getAutomaticCheckIntervalMinutes() < shortestInterval || shortestInterval == -1)) { @@ -323,7 +323,7 @@ public class MailService extends CoreService { for (Account account : Preferences.getPreferences(MailService.this).getAccounts()) { if (K9.DEBUG) Log.i(K9.LOG_TAG, "Setting up pushers for account " + account.getDescription()); - if (account.isAvailable(getApplicationContext())) { + if (account.isEnabled() && account.isAvailable(getApplicationContext())) { pushing |= MessagingController.getInstance(getApplication()).setupPushing(account); } else { //TODO: setupPushing of unavailable accounts when they become available (sd-card inserted)