Fix counts

This commit is contained in:
Damontecres 2025-10-03 12:03:25 -04:00
parent 8bbcd50385
commit 0595c7174c
No known key found for this signature in database
4 changed files with 13 additions and 9 deletions

View file

@ -65,7 +65,6 @@ class SeasonViewModel
request, request,
GetItemsRequestHandler, GetItemsRequestHandler,
viewModelScope, viewModelScope,
itemCount = item.data.childCount,
) )
pager.init() pager.init()
episodes.value = pager episodes.value = pager

View file

@ -111,7 +111,6 @@ class SeriesViewModel
request, request,
GetItemsRequestHandler, GetItemsRequestHandler,
viewModelScope, viewModelScope,
itemCount = item.data.childCount,
) )
pager.init() pager.init()
Timber.v("Loaded ${pager.size} seasons for series ${item.id}") Timber.v("Loaded ${pager.size} seasons for series ${item.id}")

View file

@ -82,11 +82,10 @@ class ApiRequestPager<T>(
val requestHandler: RequestHandler<T>, val requestHandler: RequestHandler<T>,
private val scope: CoroutineScope, private val scope: CoroutineScope,
private val pageSize: Int = DEFAULT_PAGE_SIZE, private val pageSize: Int = DEFAULT_PAGE_SIZE,
itemCount: Int? = null,
cacheSize: Long = 8, cacheSize: Long = 8,
) : AbstractList<BaseItem?>() { ) : AbstractList<BaseItem?>() {
private var items by mutableStateOf(ItemList<BaseItem>(0, pageSize, mapOf())) private var items by mutableStateOf(ItemList<BaseItem>(0, pageSize, mapOf()))
private var totalCount by mutableIntStateOf(itemCount ?: -1) private var totalCount by mutableIntStateOf(-1)
private val mutex = Mutex() private val mutex = Mutex()
private val cachedPages = private val cachedPages =
CacheBuilder CacheBuilder

View file

@ -5,6 +5,9 @@ import androidx.lifecycle.MutableLiveData
import com.github.damontecres.dolphin.DolphinApplication import com.github.damontecres.dolphin.DolphinApplication
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import timber.log.Timber import timber.log.Timber
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@ -25,11 +28,15 @@ class LoadingExceptionHandler(
return return
} }
Timber.e(exception, "Exception in coroutine") Timber.e(exception, "Exception in coroutine")
loadingState.value = runBlocking {
LoadingState.Error( withContext(Dispatchers.Main) {
message = errorMessage, loadingState.value =
exception = exception, LoadingState.Error(
) message = errorMessage,
exception = exception,
)
}
}
if (autoToast) { if (autoToast) {
Toast Toast