From 4138a17e29348c7057ae885a0b8d9d5c3f29cc07 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 21 Oct 2022 22:50:33 -0400 Subject: [PATCH] Maybe avoid extensions list rendering crashes --- .../eu/kanade/presentation/browse/ExtensionsScreen.kt | 4 ++-- .../java/eu/kanade/presentation/updates/UpdatesUiItem.kt | 6 +++--- .../tachiyomi/ui/browse/extension/ExtensionsPresenter.kt | 9 ++++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/browse/ExtensionsScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/ExtensionsScreen.kt index 3d8bc8f4d..33d322491 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/ExtensionsScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/ExtensionsScreen.kt @@ -119,14 +119,14 @@ private fun ExtensionContent( items = state.items, contentType = { when (it) { + is ExtensionUiModel.Header -> "header" is ExtensionUiModel.Item -> "item" - else -> "header" } }, key = { when (it) { is ExtensionUiModel.Header -> "extensionHeader-${it.hashCode()}" - is ExtensionUiModel.Item -> "extension-${it.extension.hashCode()}" + is ExtensionUiModel.Item -> "extension-${it.hashCode()}" } }, ) { item -> diff --git a/app/src/main/java/eu/kanade/presentation/updates/UpdatesUiItem.kt b/app/src/main/java/eu/kanade/presentation/updates/UpdatesUiItem.kt index 5d2552ea6..3c60420e3 100644 --- a/app/src/main/java/eu/kanade/presentation/updates/UpdatesUiItem.kt +++ b/app/src/main/java/eu/kanade/presentation/updates/UpdatesUiItem.kt @@ -52,7 +52,7 @@ import java.util.Date fun LazyListScope.updatesLastUpdatedItem( lastUpdated: Long, ) { - item(key = "last_updated") { + item(key = "updates-lastUpdated") { val time = remember(lastUpdated) { DateUtils.getRelativeTimeSpanString(lastUpdated, Date().time, DateUtils.MINUTE_IN_MILLIS) } @@ -92,8 +92,8 @@ fun LazyListScope.updatesUiItems( }, key = { when (it) { - is UpdatesUiModel.Header -> it.hashCode() - is UpdatesUiModel.Item -> "updates-${it.item.update.chapterId}" + is UpdatesUiModel.Header -> "updatesHeader-${it.hashCode()}" + is UpdatesUiModel.Item -> "updates-${it.item.update.mangaId}-${it.item.update.chapterId}" } }, ) { item -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsPresenter.kt index 83818be2f..c21e140d1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsPresenter.kt @@ -20,6 +20,7 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.update @@ -114,10 +115,12 @@ class ExtensionsPresenter( } items - }.collectLatest { - state.isLoading = false - state.items = it } + .debounce(500) // Avoid crashes due to LazyColumn rendering + .collectLatest { + state.isLoading = false + state.items = it + } } presenterScope.launchIO { findAvailableExtensions() }