1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Use Preferences.getAvailableAccounts() where appropriate

This commit is contained in:
cketti 2011-10-18 05:09:20 +02:00
parent 4d6946f47c
commit afd355f83c
4 changed files with 18 additions and 38 deletions

View File

@ -90,7 +90,7 @@ public class Preferences {
Account[] allAccounts = getAccounts();
Collection<Account> retval = new ArrayList<Account>(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<Account> getEnabledAccounts() {
Account[] allAccounts = getAccounts();
List<Account> enabledAccounts = new ArrayList<Account>();
for (Account account : allAccounts) {
if (account.isEnabled()) {
enabledAccounts.add(account);
}
}
return enabledAccounts;
}
public synchronized Account getAccount(String uuid) {
if (accounts == null) {
loadAccounts();

View File

@ -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;
}
}
}

View File

@ -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<LocalFolder> 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<Account> accounts;
if (account != null) {
accounts = new Account[] {
account
};
accounts = new ArrayList<Account>(1);
accounts.add(account);
} else {
accounts = prefs.getAccounts();
accounts = prefs.getAvailableAccounts();
}
for (final Account account : accounts) {

View File

@ -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)