Fix loading footer in lists

pull/539/head
Koitharu 3 years ago
parent 2c7438e64d
commit 4bd7656681
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.plus import kotlinx.coroutines.plus
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.model.distinctById import org.koitharu.kotatsu.core.model.distinctById
@ -95,7 +96,6 @@ open class RemoteListViewModel @Inject constructor(
.onEach { filterState -> .onEach { filterState ->
loadingJob?.cancelAndJoin() loadingJob?.cancelAndJoin()
mangaList.value = null mangaList.value = null
hasNextPage.value = false
loadList(filterState, false) loadList(filterState, false)
}.catch { error -> }.catch { error ->
listError.value = error listError.value = error
@ -134,12 +134,16 @@ open class RemoteListViewModel @Inject constructor(
sortOrder = filterState.sortOrder, sortOrder = filterState.sortOrder,
tags = filterState.tags, tags = filterState.tags,
) )
if (!append) { mangaList.update { oldList ->
mangaList.value = list if (!append || oldList.isNullOrEmpty()) {
} else if (list.isNotEmpty()) { list
mangaList.value = mangaList.value?.plus(list) ?: list } else {
oldList + list
}
}
if (append) {
hasNextPage.value = list.isNotEmpty()
} }
hasNextPage.value = list.isNotEmpty() // TODO check if new ids added
} catch (e: CancellationException) { } catch (e: CancellationException) {
throw e throw e
} catch (e: Throwable) { } catch (e: Throwable) {

Loading…
Cancel
Save