From e59d23ca0e63a54cd54fe5ebcbd7a8f6fe46863f Mon Sep 17 00:00:00 2001 From: cketti Date: Wed, 6 Feb 2013 00:39:45 +0100 Subject: [PATCH] Fix NullPointerException --- src/com/fsck/k9/activity/MessageList.java | 12 ++++++----- .../fsck/k9/fragment/MessageListFragment.java | 21 ++++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index e5b588011..ca74d1a63 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -922,15 +922,17 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme menu.findItem(R.id.next_message).setVisible(false); menu.findItem(R.id.previous_message).setVisible(false); } else { - final MessageReference ref = mMessageViewFragment.getMessageReference(); - final boolean canDoPrev = mMessageListFragment != null && !mMessageListFragment.isFirst(ref); - final boolean canDoNext = mMessageListFragment != null && !mMessageListFragment.isLast(ref); + MessageReference ref = mMessageViewFragment.getMessageReference(); + boolean initialized = (mMessageListFragment != null && + mMessageListFragment.isLoadFinished()); + boolean canDoPrev = (initialized && !mMessageListFragment.isFirst(ref)); + boolean canDoNext = (initialized && !mMessageListFragment.isLast(ref)); - final MenuItem prev = menu.findItem(R.id.previous_message); + MenuItem prev = menu.findItem(R.id.previous_message); prev.setEnabled(canDoPrev); prev.getIcon().setAlpha(canDoPrev ? 255 : 127); - final MenuItem next = menu.findItem(R.id.next_message); + MenuItem next = menu.findItem(R.id.next_message); next.setEnabled(canDoNext); next.getIcon().setAlpha(canDoNext ? 255 : 127); } diff --git a/src/com/fsck/k9/fragment/MessageListFragment.java b/src/com/fsck/k9/fragment/MessageListFragment.java index 02d7543c7..ab4675c88 100644 --- a/src/com/fsck/k9/fragment/MessageListFragment.java +++ b/src/com/fsck/k9/fragment/MessageListFragment.java @@ -2915,6 +2915,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick boolean startSearch(Account account, String folderName); void remoteSearchStarted(); void goBack(); + void updateMenu(); } public void onReverseSort() { @@ -3230,18 +3231,24 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick resetActionMode(); computeBatchDirection(); - if (mSavedListState != null) { - boolean loadFinished = true; - for (int i = 0; i < mCursorValid.length; i++) { - loadFinished &= mCursorValid[i]; - } - - if (loadFinished) { + if (isLoadFinished()) { + if (mSavedListState != null) { mHandler.restoreListPosition(); } + + mFragmentListener.updateMenu(); } } + public boolean isLoadFinished() { + boolean loadFinished = true; + for (int i = 0; i < mCursorValid.length; i++) { + loadFinished &= mCursorValid[i]; + } + + return loadFinished; + } + private void cleanupSelected(Cursor cursor) { if (mSelected.size() == 0) { return;