This repository has been archived by the owner on Nov 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 883
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display season information in Shows Seasons pager (#1580)
* Split out season/episode data sources * Fetch seasons and episodes from TMDb too * Display season poster * Fix tests
- Loading branch information
1 parent
250dacd
commit f07cf1e
Showing
24 changed files
with
549 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...loading/src/commonMain/kotlin/app/tivi/common/imageloading/SeasonImageModelInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2019, Google LLC, Christopher Banes and the Tivi project contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package app.tivi.common.imageloading | ||
|
||
import androidx.compose.ui.unit.Density | ||
import app.tivi.data.episodes.SeasonsEpisodesRepository | ||
import app.tivi.data.imagemodels.SeasonImageModel | ||
import app.tivi.data.util.inPast | ||
import app.tivi.tmdb.TmdbImageUrlProvider | ||
import com.seiko.imageloader.intercept.Interceptor | ||
import com.seiko.imageloader.model.ImageRequest | ||
import com.seiko.imageloader.model.ImageResult | ||
import kotlin.math.roundToInt | ||
import kotlin.time.Duration.Companion.days | ||
import me.tatarka.inject.annotations.Inject | ||
|
||
@Inject | ||
class SeasonImageModelInterceptor( | ||
private val tmdbImageUrlProvider: Lazy<TmdbImageUrlProvider>, | ||
private val repository: SeasonsEpisodesRepository, | ||
private val density: () -> Density, | ||
) : Interceptor { | ||
override suspend fun intercept(chain: Interceptor.Chain): ImageResult { | ||
val request = when (val data = chain.request.data) { | ||
is SeasonImageModel -> handle(chain, data) | ||
else -> chain.request | ||
} | ||
return chain.proceed(request) | ||
} | ||
|
||
private suspend fun handle(chain: Interceptor.Chain, model: SeasonImageModel): ImageRequest { | ||
if (repository.needSeasonUpdate(model.id, expiry = 180.days.inPast)) { | ||
runCatching { repository.updateSeason(model.id) } | ||
} | ||
|
||
val season = repository.getSeason(model.id) | ||
return season?.tmdbPosterPath?.let { posterPath -> | ||
val size = chain.options.sizeResolver.run { density().size() } | ||
val url = tmdbImageUrlProvider.value.getPosterUrl( | ||
path = posterPath, | ||
imageWidth = size.width.roundToInt(), | ||
) | ||
|
||
ImageRequest(chain.request) { | ||
data(url) | ||
} | ||
} ?: chain.request | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
data/episodes/src/commonMain/kotlin/app/tivi/data/episodes/EpisodeDataSource.kt
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
data/episodes/src/commonMain/kotlin/app/tivi/data/episodes/SeasonLastRequestStore.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2023, Google LLC, Christopher Banes and the Tivi project contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package app.tivi.data.episodes | ||
|
||
import app.tivi.data.daos.LastRequestDao | ||
import app.tivi.data.lastrequests.EntityLastRequestStore | ||
import app.tivi.data.models.Request | ||
import me.tatarka.inject.annotations.Inject | ||
|
||
@Inject | ||
class SeasonLastRequestStore( | ||
dao: LastRequestDao, | ||
) : EntityLastRequestStore(Request.SEASON_DETAILS, dao) |
30 changes: 0 additions & 30 deletions
30
data/episodes/src/commonMain/kotlin/app/tivi/data/episodes/SeasonsEpisodesDataSource.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
data/episodes/src/commonMain/kotlin/app/tivi/data/episodes/TraktEpisodeDataSourceImpl.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Shouldn't this be
tmdbSeasonsDataSource
?