mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-09 16:11:20 +02:00
Rework internals of ApiRequestPager (#518)
## Description Changes how `init()` works for `ApiRequestPager` so that it 1) always forces updating the total count if needed and 2) propagates errors during the initial fetch up to the original caller This means if an error occurs during the initialization of the pager data, it won't be quietly logged and ignored. Instead, ViewModel code will catch it and display an error in the UI. ### Related issues Should fix #492
This commit is contained in:
parent
5c5db4c1ef
commit
13d70e7623
2 changed files with 49 additions and 32 deletions
|
|
@ -252,13 +252,26 @@ class CollectionFolderViewModel
|
|||
this@CollectionFolderViewModel.sortAndDirection.value = sortAndDirection
|
||||
this@CollectionFolderViewModel.filter.value = filter
|
||||
}
|
||||
val newPager = createPager(sortAndDirection, recursive, filter, useSeriesForPrimary)
|
||||
newPager.init()
|
||||
if (newPager.isNotEmpty()) newPager.getBlocking(0)
|
||||
withContext(Dispatchers.Main) {
|
||||
pager.value = newPager
|
||||
loading.value = LoadingState.Success
|
||||
backgroundLoading.value = LoadingState.Success
|
||||
try {
|
||||
val newPager =
|
||||
createPager(sortAndDirection, recursive, filter, useSeriesForPrimary).init()
|
||||
if (newPager.isNotEmpty()) newPager.getBlocking(0)
|
||||
withContext(Dispatchers.Main) {
|
||||
pager.value = newPager
|
||||
loading.value = LoadingState.Success
|
||||
backgroundLoading.value = LoadingState.Success
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
Timber.e(
|
||||
ex,
|
||||
"Exception while loading data: sort=%s, filter=%s",
|
||||
sortAndDirection,
|
||||
filter,
|
||||
)
|
||||
withContext(Dispatchers.Main) {
|
||||
loading.value = LoadingState.Error(ex)
|
||||
pager.value = listOf()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue