feat(libraries): add size property to Library and related models for better content representation

This commit is contained in:
2026-05-02 20:56:05 +02:00
parent 2753a45645
commit 53bc6246e4
10 changed files with 18 additions and 1 deletions

View File

@@ -230,9 +230,11 @@ class InMemoryAppContentRepository @Inject constructor(
return when (library.type) {
LibraryKind.MOVIES -> library.copy(
movies = contentItem.map { it.toMovie(serverUrl()) },
size = contentItem.size,
)
LibraryKind.SERIES -> library.copy(
series = contentItem.map { it.toSeries(serverUrl()) },
size = contentItem.size,
)
}
}

View File

@@ -27,6 +27,7 @@ fun BaseItemDto.toLibrary(serverUrl: String): Library {
artworkKind = ArtworkKind.PRIMARY
),
type = LibraryKind.MOVIES,
size = childCount ?: 0,
movies = emptyList(),
)
CollectionType.TVSHOWS -> Library(
@@ -38,6 +39,7 @@ fun BaseItemDto.toLibrary(serverUrl: String): Library {
artworkKind = ArtworkKind.PRIMARY
),
type = LibraryKind.SERIES,
size = childCount ?: 0,
series = emptyList(),
)
else -> throw UnsupportedOperationException("Unsupported library type: $collectionType")
@@ -133,4 +135,4 @@ private fun formatRuntime(ticks: Long?): String {
val hours = TimeUnit.SECONDS.toHours(totalSeconds)
val minutes = TimeUnit.SECONDS.toMinutes(totalSeconds) % 60
return if (hours > 0) "${hours}h ${minutes}m" else "${minutes}m"
}
}

View File

@@ -79,6 +79,7 @@ data class CachedLibrary(
val name: String,
val type: String,
val posterUrl: String,
val size: Int = 0,
val series: List<CachedSeries>? = null,
val movies: List<CachedMovie>? = null,
)
@@ -100,6 +101,7 @@ fun Library.toCachedLibrary() = CachedLibrary(
name = name,
type = type.name,
posterUrl = posterUrl,
size = size,
series = series?.map { it.toCachedSeries() },
movies = movies?.map { it.toCachedMovie() },
)
@@ -112,6 +114,7 @@ fun CachedLibrary.toLibrary(): Library? {
name = name,
type = LibraryKind.MOVIES,
posterUrl = posterUrl,
size = size,
movies = movies?.mapNotNull { it.toMovie() } ?: emptyList(),
)
"SERIES" -> Library(
@@ -119,6 +122,7 @@ fun CachedLibrary.toLibrary(): Library? {
name = name,
type = LibraryKind.SERIES,
posterUrl = posterUrl,
size = size,
series = series?.mapNotNull { it.toSeries() } ?: emptyList(),
)
else -> null