From 4bd765668123262884aa587b808c559f437297be Mon Sep 17 00:00:00 2001 From: Koitharu Date: Wed, 25 Oct 2023 14:17:32 +0300 Subject: [PATCH] Fix loading footer in lists --- .../kotatsu/remotelist/ui/RemoteListViewModel.kt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/remotelist/ui/RemoteListViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/remotelist/ui/RemoteListViewModel.kt index 41f27351a..3336d9efc 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/remotelist/ui/RemoteListViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/remotelist/ui/RemoteListViewModel.kt @@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.stateIn +import kotlinx.coroutines.flow.update import kotlinx.coroutines.plus import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.model.distinctById @@ -95,7 +96,6 @@ open class RemoteListViewModel @Inject constructor( .onEach { filterState -> loadingJob?.cancelAndJoin() mangaList.value = null - hasNextPage.value = false loadList(filterState, false) }.catch { error -> listError.value = error @@ -134,12 +134,16 @@ open class RemoteListViewModel @Inject constructor( sortOrder = filterState.sortOrder, tags = filterState.tags, ) - if (!append) { - mangaList.value = list - } else if (list.isNotEmpty()) { - mangaList.value = mangaList.value?.plus(list) ?: list + mangaList.update { oldList -> + if (!append || oldList.isNullOrEmpty()) { + list + } else { + oldList + list + } + } + if (append) { + hasNextPage.value = list.isNotEmpty() } - hasNextPage.value = list.isNotEmpty() // TODO check if new ids added } catch (e: CancellationException) { throw e } catch (e: Throwable) {