Correctly initialize mSingleAccountMode

This fixes a NullPointerException when trying to open account settings
from the Unified Inbox (when there's only one account).
This commit is contained in:
cketti 2013-05-27 16:59:07 +02:00
parent ed354eea32
commit 34812fa5b8

View file

@ -439,20 +439,28 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
} }
} }
Preferences prefs = Preferences.getPreferences(getApplicationContext());
String[] accountUuids = mSearch.getAccountUuids(); String[] accountUuids = mSearch.getAccountUuids();
mSingleAccountMode = (accountUuids.length == 1 && !mSearch.searchAllAccounts()); if (mSearch.searchAllAccounts()) {
Account[] accounts = prefs.getAccounts();
mSingleAccountMode = (accounts.length == 1);
if (mSingleAccountMode) {
mAccount = accounts[0];
}
} else {
mSingleAccountMode = (accountUuids.length == 1);
if (mSingleAccountMode) {
mAccount = prefs.getAccount(accountUuids[0]);
}
}
mSingleFolderMode = mSingleAccountMode && (mSearch.getFolderNames().size() == 1); mSingleFolderMode = mSingleAccountMode && (mSearch.getFolderNames().size() == 1);
if (mSingleAccountMode) { if (mSingleAccountMode && (mAccount == null || !mAccount.isAvailable(this))) {
Preferences prefs = Preferences.getPreferences(getApplicationContext());
mAccount = prefs.getAccount(accountUuids[0]);
if (mAccount != null && !mAccount.isAvailable(this)) {
Log.i(K9.LOG_TAG, "not opening MessageList of unavailable account"); Log.i(K9.LOG_TAG, "not opening MessageList of unavailable account");
onAccountUnavailable(); onAccountUnavailable();
return; return;
} }
}
if (mSingleFolderMode) { if (mSingleFolderMode) {
mFolderName = mSearch.getFolderNames().get(0); mFolderName = mSearch.getFolderNames().get(0);