From 85a19ccb2ba41f9001fcc3d57d5764488f6fb8fb Mon Sep 17 00:00:00 2001 From: "r.zarchi" Date: Sun, 10 Apr 2022 11:48:41 +0430 Subject: [PATCH] Save and restore activeMessages in savedInstanceState to avoid NullPointerException when rotating --- .../main/java/com/fsck/k9/fragment/MessageListFragment.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/fragment/MessageListFragment.kt b/app/ui/legacy/src/main/java/com/fsck/k9/fragment/MessageListFragment.kt index 237a6a408..2da9c75eb 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/fragment/MessageListFragment.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/fragment/MessageListFragment.kt @@ -159,6 +159,7 @@ class MessageListFragment : private fun restoreInstanceState(savedInstanceState: Bundle?) { if (savedInstanceState == null) return + activeMessages = savedInstanceState.getStringArray(STATE_ACTIVE_MESSAGES)?.map { MessageReference.parse(it)!! } restoreSelectedMessages(savedInstanceState) isRemoteSearch = savedInstanceState.getBoolean(STATE_REMOTE_SEARCH_PERFORMED) savedListState = savedInstanceState.getParcelable(STATE_MESSAGE_LIST) @@ -438,6 +439,10 @@ class MessageListFragment : saveListState(outState) outState.putLongArray(STATE_SELECTED_MESSAGES, selected.toLongArray()) outState.putBoolean(STATE_REMOTE_SEARCH_PERFORMED, isRemoteSearch) + outState.putStringArray( + STATE_ACTIVE_MESSAGES, + activeMessages?.map(MessageReference::toIdentityString)?.toTypedArray() + ) if (activeMessage != null) { outState.putString(STATE_ACTIVE_MESSAGE, activeMessage!!.toIdentityString()) } @@ -1945,6 +1950,7 @@ class MessageListFragment : private const val ARG_IS_THREAD_DISPLAY = "isThreadedDisplay" private const val STATE_SELECTED_MESSAGES = "selectedMessages" + private const val STATE_ACTIVE_MESSAGES = "activeMessages" private const val STATE_ACTIVE_MESSAGE = "activeMessage" private const val STATE_REMOTE_SEARCH_PERFORMED = "remoteSearchPerformed" private const val STATE_MESSAGE_LIST = "listState"