From 34812fa5b8efb0eeb01f47419518b7bbc0a52302 Mon Sep 17 00:00:00 2001 From: cketti Date: Mon, 27 May 2013 16:59:07 +0200 Subject: [PATCH] Correctly initialize mSingleAccountMode This fixes a NullPointerException when trying to open account settings from the Unified Inbox (when there's only one account). --- src/com/fsck/k9/activity/MessageList.java | 28 +++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index 264d61b0f..34f5655ba 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -439,19 +439,27 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme } } + Preferences prefs = Preferences.getPreferences(getApplicationContext()); + 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); - if (mSingleAccountMode) { - 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"); - onAccountUnavailable(); - return; - } + if (mSingleAccountMode && (mAccount == null || !mAccount.isAvailable(this))) { + Log.i(K9.LOG_TAG, "not opening MessageList of unavailable account"); + onAccountUnavailable(); + return; } if (mSingleFolderMode) {