From 5f06c4c3c0ad7f26341562a82925ed878717adf0 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Mon, 4 Jul 2022 14:21:19 +0300 Subject: [PATCH] Fix selection state restoring --- .../kotatsu/base/ui/list/ListSelectionController.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/koitharu/kotatsu/base/ui/list/ListSelectionController.kt b/app/src/main/java/org/koitharu/kotatsu/base/ui/list/ListSelectionController.kt index d0bea19b3..b3171a9df 100644 --- a/app/src/main/java/org/koitharu/kotatsu/base/ui/list/ListSelectionController.kt +++ b/app/src/main/java/org/koitharu/kotatsu/base/ui/list/ListSelectionController.kt @@ -12,7 +12,9 @@ import androidx.lifecycle.LifecycleOwner import androidx.recyclerview.widget.RecyclerView import androidx.savedstate.SavedStateRegistry import androidx.savedstate.SavedStateRegistryOwner +import kotlinx.coroutines.Dispatchers import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration +import kotlin.coroutines.EmptyCoroutineContext private const val KEY_SELECTION = "selection" private const val PROVIDER_NAME = "selection_decoration" @@ -148,7 +150,11 @@ class ListSelectionController( registry.registerSavedStateProvider(PROVIDER_NAME, this@ListSelectionController) val state = registry.consumeRestoredStateForKey(PROVIDER_NAME) if (state != null) { - restoreState(state.getLongArray(KEY_SELECTION)?.toList().orEmpty()) + Dispatchers.Main.dispatch(EmptyCoroutineContext) { // == Handler.post + if (source.lifecycle.currentState.isAtLeast(Lifecycle.State.CREATED)) { + restoreState(state.getLongArray(KEY_SELECTION)?.toList().orEmpty()) + } + } } } }