From 98850087ffd154e205dd2babe12fe92714817a2c Mon Sep 17 00:00:00 2001 From: Barnabas Balogh Date: Wed, 1 Apr 2026 22:38:58 +0200 Subject: [PATCH] refactor: update image handling in Series dto to use imageUrlPrefix and JellyfinImageHelper --- .../purefin/app/content/series/SeriesScreenContentTest.kt | 4 ++-- .../hu/bbara/purefin/app/content/series/SeriesScreen.kt | 4 +++- .../hu/bbara/purefin/app/content/series/SeriesScreen.kt | 6 ++++-- .../purefin/core/data/InMemoryAppContentRepository.kt | 5 ++--- .../hu/bbara/purefin/core/data/room/entity/SeriesEntity.kt | 3 +-- .../purefin/core/data/room/offline/OfflineMediaDatabase.kt | 4 ++-- .../data/room/offline/OfflineRoomMediaLocalDataSource.kt | 6 +++--- .../src/main/java/hu/bbara/purefin/core/model/Series.kt | 2 +- .../bbara/purefin/feature/download/MediaDownloadManager.kt | 5 ++--- .../hu/bbara/purefin/feature/shared/home/HomeModels.kt | 7 +++++-- 10 files changed, 25 insertions(+), 21 deletions(-) diff --git a/app-tv/src/androidTest/java/hu/bbara/purefin/app/content/series/SeriesScreenContentTest.kt b/app-tv/src/androidTest/java/hu/bbara/purefin/app/content/series/SeriesScreenContentTest.kt index 3ba621a6..053b7494 100644 --- a/app-tv/src/androidTest/java/hu/bbara/purefin/app/content/series/SeriesScreenContentTest.kt +++ b/app-tv/src/androidTest/java/hu/bbara/purefin/app/content/series/SeriesScreenContentTest.kt @@ -92,7 +92,7 @@ class SeriesScreenContentTest { name = "Severance", synopsis = "Mark leads a team of office workers whose memories have been surgically divided.", year = "2022", - heroImageUrl = "https://images.unsplash.com/photo-1500530855697-b586d89ba3ee", + imageUrlPrefix = "https://images.unsplash.com/photo-1500530855697-b586d89ba3ee", unwatchedEpisodeCount = 3, seasonCount = 1, seasons = listOf( @@ -154,7 +154,7 @@ class SeriesScreenContentTest { name = "Foundation", synopsis = "A band of exiles works to preserve knowledge through the fall of an empire.", year = "2021", - heroImageUrl = "https://images.unsplash.com/photo-1500530855697-b586d89ba3ee", + imageUrlPrefix = "https://images.unsplash.com/photo-1500530855697-b586d89ba3ee", unwatchedEpisodeCount = 0, seasonCount = 1, seasons = listOf( diff --git a/app-tv/src/main/java/hu/bbara/purefin/app/content/series/SeriesScreen.kt b/app-tv/src/main/java/hu/bbara/purefin/app/content/series/SeriesScreen.kt index 9b77274d..874e16f4 100644 --- a/app-tv/src/main/java/hu/bbara/purefin/app/content/series/SeriesScreen.kt +++ b/app-tv/src/main/java/hu/bbara/purefin/app/content/series/SeriesScreen.kt @@ -18,11 +18,13 @@ import hu.bbara.purefin.common.ui.PurefinWaitingScreen import hu.bbara.purefin.common.ui.components.MediaDetailOverviewSection import hu.bbara.purefin.common.ui.components.MediaDetailSectionTitle import hu.bbara.purefin.common.ui.components.TvMediaDetailScaffold +import hu.bbara.purefin.core.data.image.JellyfinImageHelper import hu.bbara.purefin.core.data.navigation.SeriesDto import hu.bbara.purefin.core.model.Season import hu.bbara.purefin.core.model.Series import hu.bbara.purefin.feature.shared.content.series.SeriesViewModel import org.jellyfin.sdk.model.UUID +import org.jellyfin.sdk.model.api.ImageType @Composable fun SeriesScreen( @@ -78,7 +80,7 @@ internal fun SeriesScreenContent( } TvMediaDetailScaffold( - heroImageUrl = series.heroImageUrl, + heroImageUrl = JellyfinImageHelper.finishImageUrl(series.imageUrlPrefix, ImageType.PRIMARY), resetScrollKey = series.id, modifier = modifier, topBar = { diff --git a/app/src/main/java/hu/bbara/purefin/app/content/series/SeriesScreen.kt b/app/src/main/java/hu/bbara/purefin/app/content/series/SeriesScreen.kt index cdef6ddb..e00212e7 100644 --- a/app/src/main/java/hu/bbara/purefin/app/content/series/SeriesScreen.kt +++ b/app/src/main/java/hu/bbara/purefin/app/content/series/SeriesScreen.kt @@ -33,6 +33,7 @@ import androidx.hilt.navigation.compose.hiltViewModel import hu.bbara.purefin.common.ui.MediaSynopsis import hu.bbara.purefin.common.ui.PurefinWaitingScreen import hu.bbara.purefin.common.ui.components.MediaHero +import hu.bbara.purefin.core.data.image.JellyfinImageHelper import hu.bbara.purefin.core.data.navigation.SeriesDto import hu.bbara.purefin.core.model.CastMember import hu.bbara.purefin.core.model.Episode @@ -41,6 +42,7 @@ import hu.bbara.purefin.core.model.Series import hu.bbara.purefin.feature.download.DownloadState import hu.bbara.purefin.feature.shared.content.series.SeriesViewModel import hu.bbara.purefin.ui.theme.AppTheme +import org.jellyfin.sdk.model.api.ImageType import java.util.UUID @Composable @@ -198,7 +200,7 @@ private fun SeriesHeroSection( .height(sectionHeight) ) { MediaHero( - imageUrl = series.heroImageUrl, + imageUrl = JellyfinImageHelper.finishImageUrl(series.imageUrlPrefix, ImageType.PRIMARY), backgroundColor = scheme.background, modifier = Modifier.fillMaxSize() ) @@ -315,7 +317,7 @@ private fun previewSeries(): Series { name = "Constellation", synopsis = "When an experiment in orbit goes wrong, the survivors return home to a world that no longer fits their memories.", year = "2024", - heroImageUrl = "https://images.unsplash.com/photo-1446776811953-b23d57bd21aa", + imageUrlPrefix = "https://images.unsplash.com/photo-1446776811953-b23d57bd21aa", unwatchedEpisodeCount = 2, seasonCount = 2, seasons = listOf( diff --git a/core/data/src/main/java/hu/bbara/purefin/core/data/InMemoryAppContentRepository.kt b/core/data/src/main/java/hu/bbara/purefin/core/data/InMemoryAppContentRepository.kt index d2c6db11..813eae25 100644 --- a/core/data/src/main/java/hu/bbara/purefin/core/data/InMemoryAppContentRepository.kt +++ b/core/data/src/main/java/hu/bbara/purefin/core/data/InMemoryAppContentRepository.kt @@ -451,10 +451,9 @@ class InMemoryAppContentRepository @Inject constructor( synopsis = this.overview ?: "No synopsis available", year = this.productionYear?.toString() ?: this.premiereDate?.year?.toString().orEmpty(), - heroImageUrl = JellyfinImageHelper.toImageUrl( + imageUrlPrefix = JellyfinImageHelper.toPrefixImageUrl( url = serverUrl, - itemId = this.id, - type = ImageType.PRIMARY + itemId = this.id ), unwatchedEpisodeCount = this.userData!!.unplayedItemCount!!, seasonCount = this.childCount!!, diff --git a/core/data/src/main/java/hu/bbara/purefin/core/data/room/entity/SeriesEntity.kt b/core/data/src/main/java/hu/bbara/purefin/core/data/room/entity/SeriesEntity.kt index cd3ba8a5..94cc1d7e 100644 --- a/core/data/src/main/java/hu/bbara/purefin/core/data/room/entity/SeriesEntity.kt +++ b/core/data/src/main/java/hu/bbara/purefin/core/data/room/entity/SeriesEntity.kt @@ -1,7 +1,6 @@ package hu.bbara.purefin.core.data.room.entity import androidx.room.Entity -import androidx.room.ForeignKey import androidx.room.Index import androidx.room.PrimaryKey import java.util.UUID @@ -16,7 +15,7 @@ data class SeriesEntity( val name: String, val synopsis: String, val year: String, - val heroImageUrl: String, + val imageUrlPrefix: String, val unwatchedEpisodeCount: Int, val seasonCount: Int ) diff --git a/core/data/src/main/java/hu/bbara/purefin/core/data/room/offline/OfflineMediaDatabase.kt b/core/data/src/main/java/hu/bbara/purefin/core/data/room/offline/OfflineMediaDatabase.kt index b2baa974..d4025fe6 100644 --- a/core/data/src/main/java/hu/bbara/purefin/core/data/room/offline/OfflineMediaDatabase.kt +++ b/core/data/src/main/java/hu/bbara/purefin/core/data/room/offline/OfflineMediaDatabase.kt @@ -23,7 +23,7 @@ import hu.bbara.purefin.core.data.room.entity.SmartDownloadEntity EpisodeEntity::class, SmartDownloadEntity::class, ], - version = 7, + version = 8, exportSchema = false ) @TypeConverters(UuidConverters::class) @@ -33,4 +33,4 @@ abstract class OfflineMediaDatabase : RoomDatabase() { abstract fun seasonDao(): SeasonDao abstract fun episodeDao(): EpisodeDao abstract fun smartDownloadDao(): SmartDownloadDao -} \ No newline at end of file +} diff --git a/core/data/src/main/java/hu/bbara/purefin/core/data/room/offline/OfflineRoomMediaLocalDataSource.kt b/core/data/src/main/java/hu/bbara/purefin/core/data/room/offline/OfflineRoomMediaLocalDataSource.kt index 91355ec1..f7c7a711 100644 --- a/core/data/src/main/java/hu/bbara/purefin/core/data/room/offline/OfflineRoomMediaLocalDataSource.kt +++ b/core/data/src/main/java/hu/bbara/purefin/core/data/room/offline/OfflineRoomMediaLocalDataSource.kt @@ -219,7 +219,7 @@ class OfflineRoomMediaLocalDataSource( name = name, synopsis = synopsis, year = year, - heroImageUrl = heroImageUrl, + imageUrlPrefix = imageUrlPrefix, unwatchedEpisodeCount = unwatchedEpisodeCount, seasonCount = seasonCount ) @@ -272,7 +272,7 @@ class OfflineRoomMediaLocalDataSource( name = name, synopsis = synopsis, year = year, - heroImageUrl = heroImageUrl, + imageUrlPrefix = imageUrlPrefix, unwatchedEpisodeCount = unwatchedEpisodeCount, seasonCount = seasonCount, seasons = seasons, @@ -305,4 +305,4 @@ class OfflineRoomMediaLocalDataSource( heroImageUrl = heroImageUrl, cast = emptyList() ) -} \ No newline at end of file +} diff --git a/core/model/src/main/java/hu/bbara/purefin/core/model/Series.kt b/core/model/src/main/java/hu/bbara/purefin/core/model/Series.kt index 4a0a9d37..2c20edce 100644 --- a/core/model/src/main/java/hu/bbara/purefin/core/model/Series.kt +++ b/core/model/src/main/java/hu/bbara/purefin/core/model/Series.kt @@ -8,7 +8,7 @@ data class Series( val name: String, val synopsis: String, val year: String, - val heroImageUrl: String, + val imageUrlPrefix: String, val unwatchedEpisodeCount: Int, val seasonCount: Int, val seasons: List, diff --git a/feature/download/src/main/java/hu/bbara/purefin/feature/download/MediaDownloadManager.kt b/feature/download/src/main/java/hu/bbara/purefin/feature/download/MediaDownloadManager.kt index cf967975..ae9b086d 100644 --- a/feature/download/src/main/java/hu/bbara/purefin/feature/download/MediaDownloadManager.kt +++ b/feature/download/src/main/java/hu/bbara/purefin/feature/download/MediaDownloadManager.kt @@ -385,10 +385,9 @@ class MediaDownloadManager @Inject constructor( name = name ?: "Unknown", synopsis = overview ?: "No synopsis available", year = productionYear?.toString() ?: premiereDate?.year?.toString().orEmpty(), - heroImageUrl = JellyfinImageHelper.toImageUrl( + imageUrlPrefix = JellyfinImageHelper.toPrefixImageUrl( url = serverUrl, - itemId = id, - type = ImageType.PRIMARY + itemId = id ), unwatchedEpisodeCount = userData?.unplayedItemCount ?: 0, seasonCount = childCount ?: 0, diff --git a/feature/shared/src/main/java/hu/bbara/purefin/feature/shared/home/HomeModels.kt b/feature/shared/src/main/java/hu/bbara/purefin/feature/shared/home/HomeModels.kt index 785a61ac..fbc9af1a 100644 --- a/feature/shared/src/main/java/hu/bbara/purefin/feature/shared/home/HomeModels.kt +++ b/feature/shared/src/main/java/hu/bbara/purefin/feature/shared/home/HomeModels.kt @@ -58,7 +58,10 @@ data class SuggestedSeries ( override val id: UUID = series.id, override val title: String = series.name, override val description: String = series.synopsis, - override val imageUrl: String = series.heroImageUrl + override val imageUrl: String = JellyfinImageHelper.finishImageUrl( + prefixImageUrl = series.imageUrlPrefix, + imageType = ImageType.PRIMARY + ) ) : SuggestedItem data class SuggestedMovie ( @@ -146,7 +149,7 @@ data class PosterItem( val imageUrl: String = when (type) { BaseItemKind.MOVIE -> movie!!.imageUrlPrefix BaseItemKind.EPISODE -> episode!!.heroImageUrl - BaseItemKind.SERIES -> series!!.heroImageUrl + BaseItemKind.SERIES -> series!!.imageUrlPrefix else -> throw IllegalArgumentException("Invalid type: $type") } fun watched() = when (type) {