Skip to content

Commit 2740362

Browse files
authored
uplift(beta): fix(message-list): lateinit property adapter has not been initialized (#10526)
2 parents d3a0e88 + 6ea99de commit 2740362

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/BaseMessageListFragment.kt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ abstract class BaseMessageListFragment :
288288
}
289289

290290
private lateinit var messageListAppearance: MessageListAppearance
291+
private var pendingMessageListInfo: MessageListInfo? = null
292+
private var pendingAdapterDependentFunctionExecution = mutableListOf<() -> Unit>()
291293

292294
fun isSearchViewCollapsed(): Boolean {
293295
return searchView?.isIconified != false
@@ -443,8 +445,6 @@ abstract class BaseMessageListFragment :
443445
}
444446
}
445447

446-
private var pendingMessageListInfo: MessageListInfo? = null
447-
448448
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
449449
lifecycleScope.launch {
450450
viewLifecycleOwner.repeatOnLifecycle(state = Lifecycle.State.CREATED) {
@@ -658,6 +658,11 @@ abstract class BaseMessageListFragment :
658658

659659
this.recyclerView = recyclerView
660660
this.itemTouchHelper = itemTouchHelper
661+
if (pendingAdapterDependentFunctionExecution.isNotEmpty()) {
662+
logger.debug(logTag) { "Executing pending adapter dependent functions" }
663+
pendingAdapterDependentFunctionExecution.forEach { it() }
664+
pendingAdapterDependentFunctionExecution.clear()
665+
}
661666
}
662667

663668
private fun requireCoordinatorLayout(): CoordinatorLayout {
@@ -756,7 +761,17 @@ abstract class BaseMessageListFragment :
756761
viewModel.loadMessageList(config, forceUpdate)
757762
}
758763

759-
fun folderLoading(folderId: Long, loading: Boolean) {
764+
private fun executeOnlyAfterAdapterIsReady(function: () -> Unit) {
765+
if (::adapter.isInitialized.not()) {
766+
pendingAdapterDependentFunctionExecution.add {
767+
function()
768+
}
769+
} else {
770+
function()
771+
}
772+
}
773+
774+
fun folderLoading(folderId: Long, loading: Boolean) = executeOnlyAfterAdapterIsReady {
760775
currentFolder?.let {
761776
if (it.databaseId == folderId) {
762777
it.loading = loading
@@ -882,6 +897,7 @@ abstract class BaseMessageListFragment :
882897
itemTouchHelper = null
883898
swipeRefreshLayout = null
884899
floatingActionButton = null
900+
pendingAdapterDependentFunctionExecution.clear()
885901

886902
if (isNewMessagesView && !requireActivity().isChangingConfigurations) {
887903
account?.id?.let { messagingController.clearNewMessages(it) }

0 commit comments

Comments
 (0)