mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 13:12:25 -05:00
Use Preferences.getAvailableAccounts() where appropriate
This commit is contained in:
parent
4d6946f47c
commit
afd355f83c
@ -90,7 +90,7 @@ public class Preferences {
|
|||||||
Account[] allAccounts = getAccounts();
|
Account[] allAccounts = getAccounts();
|
||||||
Collection<Account> retval = new ArrayList<Account>(accounts.size());
|
Collection<Account> retval = new ArrayList<Account>(accounts.size());
|
||||||
for (Account account : allAccounts) {
|
for (Account account : allAccounts) {
|
||||||
if (account.isAvailable(mContext)) {
|
if (account.isEnabled() && account.isAvailable(mContext)) {
|
||||||
retval.add(account);
|
retval.add(account);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,23 +98,6 @@ public class Preferences {
|
|||||||
return retval;
|
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) {
|
public synchronized Account getAccount(String uuid) {
|
||||||
if (accounts == null) {
|
if (accounts == null) {
|
||||||
loadAccounts();
|
loadAccounts();
|
||||||
|
@ -28,6 +28,7 @@ import java.util.List;
|
|||||||
* @see K9ExpandableListActivity
|
* @see K9ExpandableListActivity
|
||||||
*/
|
*/
|
||||||
public class ChooseAccount extends 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()
|
* {@link Intent} extended data name for storing {@link Account#getUuid()
|
||||||
@ -50,7 +51,7 @@ public class ChooseAccount extends K9ExpandableListActivity {
|
|||||||
final ExpandableListView expandableListView = getExpandableListView();
|
final ExpandableListView expandableListView = getExpandableListView();
|
||||||
expandableListView.setItemsCanFocus(false);
|
expandableListView.setItemsCanFocus(false);
|
||||||
|
|
||||||
final ExpandableListAdapter adapter = createAdapter();
|
final IdentitiesAdapter adapter = createAdapter();
|
||||||
setListAdapter(adapter);
|
setListAdapter(adapter);
|
||||||
|
|
||||||
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
|
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
|
||||||
@ -77,7 +78,7 @@ public class ChooseAccount extends K9ExpandableListActivity {
|
|||||||
final Bundle extras = getIntent().getExtras();
|
final Bundle extras = getIntent().getExtras();
|
||||||
final String uuid = extras.getString(EXTRA_ACCOUNT);
|
final String uuid = extras.getString(EXTRA_ACCOUNT);
|
||||||
if (uuid != null) {
|
if (uuid != null) {
|
||||||
final Account[] accounts = Preferences.getPreferences(this).getAccounts();
|
final Account[] accounts = adapter.getAccounts();
|
||||||
final int length = accounts.length;
|
final int length = accounts.length;
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
final Account account = accounts[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());
|
return new IdentitiesAdapter(this, getLayoutInflater());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,10 +124,13 @@ public class ChooseAccount extends K9ExpandableListActivity {
|
|||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private LayoutInflater mLayoutInflater;
|
private LayoutInflater mLayoutInflater;
|
||||||
|
private Account[] mAccounts;
|
||||||
|
|
||||||
public IdentitiesAdapter(final Context context, final LayoutInflater layoutInflater) {
|
public IdentitiesAdapter(final Context context, final LayoutInflater layoutInflater) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mLayoutInflater = layoutInflater;
|
mLayoutInflater = layoutInflater;
|
||||||
|
Preferences prefs = Preferences.getPreferences(mContext);
|
||||||
|
mAccounts = prefs.getAvailableAccounts().toArray(EMPTY_ACCOUNT_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -233,7 +237,7 @@ public class ChooseAccount extends K9ExpandableListActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Account[] getAccounts() {
|
private Account[] getAccounts() {
|
||||||
return Preferences.getPreferences(mContext).getAccounts();
|
return mAccounts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -650,15 +650,10 @@ public class MessagingController implements Runnable {
|
|||||||
accountUuidsSet.addAll(Arrays.asList(accountUuids));
|
accountUuidsSet.addAll(Arrays.asList(accountUuids));
|
||||||
}
|
}
|
||||||
final Preferences prefs = Preferences.getPreferences(mApplication.getApplicationContext());
|
final Preferences prefs = Preferences.getPreferences(mApplication.getApplicationContext());
|
||||||
Account[] accounts = prefs.getAccounts();
|
|
||||||
List<LocalFolder> foldersToSearch = null;
|
List<LocalFolder> foldersToSearch = null;
|
||||||
boolean displayableOnly = false;
|
boolean displayableOnly = false;
|
||||||
boolean noSpecialFolders = true;
|
boolean noSpecialFolders = true;
|
||||||
for (final Account account : accounts) {
|
for (final Account account : prefs.getAvailableAccounts()) {
|
||||||
if (!account.isAvailable(mApplication)) {
|
|
||||||
Log.d(K9.LOG_TAG, "searchLocalMessagesSynchronous() ignores account that is not available");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (accountUuids != null && !accountUuidsSet.contains(account.getUuid())) {
|
if (accountUuids != null && !accountUuidsSet.contains(account.getUuid())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -2837,8 +2832,7 @@ public class MessagingController implements Runnable {
|
|||||||
|
|
||||||
public void sendPendingMessages(MessagingListener listener) {
|
public void sendPendingMessages(MessagingListener listener) {
|
||||||
final Preferences prefs = Preferences.getPreferences(mApplication.getApplicationContext());
|
final Preferences prefs = Preferences.getPreferences(mApplication.getApplicationContext());
|
||||||
Account[] accounts = prefs.getAccounts();
|
for (Account account : prefs.getAvailableAccounts()) {
|
||||||
for (Account account : accounts) {
|
|
||||||
sendPendingMessages(account, listener);
|
sendPendingMessages(account, listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3596,13 +3590,12 @@ public class MessagingController implements Runnable {
|
|||||||
Log.i(K9.LOG_TAG, "Starting mail check");
|
Log.i(K9.LOG_TAG, "Starting mail check");
|
||||||
Preferences prefs = Preferences.getPreferences(context);
|
Preferences prefs = Preferences.getPreferences(context);
|
||||||
|
|
||||||
Account[] accounts;
|
Collection<Account> accounts;
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
accounts = new Account[] {
|
accounts = new ArrayList<Account>(1);
|
||||||
account
|
accounts.add(account);
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
accounts = prefs.getAccounts();
|
accounts = prefs.getAvailableAccounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final Account account : accounts) {
|
for (final Account account : accounts) {
|
||||||
|
@ -228,7 +228,7 @@ public class MailService extends CoreService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (Account account : prefs.getAccounts()) {
|
for (Account account : prefs.getAvailableAccounts()) {
|
||||||
if (account.getAutomaticCheckIntervalMinutes() != -1
|
if (account.getAutomaticCheckIntervalMinutes() != -1
|
||||||
&& account.getFolderSyncMode() != FolderMode.NONE
|
&& account.getFolderSyncMode() != FolderMode.NONE
|
||||||
&& (account.getAutomaticCheckIntervalMinutes() < shortestInterval || shortestInterval == -1)) {
|
&& (account.getAutomaticCheckIntervalMinutes() < shortestInterval || shortestInterval == -1)) {
|
||||||
@ -323,7 +323,7 @@ public class MailService extends CoreService {
|
|||||||
for (Account account : Preferences.getPreferences(MailService.this).getAccounts()) {
|
for (Account account : Preferences.getPreferences(MailService.this).getAccounts()) {
|
||||||
if (K9.DEBUG)
|
if (K9.DEBUG)
|
||||||
Log.i(K9.LOG_TAG, "Setting up pushers for account " + account.getDescription());
|
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);
|
pushing |= MessagingController.getInstance(getApplication()).setupPushing(account);
|
||||||
} else {
|
} else {
|
||||||
//TODO: setupPushing of unavailable accounts when they become available (sd-card inserted)
|
//TODO: setupPushing of unavailable accounts when they become available (sd-card inserted)
|
||||||
|
Loading…
Reference in New Issue
Block a user