From a43bc28f920aefb67ce8320623911f51e9a8e49e Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Mon, 23 Oct 2023 13:13:30 -0600 Subject: [PATCH] Use firstOrNull --- .../metaproviders/TmdbProvider.kt | 45 +++++-------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/metaproviders/TmdbProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/metaproviders/TmdbProvider.kt index 13d1b78a..6500f644 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/metaproviders/TmdbProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/metaproviders/TmdbProvider.kt @@ -273,46 +273,21 @@ open class TmdbProvider : MainAPI() { return if (isTvSeries) { val contentRatings = tmdb.tvService().content_ratings(id).awaitResponse().body() contentRatings?.results - ?.find { it.iso_3166_1 == country } - ?.rating + ?.find { it: ContentRating -> + it.iso_3166_1 == country + }?.rating } else { val releaseDates = tmdb.moviesService().releaseDates(id).awaitResponse().body()?.results - val certification = findFirstNonEmptyCertificationWithCountry(releaseDates, country) - if (!certification.isNullOrEmpty()) { - certification - } else { - null - } + val certification = releaseDates?.firstOrNull { it: ReleaseDatesResult -> + it.iso_3166_1 == country + }?.release_dates?.firstOrNull { it: ReleaseDate -> + !it.certification.isNullOrBlank() + }?.certification + + certification } } - private fun findFirstNonEmptyCertificationWithCountry( - releaseDatesResults: List?, - country: String - ): String? { - for (releaseDateResult in releaseDatesResults.orEmpty()) { - if (releaseDateResult.iso_3166_1 == country) { - val certification = findFirstNonEmptyCertification(releaseDateResult.release_dates) - if (!certification.isNullOrEmpty()) { - return certification - } - } - } - - return null - } - - private fun findFirstNonEmptyCertification(releaseDates: List?): String? { - for (releaseDate in releaseDates.orEmpty()) { - val certification = releaseDate.certification - if (!certification.isNullOrBlank()) { - return certification - } - } - - return null - } - // Possible to add recommendations and such here. override suspend fun load(url: String): LoadResponse? { // https://www.themoviedb.org/movie/7445-brothers