Maybe avoid extensions list rendering crashes

This commit is contained in:
arkon 2022-10-21 22:50:33 -04:00
parent fbda243c0d
commit 4138a17e29
3 changed files with 11 additions and 8 deletions

View File

@ -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 ->

View File

@ -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 ->

View File

@ -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,7 +115,9 @@ class ExtensionsPresenter(
}
items
}.collectLatest {
}
.debounce(500) // Avoid crashes due to LazyColumn rendering
.collectLatest {
state.isLoading = false
state.items = it
}