fix(data): gracefully skip unsupported library types during refresh

Previously, toLibrary() threw UnsupportedOperationException for
library types the app does not surface (e.g. boxsets, music, photos,
live TV), which aborted the entire home screen refresh. Now these
unsupported types are logged and skipped, preventing a single
unexpected view from leaving the user with an empty home screen.
This commit is contained in:
2026-06-20 19:49:35 +00:00
parent 00c5689195
commit 80b1bd8547
2 changed files with 15 additions and 4 deletions

View File

@@ -280,8 +280,8 @@ class InMemoryAppContentRepository @Inject constructor(
// library detail screen via loadLibraryContent, and on the
// home rows by loadSuggestions / loadContinueWatching /
// loadLatestLibraryContent.
librariesItem.map { dto ->
val library = dto.toLibrary(serverUrl())
librariesItem.mapNotNull { dto ->
val library = dto.toLibrary(serverUrl()) ?: return@mapNotNull null
val count = jellyfinApiClient.getLibraryItemCount(library.id) ?: library.size
when (library.type) {
LibraryKind.MOVIES -> library.copy(movies = emptyList(), size = count)

View File

@@ -11,12 +11,13 @@ import hu.bbara.purefin.model.Season
import hu.bbara.purefin.model.Series
import org.jellyfin.sdk.model.api.BaseItemDto
import org.jellyfin.sdk.model.api.CollectionType
import timber.log.Timber
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.Locale
import java.util.concurrent.TimeUnit
fun BaseItemDto.toLibrary(serverUrl: String): Library {
fun BaseItemDto.toLibrary(serverUrl: String): Library? {
return when (collectionType) {
CollectionType.MOVIES -> Library(
id = id,
@@ -42,10 +43,20 @@ fun BaseItemDto.toLibrary(serverUrl: String): Library {
size = childCount ?: 0,
series = emptyList(),
)
else -> throw UnsupportedOperationException("Unsupported library type: $collectionType")
else -> {
// Jellyfin servers can return other top-level views (e.g. boxsets,
// music, photos, live TV) that this app does not surface on the
// home dashboard. Skip them so a single unsupported view does
// not abort the whole refresh and leave the user with an empty
// home screen.
Timber.tag(TAG).w("Skipping unsupported library type: $collectionType")
null
}
}
}
private const val TAG = "BaseItemDtoConverter"
fun BaseItemDto.toMovie(serverUrl: String): Movie {
return Movie(
id = id,