diff --git a/api/tmdb/build.gradle.kts b/api/tmdb/build.gradle.kts index 1933da5363..d373551d86 100644 --- a/api/tmdb/build.gradle.kts +++ b/api/tmdb/build.gradle.kts @@ -24,12 +24,10 @@ plugins { dependencies { implementation(projects.core.base) - api(libs.tmdbJava) { - exclude(group = "org.threeten", module = "threetenbp") - } - api("org.threeten:threetenbp:${libs.versions.threetenbp.get()}:no-tzdb") + api(libs.tmdb.api) implementation(libs.okhttp.okhttp) + implementation(libs.ktor.client) implementation(libs.kotlininject.runtime) ksp(libs.kotlininject.compiler) diff --git a/api/tmdb/src/main/java/app/tivi/tmdb/TmdbComponent.kt b/api/tmdb/src/main/java/app/tivi/tmdb/TmdbComponent.kt index 8698f41ea3..15a4219413 100644 --- a/api/tmdb/src/main/java/app/tivi/tmdb/TmdbComponent.kt +++ b/api/tmdb/src/main/java/app/tivi/tmdb/TmdbComponent.kt @@ -16,8 +16,9 @@ package app.tivi.tmdb +import app.moviebase.tmdb.Tmdb3 import app.tivi.inject.ApplicationScope -import com.uwetrottmann.tmdb2.Tmdb +import io.ktor.client.engine.okhttp.OkHttp import me.tatarka.inject.annotations.Provides import okhttp3.OkHttpClient @@ -33,9 +34,15 @@ interface TmdbComponent { fun provideTmdb( client: OkHttpClient, tmdbOAuthInfo: TmdbOAuthInfo, - ): Tmdb = object : Tmdb(tmdbOAuthInfo.apiKey) { - override fun okHttpClient(): OkHttpClient = client.newBuilder() - .apply { setOkHttpClientDefaults(this) } - .build() + ): Tmdb3 = Tmdb3 { + tmdbApiKey = tmdbOAuthInfo.apiKey + maxRetriesOnException = 3 + + httpClient(OkHttp) { + // Probably want to move to using Ktor's caching, timeouts, etc eventually + engine { + preconfigured = client + } + } } } diff --git a/api/tmdb/src/main/java/app/tivi/tmdb/TmdbManager.kt b/api/tmdb/src/main/java/app/tivi/tmdb/TmdbManager.kt index 2d1d8b0499..b6bd653da0 100644 --- a/api/tmdb/src/main/java/app/tivi/tmdb/TmdbManager.kt +++ b/api/tmdb/src/main/java/app/tivi/tmdb/TmdbManager.kt @@ -16,43 +16,33 @@ package app.tivi.tmdb +import app.moviebase.tmdb.Tmdb3 +import app.moviebase.tmdb.model.TmdbConfiguration import app.tivi.inject.ApplicationScope -import app.tivi.util.AppCoroutineDispatchers -import com.uwetrottmann.tmdb2.Tmdb -import com.uwetrottmann.tmdb2.entities.Configuration import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.withContext import me.tatarka.inject.annotations.Inject -import retrofit2.awaitResponse @ApplicationScope @Inject class TmdbManager( - private val dispatchers: AppCoroutineDispatchers, - private val tmdbClient: Tmdb, + private val tmdbClient: Tmdb3, ) { private val imageProvider = MutableStateFlow(TmdbImageUrlProvider()) fun getLatestImageProvider() = imageProvider.value suspend fun refreshConfiguration() { - try { - val response = withContext(dispatchers.io) { - tmdbClient.configurationService().configuration().awaitResponse() - } - onConfigurationLoaded(response.body()!!) - } catch (t: Throwable) { - // TODO - } + val response = tmdbClient.configuration.getApiConfiguration() + onConfigurationLoaded(response) } - private fun onConfigurationLoaded(configuration: Configuration) { - configuration.images?.also { images -> + private fun onConfigurationLoaded(configuration: TmdbConfiguration) { + configuration.images.also { images -> val newProvider = TmdbImageUrlProvider( - images.secure_base_url!!, - images.poster_sizes ?: emptyList(), - images.backdrop_sizes ?: emptyList(), - images.logo_sizes ?: emptyList(), + baseImageUrl = images.secureBaseUrl, + posterSizes = images.posterSizes, + backdropSizes = images.backdropSizes, + logoSizes = images.logoSizes, ) imageProvider.value = newProvider } diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 0b344c8684..ed8606f572 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -59,3 +59,7 @@ # See https://issuetracker.google.com/issues/265188224 -keep,allowshrinking class * extends androidx.compose.ui.node.ModifierNodeElement {} + +# Using ktor client in Android has missing proguard rule +# See https://youtrack.jetbrains.com/issue/KTOR-5528 +-dontwarn org.slf4j.** diff --git a/data/episodes/src/main/java/app/tivi/data/episodes/TmdbEpisodeDataSourceImpl.kt b/data/episodes/src/main/java/app/tivi/data/episodes/TmdbEpisodeDataSourceImpl.kt index 48096a14e8..6067caa953 100644 --- a/data/episodes/src/main/java/app/tivi/data/episodes/TmdbEpisodeDataSourceImpl.kt +++ b/data/episodes/src/main/java/app/tivi/data/episodes/TmdbEpisodeDataSourceImpl.kt @@ -16,29 +16,29 @@ package app.tivi.data.episodes +import app.moviebase.tmdb.Tmdb3 import app.tivi.data.mappers.ShowIdToTmdbIdMapper -import app.tivi.data.mappers.TmdbEpisodeToEpisode +import app.tivi.data.mappers.TmdbEpisodeDetailToEpisode import app.tivi.data.models.Episode -import app.tivi.data.util.bodyOrThrow -import app.tivi.data.util.withRetry -import com.uwetrottmann.tmdb2.Tmdb import me.tatarka.inject.annotations.Inject -import retrofit2.awaitResponse @Inject class TmdbEpisodeDataSourceImpl( private val tmdbIdMapper: ShowIdToTmdbIdMapper, - private val tmdb: Tmdb, - private val episodeMapper: TmdbEpisodeToEpisode, + private val tmdb: Tmdb3, + private val episodeMapper: TmdbEpisodeDetailToEpisode, ) : EpisodeDataSource { override suspend fun getEpisode( showId: Long, seasonNumber: Int, episodeNumber: Int, - ): Episode = withRetry { - tmdb.tvEpisodesService() - .episode(tmdbIdMapper.map(showId), seasonNumber, episodeNumber, null) - .awaitResponse() - .let { episodeMapper.map(it.bodyOrThrow()) } + ): Episode { + return tmdb.showEpisodes + .getDetails( + showId = tmdbIdMapper.map(showId), + seasonNumber = seasonNumber, + episodeNumber = episodeNumber, + ) + .let { episodeMapper.map(it) } } } diff --git a/data/legacy/src/main/java/app/tivi/data/mappers/Mappers.kt b/data/legacy/src/main/java/app/tivi/data/mappers/Mappers.kt index 51fefb4b45..6ebd3a9bf2 100644 --- a/data/legacy/src/main/java/app/tivi/data/mappers/Mappers.kt +++ b/data/legacy/src/main/java/app/tivi/data/mappers/Mappers.kt @@ -18,9 +18,6 @@ package app.tivi.data.mappers -import com.uwetrottmann.tmdb2.entities.BaseTvShow -import com.uwetrottmann.tmdb2.entities.TvShowResultsPage - suspend inline fun Mapper.map(collection: Collection) = collection.map { map(it) } inline fun pairMapperOf( @@ -40,9 +37,3 @@ inline fun pairMapperOf( firstMapper.map(value) to secondMapper.map(index, value) } } - -inline fun unwrapTmdbShowResults( - crossinline f: suspend (List) -> List, -): suspend (TvShowResultsPage) -> List = { - f(it.results ?: emptyList()) -} diff --git a/data/legacy/src/main/java/app/tivi/data/mappers/TmdbEpisodeToEpisode.kt b/data/legacy/src/main/java/app/tivi/data/mappers/TmdbEpisodeDetailToEpisode.kt similarity index 75% rename from data/legacy/src/main/java/app/tivi/data/mappers/TmdbEpisodeToEpisode.kt rename to data/legacy/src/main/java/app/tivi/data/mappers/TmdbEpisodeDetailToEpisode.kt index 02008d11cb..825af2f731 100644 --- a/data/legacy/src/main/java/app/tivi/data/mappers/TmdbEpisodeToEpisode.kt +++ b/data/legacy/src/main/java/app/tivi/data/mappers/TmdbEpisodeDetailToEpisode.kt @@ -16,18 +16,18 @@ package app.tivi.data.mappers +import app.moviebase.tmdb.model.TmdbEpisodeDetail import app.tivi.data.models.Episode -import com.uwetrottmann.tmdb2.entities.TvEpisode import me.tatarka.inject.annotations.Inject @Inject -class TmdbEpisodeToEpisode : Mapper { - override suspend fun map(from: TvEpisode) = Episode( +class TmdbEpisodeDetailToEpisode : Mapper { + override suspend fun map(from: TmdbEpisodeDetail): Episode = Episode( seasonId = 0, tmdbId = from.id, title = from.name, - number = from.episode_number, + number = from.episodeNumber, summary = from.overview, - tmdbBackdropPath = from.still_path, + tmdbBackdropPath = from.stillPath, ) } diff --git a/data/legacy/src/main/java/app/tivi/data/mappers/TmdbImagesToShowImages.kt b/data/legacy/src/main/java/app/tivi/data/mappers/TmdbShowDetailToShowImages.kt similarity index 73% rename from data/legacy/src/main/java/app/tivi/data/mappers/TmdbImagesToShowImages.kt rename to data/legacy/src/main/java/app/tivi/data/mappers/TmdbShowDetailToShowImages.kt index e5b62c66e0..bab1760c4b 100644 --- a/data/legacy/src/main/java/app/tivi/data/mappers/TmdbImagesToShowImages.kt +++ b/data/legacy/src/main/java/app/tivi/data/mappers/TmdbShowDetailToShowImages.kt @@ -16,15 +16,15 @@ package app.tivi.data.mappers +import app.moviebase.tmdb.model.TmdbFileImage +import app.moviebase.tmdb.model.TmdbShowDetail import app.tivi.data.models.ImageType import app.tivi.data.models.ShowTmdbImage -import com.uwetrottmann.tmdb2.entities.Image -import com.uwetrottmann.tmdb2.entities.TvShow import me.tatarka.inject.annotations.Inject @Inject -class TmdbImagesToShowImages() : Mapper> { - override suspend fun map(from: TvShow): List { +class TmdbShowDetailToShowImages : Mapper> { + override suspend fun map(from: TmdbShowDetail): List { val results = ArrayList() from.images?.posters?.mapTo(results) { image -> from.mapImage(image, ImageType.POSTER) @@ -36,20 +36,20 @@ class TmdbImagesToShowImages() : Mapper> { if (results.isEmpty()) { // If we have no images, we haven't been passed a result which has images. We'll // synthesize some from the TvShow properties - from.poster_path?.also { path -> + from.posterPath?.let { path -> results += ShowTmdbImage( showId = 0, path = path, - type = ImageType.POSTER, isPrimary = true, + type = ImageType.POSTER, ) } - from.backdrop_path?.also { path -> + from.backdropPath?.let { path -> results += ShowTmdbImage( showId = 0, path = path, - type = ImageType.BACKDROP, isPrimary = true, + type = ImageType.BACKDROP, ) } } @@ -57,15 +57,15 @@ class TmdbImagesToShowImages() : Mapper> { return results } - private fun TvShow.mapImage(image: Image, type: ImageType) = ShowTmdbImage( + private fun TmdbShowDetail.mapImage(image: TmdbFileImage, type: ImageType) = ShowTmdbImage( showId = 0, - path = image.file_path!!, + path = image.filePath, type = type, - language = image.iso_639_1, - rating = image.vote_average?.toFloat() ?: 0f, + language = image.iso639, + rating = image.voteAverage ?: 0f, isPrimary = when (type) { - ImageType.BACKDROP -> image.file_path == backdrop_path - ImageType.POSTER -> image.file_path == poster_path + ImageType.BACKDROP -> image.filePath == backdropPath + ImageType.POSTER -> image.filePath == posterPath else -> false }, ) diff --git a/data/legacy/src/main/java/app/tivi/data/mappers/TmdbBaseShowToTiviShow.kt b/data/legacy/src/main/java/app/tivi/data/mappers/TmdbShowDetailToTiviShow.kt similarity index 68% rename from data/legacy/src/main/java/app/tivi/data/mappers/TmdbBaseShowToTiviShow.kt rename to data/legacy/src/main/java/app/tivi/data/mappers/TmdbShowDetailToTiviShow.kt index b61d52a5bb..dfa17a91c6 100644 --- a/data/legacy/src/main/java/app/tivi/data/mappers/TmdbBaseShowToTiviShow.kt +++ b/data/legacy/src/main/java/app/tivi/data/mappers/TmdbShowDetailToTiviShow.kt @@ -16,15 +16,19 @@ package app.tivi.data.mappers +import app.moviebase.tmdb.model.TmdbShowDetail import app.tivi.data.models.TiviShow -import com.uwetrottmann.tmdb2.entities.BaseTvShow import me.tatarka.inject.annotations.Inject @Inject -class TmdbBaseShowToTiviShow() : Mapper { - override suspend fun map(from: BaseTvShow) = TiviShow( +class TmdbShowDetailToTiviShow : Mapper { + override suspend fun map(from: TmdbShowDetail) = TiviShow( tmdbId = from.id, + imdbId = from.externalIds?.imdbId, title = from.name, summary = from.overview, + homepage = from.homepage, + network = from.networks.firstOrNull()?.name, + networkLogoPath = from.networks.firstOrNull()?.logoPath, ) } diff --git a/data/legacy/src/main/java/app/tivi/data/mappers/TmdbShowResultsPageToTiviShows.kt b/data/legacy/src/main/java/app/tivi/data/mappers/TmdbShowPageResultToTiviShows.kt similarity index 68% rename from data/legacy/src/main/java/app/tivi/data/mappers/TmdbShowResultsPageToTiviShows.kt rename to data/legacy/src/main/java/app/tivi/data/mappers/TmdbShowPageResultToTiviShows.kt index 0f2f1270fd..b3eb115e6c 100644 --- a/data/legacy/src/main/java/app/tivi/data/mappers/TmdbShowResultsPageToTiviShows.kt +++ b/data/legacy/src/main/java/app/tivi/data/mappers/TmdbShowPageResultToTiviShows.kt @@ -16,33 +16,33 @@ package app.tivi.data.mappers +import app.moviebase.tmdb.model.TmdbShowPageResult import app.tivi.data.models.ImageType import app.tivi.data.models.ShowTmdbImage import app.tivi.data.models.TiviShow -import com.uwetrottmann.tmdb2.entities.TvShowResultsPage import me.tatarka.inject.annotations.Inject @Inject -class TmdbShowResultsPageToTiviShows( - private val tmdbShowMapper: TmdbBaseShowToTiviShow, -) : Mapper>>> { - override suspend fun map(from: TvShowResultsPage): List>> { - return from.results.map { - val show = tmdbShowMapper.map(it) +class TmdbShowPageResultToTiviShows( + private val tmdbShowMapper: TmdbShowToTiviShow, +) : Mapper>>> { + override suspend fun map(from: TmdbShowPageResult): List>> { + return from.results.map { result -> + val show = tmdbShowMapper.map(result) val images = ArrayList() - if (it.poster_path != null) { + result.posterPath?.let { path -> images += ShowTmdbImage( showId = 0, - path = it.poster_path, + path = path, isPrimary = true, type = ImageType.POSTER, ) } - if (it.backdrop_path != null) { + result.backdropPath?.let { path -> images += ShowTmdbImage( showId = 0, - path = it.backdrop_path, + path = path, isPrimary = true, type = ImageType.BACKDROP, ) diff --git a/data/legacy/src/main/java/app/tivi/data/mappers/TmdbShowToTiviShow.kt b/data/legacy/src/main/java/app/tivi/data/mappers/TmdbShowToTiviShow.kt index 55b1c1dbcd..54c391ef2e 100644 --- a/data/legacy/src/main/java/app/tivi/data/mappers/TmdbShowToTiviShow.kt +++ b/data/legacy/src/main/java/app/tivi/data/mappers/TmdbShowToTiviShow.kt @@ -16,19 +16,15 @@ package app.tivi.data.mappers +import app.moviebase.tmdb.model.TmdbShow import app.tivi.data.models.TiviShow -import com.uwetrottmann.tmdb2.entities.TvShow import me.tatarka.inject.annotations.Inject @Inject -class TmdbShowToTiviShow() : Mapper { - override suspend fun map(from: TvShow) = TiviShow( +class TmdbShowToTiviShow : Mapper { + override suspend fun map(from: TmdbShow) = TiviShow( tmdbId = from.id, - imdbId = from.external_ids?.imdb_id, title = from.name, summary = from.overview, - homepage = from.homepage, - network = from.networks?.firstOrNull()?.name, - networkLogoPath = from.networks?.firstOrNull()?.logo_path, ) } diff --git a/data/relatedshows/src/main/java/app/tivi/data/relatedshows/RelatedShowsStore.kt b/data/relatedshows/src/main/java/app/tivi/data/relatedshows/RelatedShowsStore.kt index 1b3630a826..9f42cc5c73 100644 --- a/data/relatedshows/src/main/java/app/tivi/data/relatedshows/RelatedShowsStore.kt +++ b/data/relatedshows/src/main/java/app/tivi/data/relatedshows/RelatedShowsStore.kt @@ -33,7 +33,7 @@ import org.mobilenativefoundation.store.store5.StoreBuilder @ApplicationScope @Inject class RelatedShowsStore( - dataSource: TmdbRelatedShowsDataSource, + dataSource: TraktRelatedShowsDataSource, relatedShowsDao: RelatedShowsDao, showDao: TiviShowDao, lastRequestStore: RelatedShowsLastRequestStore, diff --git a/data/relatedshows/src/main/java/app/tivi/data/relatedshows/TmdbRelatedShowsDataSourceImpl.kt b/data/relatedshows/src/main/java/app/tivi/data/relatedshows/TmdbRelatedShowsDataSourceImpl.kt index 9a39461542..a19c241f7d 100644 --- a/data/relatedshows/src/main/java/app/tivi/data/relatedshows/TmdbRelatedShowsDataSourceImpl.kt +++ b/data/relatedshows/src/main/java/app/tivi/data/relatedshows/TmdbRelatedShowsDataSourceImpl.kt @@ -16,37 +16,34 @@ package app.tivi.data.relatedshows +import app.moviebase.tmdb.Tmdb3 +import app.moviebase.tmdb.model.TmdbShow import app.tivi.data.mappers.IndexedMapper import app.tivi.data.mappers.ShowIdToTmdbIdMapper -import app.tivi.data.mappers.TmdbBaseShowToTiviShow +import app.tivi.data.mappers.TmdbShowToTiviShow import app.tivi.data.mappers.pairMapperOf -import app.tivi.data.mappers.unwrapTmdbShowResults import app.tivi.data.models.RelatedShowEntry import app.tivi.data.models.TiviShow -import app.tivi.data.util.bodyOrThrow import app.tivi.data.util.withRetry -import com.uwetrottmann.tmdb2.Tmdb -import com.uwetrottmann.tmdb2.entities.BaseTvShow import me.tatarka.inject.annotations.Inject -import retrofit2.awaitResponse @Inject class TmdbRelatedShowsDataSourceImpl( private val tmdbIdMapper: ShowIdToTmdbIdMapper, - private val tmdb: Tmdb, - showMapper: TmdbBaseShowToTiviShow, + private val tmdb: Tmdb3, + showMapper: TmdbShowToTiviShow, ) : TmdbRelatedShowsDataSource { - private val entryMapper = IndexedMapper { index, _ -> + + private val entryMapper = IndexedMapper { index, _ -> RelatedShowEntry(showId = 0, otherShowId = 0, orderIndex = index) } - private val resultMapper = unwrapTmdbShowResults(pairMapperOf(showMapper, entryMapper)) + private val resultMapper = pairMapperOf(showMapper, entryMapper) override suspend operator fun invoke( showId: Long, ): List> = withRetry { - tmdb.tvService() - .recommendations(tmdbIdMapper.map(showId), 1, null) - .awaitResponse() - .let { resultMapper(it.bodyOrThrow()) } + tmdb.show + .getRecommendations(tmdbIdMapper.map(showId), 1, null) + .let { resultMapper(it.results) } } } diff --git a/data/search/src/main/java/app/tivi/data/search/TmdbSearchDataSource.kt b/data/search/src/main/java/app/tivi/data/search/TmdbSearchDataSource.kt index c98f96b6a0..2841d89d65 100644 --- a/data/search/src/main/java/app/tivi/data/search/TmdbSearchDataSource.kt +++ b/data/search/src/main/java/app/tivi/data/search/TmdbSearchDataSource.kt @@ -16,26 +16,22 @@ package app.tivi.data.search -import app.tivi.data.mappers.TmdbShowResultsPageToTiviShows +import app.moviebase.tmdb.Tmdb3 +import app.tivi.data.mappers.TmdbShowPageResultToTiviShows import app.tivi.data.models.ShowTmdbImage import app.tivi.data.models.TiviShow -import app.tivi.data.util.bodyOrThrow -import app.tivi.data.util.withRetry -import com.uwetrottmann.tmdb2.Tmdb import me.tatarka.inject.annotations.Inject -import retrofit2.awaitResponse @Inject class TmdbSearchDataSource( - private val tmdb: Tmdb, - private val mapper: TmdbShowResultsPageToTiviShows, + private val tmdb: Tmdb3, + private val mapper: TmdbShowPageResultToTiviShows, ) : SearchDataSource { override suspend fun search( query: String, - ): List>> = withRetry { - tmdb.searchService() - .tv(query, 1, null, null, false) - .awaitResponse() - .let { mapper.map(it.bodyOrThrow()) } + ): List>> { + return tmdb.search + .findShows(query, 1) + .let { mapper.map(it) } } } diff --git a/data/showimages/src/main/java/app/tivi/data/showimages/TmdbShowImagesDataSource.kt b/data/showimages/src/main/java/app/tivi/data/showimages/TmdbShowImagesDataSource.kt index bdd7f87fff..d5b41aac52 100644 --- a/data/showimages/src/main/java/app/tivi/data/showimages/TmdbShowImagesDataSource.kt +++ b/data/showimages/src/main/java/app/tivi/data/showimages/TmdbShowImagesDataSource.kt @@ -16,29 +16,24 @@ package app.tivi.data.showimages -import app.tivi.data.mappers.TmdbImagesToShowImages +import app.moviebase.tmdb.Tmdb3 +import app.moviebase.tmdb.model.AppendResponse +import app.tivi.data.mappers.TmdbShowDetailToShowImages import app.tivi.data.models.ShowTmdbImage import app.tivi.data.models.TiviShow -import app.tivi.data.util.bodyOrThrow -import app.tivi.data.util.withRetry -import com.uwetrottmann.tmdb2.Tmdb import me.tatarka.inject.annotations.Inject -import retrofit2.awaitResponse @Inject class TmdbShowImagesDataSource( - private val tmdb: Tmdb, - private val mapper: TmdbImagesToShowImages, + private val tmdb: Tmdb3, + private val mapper: TmdbShowDetailToShowImages, ) : ShowImagesDataSource { override suspend fun getShowImages(show: TiviShow): List { val tmdbId = show.tmdbId ?: throw IllegalArgumentException("TmdbId for show does not exist [$show]") - return withRetry { - tmdb.tvService() - .tv(tmdbId, null) - .awaitResponse() - .let { mapper.map(it.bodyOrThrow()) } - } + return tmdb.show + .getDetails(showId = tmdbId, appendResponses = listOf(AppendResponse.IMAGES)) + .let { mapper.map(it) } } } diff --git a/data/shows/src/main/java/app/tivi/data/shows/TmdbShowDataSourceImpl.kt b/data/shows/src/main/java/app/tivi/data/shows/TmdbShowDataSourceImpl.kt index 714e88fae3..b5a6f0e441 100644 --- a/data/shows/src/main/java/app/tivi/data/shows/TmdbShowDataSourceImpl.kt +++ b/data/shows/src/main/java/app/tivi/data/shows/TmdbShowDataSourceImpl.kt @@ -16,28 +16,20 @@ package app.tivi.data.shows -import app.tivi.data.mappers.TmdbShowToTiviShow +import app.moviebase.tmdb.Tmdb3 +import app.tivi.data.mappers.TmdbShowDetailToTiviShow import app.tivi.data.models.TiviShow -import app.tivi.data.util.bodyOrThrow -import app.tivi.data.util.withRetry -import com.uwetrottmann.tmdb2.Tmdb import me.tatarka.inject.annotations.Inject -import retrofit2.awaitResponse @Inject class TmdbShowDataSourceImpl( - private val tmdb: Tmdb, - private val mapper: TmdbShowToTiviShow, + private val tmdb: Tmdb3, + private val mapper: TmdbShowDetailToTiviShow, ) : ShowDataSource { override suspend fun getShow(show: TiviShow): TiviShow { val tmdbId = show.tmdbId ?: throw IllegalArgumentException("TmdbId for show does not exist [$show]") - return withRetry { - tmdb.tvService() - .tv(tmdbId, null) - .awaitResponse() - .let { mapper.map(it.bodyOrThrow()) } - } + return tmdb.show.getDetails(tmdbId).let { mapper.map(it) } } } diff --git a/data/test/src/test/java/app/tivi/data/DatabaseTest.kt b/data/test/src/test/java/app/tivi/data/DatabaseTest.kt index 79fe0f9a5d..c8b683b0b6 100644 --- a/data/test/src/test/java/app/tivi/data/DatabaseTest.kt +++ b/data/test/src/test/java/app/tivi/data/DatabaseTest.kt @@ -20,6 +20,7 @@ import android.app.Application import androidx.arch.core.executor.testing.InstantTaskExecutorRule import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 +import app.moviebase.tmdb.Tmdb3 import app.tivi.core.analytics.AnalyticsComponent import app.tivi.extensions.unsafeLazy import app.tivi.inject.ApplicationScope @@ -31,7 +32,6 @@ import app.tivi.trakt.TraktOAuthInfo import app.tivi.util.Logger import app.tivi.util.LoggerComponent import app.tivi.util.TiviLogger -import com.uwetrottmann.tmdb2.Tmdb import com.uwetrottmann.trakt5.TraktV2 import io.mockk.mockk import me.tatarka.inject.annotations.Component @@ -89,7 +89,7 @@ abstract class TestApplicationComponent( override fun provideTmdb( client: OkHttpClient, tmdbOAuthInfo: TmdbOAuthInfo, - ): Tmdb = Tmdb("fakefakefake") + ): Tmdb3 = Tmdb3("fakefakefake") @Provides override fun provideLogger(bind: TiviLogger): Logger = mockk(relaxUnitFun = true) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0e62d0a0d2..1a0414fd30 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,6 +13,7 @@ kotlin = "1.8.10" kotlininject = "0.6.1" ktlint = "0.48.1" okhttp = "4.10.0" +ktor = "2.2.4" paging = "3.1.1" retrofit = "2.9.0" room = "2.5.0" @@ -133,6 +134,8 @@ mockK = "io.mockk:mockk:1.13.4" okhttp-loggingInterceptor = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "okhttp" } okhttp-okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" } +ktor-client = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" } + playservices-blockstore = "com.google.android.gms:play-services-auth-blockstore:16.2.0" retrofit-gsonConverter = { module = "com.squareup.retrofit2:converter-gson", version.ref = "retrofit" } @@ -151,7 +154,7 @@ threeTenAbp = "com.jakewharton.threetenabp:threetenabp:1.4.4" timber = "com.jakewharton.timber:timber:5.0.1" -tmdbJava = "com.uwetrottmann.tmdb2:tmdb-java:2.8.1" +tmdb-api = "app.moviebase:tmdb-api:0.9.0" traktJava = "com.uwetrottmann.trakt5:trakt-java:6.11.2"