diff --git a/data/src/main/AndroidManifest.xml b/data/src/main/AndroidManifest.xml index a5918e6..8072ee0 100644 --- a/data/src/main/AndroidManifest.xml +++ b/data/src/main/AndroidManifest.xml @@ -1,4 +1,2 @@ - - - \ No newline at end of file + diff --git a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/ISO8601DateParser.kt b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/ISO8601DateParser.kt index c7d87b8..f834d36 100644 --- a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/ISO8601DateParser.kt +++ b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/ISO8601DateParser.kt @@ -2,12 +2,13 @@ package ch.srg.dataProvider.integrationlayer.data import java.text.ParseException import java.text.SimpleDateFormat -import java.util.* +import java.util.Date +import java.util.Locale /** * DateParser to convert Integration Layer String date to date (ISO_8601) * - * DateParser isn't Thread Safe, each thread must use it own instance. + * DateParser isn't Thread Safe, each thread must use its own instance. * Because SimpleDateFormat isn't Thread Safe @link(https://developer.android.com/reference/java/text/SimpleDateFormat) * * diff --git a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/AspectRatio.kt b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/AspectRatio.kt index 6396f39..83fce62 100644 --- a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/AspectRatio.kt +++ b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/AspectRatio.kt @@ -8,21 +8,21 @@ import kotlinx.serialization.Serializable data class AspectRatio(val numerator: Int, val denominator: Int) { override fun toString(): String { - return "$numerator$Separator$denominator" + return "$numerator$SEPARATOR$denominator" } companion object { val Infinity = AspectRatio(1, 0) val Zero = AspectRatio(0, 1) - private const val Separator = ":" + private const val SEPARATOR = ":" /** * Parse Aspect ratio writing with this numerator:denominator format. - * Example : 1:1, 16:9, 9:16 + * Examples: 1:1, 16:9, 9:16 */ fun parse(str: String): AspectRatio { - val numeratorDenominatorString = str.split(Separator) + val numeratorDenominatorString = str.split(SEPARATOR) require(numeratorDenominatorString.size == 2) { "Expected rational as numerator:denominator but is $str" } val numerator = numeratorDenominatorString[0].toInt() val denominator = numeratorDenominatorString[1].toInt() diff --git a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/BroadCastInformation.kt b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/BroadCastInformation.kt index 4ca68fa..d7fa551 100644 --- a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/BroadCastInformation.kt +++ b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/BroadCastInformation.kt @@ -1,5 +1,7 @@ @file:UseSerializers(DateSerializer::class) + package ch.srg.dataProvider.integrationlayer.data.remote + import ch.srg.dataProvider.integrationlayer.data.serializer.DateSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers diff --git a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Chapter.kt b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Chapter.kt index dfe7f25..8b31859 100644 --- a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Chapter.kt +++ b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Chapter.kt @@ -57,7 +57,7 @@ data class Chapter( val postTrailerStart: Date? = null, /** * The reference date corresponding to the beginning of the stream, if any. You can use this date to map a time - * position relative to the stream (e.g. a segment mark in or mark out) to a date. + * position relative to the stream (e.g., a segment mark in or mark out) to a date. */ @SerialName("dvrReferenceDate") val resourceReferenceDate: Date? = null, diff --git a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Episode.kt b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Episode.kt index 0e4cb4d..9ae0fdd 100644 --- a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Episode.kt +++ b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Episode.kt @@ -1,4 +1,5 @@ @file:UseSerializers(DateSerializer::class) + package ch.srg.dataProvider.integrationlayer.data.remote import ch.srg.dataProvider.integrationlayer.data.ImageUrl diff --git a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Media.kt b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Media.kt index 69abd10..a54525c 100644 --- a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Media.kt +++ b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Media.kt @@ -1,4 +1,5 @@ @file:UseSerializers(DateSerializer::class) + package ch.srg.dataProvider.integrationlayer.data.remote import ch.srg.dataProvider.integrationlayer.data.ImageUrl diff --git a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/MediaComposition.kt b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/MediaComposition.kt index 3c53480..4e7e92d 100644 --- a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/MediaComposition.kt +++ b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/MediaComposition.kt @@ -1,6 +1,5 @@ package ch.srg.dataProvider.integrationlayer.data.remote -import android.text.TextUtils import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -35,7 +34,7 @@ data class MediaComposition( ) /** - * The chapter which should be initially played. + * The chapter that should be initially played. */ fun getMainChapter(): Chapter { return checkNotNull(findChapter(chapterUrn)) { "The main chapter is missing from mediaComposition" } @@ -80,7 +79,7 @@ data class MediaComposition( return false } for (chapter in chapterList) { - if (TextUtils.equals(chapter.urn, urn)) { + if (chapter.urn == urn) { return true } if (chapter.findSegment(urn) != null) { diff --git a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Page.kt b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Page.kt index de40a77..5bcba01 100644 --- a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Page.kt +++ b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Page.kt @@ -1,5 +1,7 @@ package ch.srg.dataProvider.integrationlayer.data.remote + import kotlinx.serialization.Serializable + /** * Copyright (c) SRG SSR. All rights reserved. *

diff --git a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/RelatedContent.kt b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/RelatedContent.kt index a330fc5..55ccae1 100644 --- a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/RelatedContent.kt +++ b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/RelatedContent.kt @@ -1,5 +1,7 @@ package ch.srg.dataProvider.integrationlayer.data.remote + import kotlinx.serialization.Serializable + /** * Copyright (c) SRG SSR. All rights reserved. *

diff --git a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Resource.kt b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Resource.kt index 84a6522..5789498 100644 --- a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Resource.kt +++ b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/Resource.kt @@ -1,6 +1,5 @@ package ch.srg.dataProvider.integrationlayer.data.remote -import android.net.Uri import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -49,19 +48,19 @@ data class Resource @JvmOverloads constructor( } fun isLocalFile(): Boolean { - return Uri.parse(url).scheme == LOCAL_FILE_SCHEME_URL + return url.startsWith(LOCAL_FILE_SCHEME_URL) } fun hasDrm(): Boolean { - return drmList != null && drmList.isNotEmpty() + return !drmList.isNullOrEmpty() } fun hasSubtitles(): Boolean { - return subtitleVariants != null && subtitleVariants.isNotEmpty() + return !subtitleVariants.isNullOrEmpty() } fun hasAudioTracks(): Boolean { - return audioVariants != null && audioVariants.isNotEmpty() + return !audioVariants.isNullOrEmpty() } @Serializable @@ -72,6 +71,6 @@ data class Resource @JvmOverloads constructor( } companion object { - const val LOCAL_FILE_SCHEME_URL = "file" + const val LOCAL_FILE_SCHEME_URL = "file:" } } diff --git a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/SRGMediaMetadata.kt b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/SRGMediaMetadata.kt index d9c55a6..8a8d523 100644 --- a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/SRGMediaMetadata.kt +++ b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/SRGMediaMetadata.kt @@ -1,6 +1,5 @@ package ch.srg.dataProvider.integrationlayer.data.remote -import android.text.TextUtils import java.util.Date /** @@ -28,12 +27,12 @@ interface SRGMediaMetadata : SRGIdentifierMetadata, SRGImageMetadata, SRGMetadat fun getDownloadUri(quality: Quality = Quality.HD): String? { return when (quality) { Quality.SD -> podcastSdUrl - Quality.HD, Quality.HQ -> if (TextUtils.isEmpty(podcastHdUrl)) podcastSdUrl else podcastHdUrl + Quality.HD, Quality.HQ -> if (podcastHdUrl.isNullOrBlank()) podcastSdUrl else podcastHdUrl } } /** - * isBlocked if it has a blockReason or blocked by TimeAvailability at given time + * isBlocked if it has a blockReason or blocked by TimeAvailability at a given time */ fun isBlocked(at: Date = Date()): Boolean { return blockReason != null || getTimeAvailability(at) != TimeAvailability.AVAILABLE diff --git a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/SearchParams.kt b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/SearchParams.kt index c2e929d..9cb8542 100644 --- a/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/SearchParams.kt +++ b/data/src/main/java/ch/srg/dataProvider/integrationlayer/data/remote/SearchParams.kt @@ -1,8 +1,5 @@ package ch.srg.dataProvider.integrationlayer.data.remote -import android.text.TextUtils -import java.util.Locale - /** * Copyright (c) SRG SSR. All rights reserved. * @@ -16,7 +13,7 @@ class SearchParams { AND, OR; override fun toString(): String { - return name.lowercase(Locale.getDefault()) + return name.lowercase() } } @@ -24,7 +21,7 @@ class SearchParams { DEFAULT, DATE; override fun toString(): String { - return name.lowercase(Locale.getDefault()) + return name.lowercase() } } @@ -32,7 +29,7 @@ class SearchParams { DESC, ASC; override fun toString(): String { - return name.lowercase(Locale.getDefault()) + return name.lowercase() } } @@ -102,7 +99,7 @@ class SearchParams { private fun put(result: HashMap, key: String, values: List?) { if (values != null) { - result[key] = TextUtils.join(",", values) + result[key] = values.joinToString(",") } } } diff --git a/data/src/test/java/ch/srg/dataProvider/integrationlayer/data/TestAspectRatioSerializer.kt b/data/src/test/java/ch/srg/dataProvider/integrationlayer/data/TestAspectRatioSerializer.kt index 517e61d..41f5f09 100644 --- a/data/src/test/java/ch/srg/dataProvider/integrationlayer/data/TestAspectRatioSerializer.kt +++ b/data/src/test/java/ch/srg/dataProvider/integrationlayer/data/TestAspectRatioSerializer.kt @@ -2,7 +2,6 @@ package ch.srg.dataProvider.integrationlayer.data import ch.srg.dataProvider.integrationlayer.data.remote.AspectRatio import kotlinx.serialization.encodeToString -import kotlinx.serialization.json.Json import org.junit.Assert.assertEquals import org.junit.Test diff --git a/data/src/test/java/ch/srg/dataProvider/integrationlayer/data/TestBlockReasonSerializer.kt b/data/src/test/java/ch/srg/dataProvider/integrationlayer/data/TestBlockReasonSerializer.kt index 2faf5cc..22d5ac8 100644 --- a/data/src/test/java/ch/srg/dataProvider/integrationlayer/data/TestBlockReasonSerializer.kt +++ b/data/src/test/java/ch/srg/dataProvider/integrationlayer/data/TestBlockReasonSerializer.kt @@ -2,7 +2,6 @@ package ch.srg.dataProvider.integrationlayer.data import ch.srg.dataProvider.integrationlayer.data.remote.BlockReason import kotlinx.serialization.encodeToString -import kotlinx.serialization.json.Json import org.junit.Assert.assertEquals import org.junit.Test diff --git a/dataprovider-paging/src/main/AndroidManifest.xml b/dataprovider-paging/src/main/AndroidManifest.xml index 8bdb7e1..8072ee0 100644 --- a/dataprovider-paging/src/main/AndroidManifest.xml +++ b/dataprovider-paging/src/main/AndroidManifest.xml @@ -1,4 +1,2 @@ - - - + diff --git a/dataprovider-paging/src/main/java/ch/srgssr/dataprovider/paging/DataProviderPaging.kt b/dataprovider-paging/src/main/java/ch/srgssr/dataprovider/paging/DataProviderPaging.kt index 3c04a27..a1101af 100644 --- a/dataprovider-paging/src/main/java/ch/srgssr/dataprovider/paging/DataProviderPaging.kt +++ b/dataprovider-paging/src/main/java/ch/srgssr/dataprovider/paging/DataProviderPaging.kt @@ -38,7 +38,7 @@ class DataProviderPaging( ) { private val searchProvider = SearchProvider(ilService) - fun getShowListFromUrns(tabUrns: List, pageSize: Int = DefaultPageSize): Flow> { + fun getShowListFromUrns(tabUrns: List, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return Pager(config = pageSize.toPagingConfig(), pagingSourceFactory = { UrnsPagingSource(urns = tabUrns, call = { urns -> ilService.getShowListFromUrns(IlUrns(urns)) @@ -46,7 +46,7 @@ class DataProviderPaging( }).flow } - fun getMediaListFromUrns(tabUrns: List, pageSize: Int = DefaultPageSize): Flow> { + fun getMediaListFromUrns(tabUrns: List, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return Pager(config = pageSize.toPagingConfig(), pagingSourceFactory = { UrnsPagingSource(urns = tabUrns, call = { urns -> ilService.getMediaListFromUrns(IlUrns(urns)) @@ -54,7 +54,7 @@ class DataProviderPaging( }).flow } - fun getLatestMediaByShowUrn(showUrn: String, pageSize: Int = DefaultPageSize): Flow> { + fun getLatestMediaByShowUrn(showUrn: String, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return createNextUrlPagingData( pageSize = pageSize, initialCall = { ilService.getLatestMediaByShowUrn(showUrn, it.toIlPaging()) }, nextCall = { ilService.getMediaListNextUrl(it) } @@ -67,7 +67,7 @@ class DataProviderPaging( maxPublishDate: Date? = null, minPublishDate: Date? = null, types: String? = null, - pageSize: Int = DefaultPageSize + pageSize: Int = DEFAULT_PAGE_SIZE ): Flow> { return Pager(config = pageSize.toPagingConfig(), pagingSourceFactory = { UrnsPagingSource( @@ -86,7 +86,7 @@ class DataProviderPaging( }).flow } - fun getMediaRecommendedByUrn(urn: String, pageSize: Int = DefaultPageSize): Flow> { + fun getMediaRecommendedByUrn(urn: String, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return createNextUrlPagingData( pageSize = pageSize, initialCall = { ilService.getMediaRecommendedByUrn(urn, it.toIlPaging()) }, @@ -94,7 +94,7 @@ class DataProviderPaging( ) } - fun getLatestMediaByTopicUrn(topicUrn: String, pageSize: Int = DefaultPageSize): Flow> { + fun getLatestMediaByTopicUrn(topicUrn: String, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return createNextUrlPagingData( pageSize = pageSize, initialCall = { ilService.getLatestMediaByTopicUrn(topicUrn, it.toIlPaging()) }, @@ -102,7 +102,7 @@ class DataProviderPaging( ) } - fun getMostClickedMediaByTopicUrn(topicUrn: String, pageSize: Int = DefaultPageSize): Flow> { + fun getMostClickedMediaByTopicUrn(topicUrn: String, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return createNextUrlPagingData( pageSize = pageSize, initialCall = { ilService.getMostClickedMediaByTopicUrn(topicUrn, it.toIlPaging()) }, @@ -110,7 +110,7 @@ class DataProviderPaging( ) } - fun getTvMostClickedMedias(bu: Bu, topicId: String? = null, pageSize: Int = DefaultPageSize): Flow> { + fun getTvMostClickedMedias(bu: Bu, topicId: String? = null, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return createNextUrlPagingData( pageSize = pageSize, initialCall = { ilService.getTvMostClickedMedias(bu, topicId, it.toIlPaging()) }, @@ -118,7 +118,7 @@ class DataProviderPaging( ) } - fun getTvSoonExpiringMedias(bu: Bu, topicId: String? = null, pageSize: Int = DefaultPageSize): Flow> { + fun getTvSoonExpiringMedias(bu: Bu, topicId: String? = null, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return createNextUrlPagingData( pageSize = pageSize, initialCall = { ilService.getTvSoonExpiringMedias(bu, topicId, it.toIlPaging()) }, @@ -126,7 +126,7 @@ class DataProviderPaging( ) } - fun getTvSoonExpiringMedias(bu: Bu, pageSize: Int = DefaultPageSize): Flow> { + fun getTvSoonExpiringMedias(bu: Bu, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return createNextUrlPagingData( pageSize = pageSize, initialCall = { ilService.getTvWebFirstMedias(bu, it.toIlPaging()) }, @@ -134,7 +134,7 @@ class DataProviderPaging( ) } - fun getTvLatestEpisodes(bu: Bu, pageSize: Int = DefaultPageSize): Flow> { + fun getTvLatestEpisodes(bu: Bu, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return createNextUrlPagingData( pageSize = pageSize, initialCall = { ilService.getTvLatestEpisodes(bu, it.toIlPaging()) }, @@ -142,7 +142,7 @@ class DataProviderPaging( ) } - fun getTrendingMedias(bu: Bu, type: IlMediaType, onlyEpisodes: Boolean = false, pageSize: Int = DefaultPageSize): Flow> { + fun getTrendingMedias(bu: Bu, type: IlMediaType, onlyEpisodes: Boolean = false, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return createNextUrlPagingData( pageSize = pageSize, initialCall = { ilService.getTrendingMedias(bu, type, onlyEpisodes, it.toIlPaging()) }, @@ -150,7 +150,7 @@ class DataProviderPaging( ) } - fun getLatestMediaByChannelId(bu: Bu, type: IlMediaType, channelId: String, pageSize: Int = DefaultPageSize): Flow> { + fun getLatestMediaByChannelId(bu: Bu, type: IlMediaType, channelId: String, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return createNextUrlPagingData( pageSize = pageSize, initialCall = { ilService.getLatestMediaByChannelId(bu, type, channelId, it.toIlPaging()) }, @@ -158,7 +158,7 @@ class DataProviderPaging( ) } - fun getTvEpisodesByDate(bu: Bu, date: IlDate, pageSize: Int = DefaultPageSize): Flow> { + fun getTvEpisodesByDate(bu: Bu, date: IlDate, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return createNextUrlPagingData( pageSize = pageSize, initialCall = { ilService.getTvEpisodesByDate(bu, date, it.toIlPaging()) }, @@ -166,7 +166,7 @@ class DataProviderPaging( ) } - fun getEpisodeCompositionByUrn(showUrn: String, pageSize: Int = DefaultPageSize): Flow> { + fun getEpisodeCompositionByUrn(showUrn: String, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return createNextUrlPagingData( pageSize = pageSize, initialCall = { ilService.getEpisodeCompositionByUrn(showUrn, it.toIlPaging()) }, @@ -178,7 +178,7 @@ class DataProviderPaging( bu: Bu, type: LiveCenterType, onlyEventsWithResult: Boolean = true, - pageSize: Int = DefaultPageSize + pageSize: Int = DEFAULT_PAGE_SIZE ): Flow> { return createNextUrlPagingData( pageSize = pageSize, @@ -187,7 +187,7 @@ class DataProviderPaging( ) } - fun getScheduledLiveStreamVideos(bu: Bu, signLanguageOnly: Boolean = false, pageSize: Int = DefaultPageSize): Flow> { + fun getScheduledLiveStreamVideos(bu: Bu, signLanguageOnly: Boolean = false, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return createNextUrlPagingData( pageSize = pageSize, initialCall = { ilService.getScheduledLiveStreamVideos(bu, signLanguageOnly, it.toIlPaging()) }, @@ -195,7 +195,7 @@ class DataProviderPaging( ) } - fun getRadioEpisodesByDateByChannelId(bu: Bu, date: IlDate, channelId: String, pageSize: Int = DefaultPageSize): Flow> { + fun getRadioEpisodesByDateByChannelId(bu: Bu, date: IlDate, channelId: String, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return createNextUrlPagingData( pageSize = pageSize, initialCall = { ilService.getRadioEpisodesByDateByChannelId(bu, date, channelId, it.toIlPaging()) }, @@ -207,7 +207,7 @@ class DataProviderPaging( bu: Bu, channelId: String, onlyEpisodes: Boolean? = null, - pageSize: Int = DefaultPageSize + pageSize: Int = DEFAULT_PAGE_SIZE ): Flow> { return createNextUrlPagingData( pageSize = pageSize, @@ -217,7 +217,7 @@ class DataProviderPaging( ) } - fun getRadioMostClickedMediasByChannelId(bu: Bu, onlyEpisodes: Boolean? = null, pageSize: Int = DefaultPageSize): Flow> { + fun getRadioMostClickedMediasByChannelId(bu: Bu, onlyEpisodes: Boolean? = null, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return createNextUrlPagingData( pageSize = pageSize, initialCall = { ilService.getRadioMostClickedMedias(bu, onlyEpisodes, it.toIlPaging()) }, @@ -225,7 +225,7 @@ class DataProviderPaging( ) } - fun getRadioSongListByChannelId(bu: Bu, channelId: String, pageSize: Int = DefaultPageSize): Flow> { + fun getRadioSongListByChannelId(bu: Bu, channelId: String, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return createNextUrlPagingData( pageSize = pageSize, initialCall = { ilService.getRadioSongListByChannelId(bu = bu, channelId = channelId, pageSize = it.toIlPaging()) }, @@ -235,7 +235,7 @@ class DataProviderPaging( fun getAllAlphabeticalShows(bu: Bu, transmission: Transmission, radioChannelId: String? = null): Flow> { return createNextUrlPagingData( - pageSize = DefaultPageSize, + pageSize = DEFAULT_PAGE_SIZE, initialCall = { ilService.getAllAlphabeticalShows( bu = bu, transmission = IlTransmission(transmission), @@ -245,7 +245,7 @@ class DataProviderPaging( ) } - fun getTvAlphabeticalShows(bu: Bu, pageSize: Int = DefaultPageSize): Flow> { + fun getTvAlphabeticalShows(bu: Bu, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return createNextUrlPagingData( pageSize = pageSize, initialCall = { ilService.getTvAlphabeticalShows(bu = bu, pageSize = it.toIlPaging()) }, @@ -253,7 +253,7 @@ class DataProviderPaging( ) } - fun getRadioAlphabeticalShowsByChannelId(bu: Bu, radioChannelId: String, pageSize: Int = DefaultPageSize): Flow> { + fun getRadioAlphabeticalShowsByChannelId(bu: Bu, radioChannelId: String, pageSize: Int = DEFAULT_PAGE_SIZE): Flow> { return createNextUrlPagingData( pageSize = pageSize, initialCall = { ilService.getRadioAlphabeticalShowsByChannelId(bu = bu, channelId = radioChannelId, pageSize = it.toIlPaging()) }, @@ -275,7 +275,7 @@ class DataProviderPaging( searchTerm: String, queryParameters: SearchParams.MediaParams, lastResult: MutableSharedFlow? = null, - pageSize: Int = DefaultPageSize + pageSize: Int = DEFAULT_PAGE_SIZE ): Flow> { return createNextUrlPagingData( pageSize, @@ -303,7 +303,7 @@ class DataProviderPaging( searchTerm: String, queryParameters: SearchParams.ShowParams, lastResult: MutableSharedFlow? = null, - pageSize: Int = DefaultPageSize + pageSize: Int = DEFAULT_PAGE_SIZE ): Flow> { return createNextUrlPagingData( pageSize, @@ -319,7 +319,7 @@ class DataProviderPaging( } companion object { - private const val DefaultPageSize = 10 + private const val DEFAULT_PAGE_SIZE = 10 private fun Int.toPagingConfig() = PagingConfig(pageSize = this, prefetchDistance = 1) diff --git a/dataprovider-retrofit/src/main/AndroidManifest.xml b/dataprovider-retrofit/src/main/AndroidManifest.xml index 19d2638..56a9e28 100644 --- a/dataprovider-retrofit/src/main/AndroidManifest.xml +++ b/dataprovider-retrofit/src/main/AndroidManifest.xml @@ -1,4 +1,5 @@ + diff --git a/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/IlService.kt b/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/IlService.kt index ec0e697..57e7e38 100644 --- a/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/IlService.kt +++ b/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/IlService.kt @@ -38,7 +38,7 @@ import retrofit2.http.Url * Retrofit suspend function already called in IO Dispatcher ie withContext(Dispatchers.IO) * So no need to call it when calling it inside a Coroutine scope. * - * suspend function may throws those exceptions : + * Suspend function may throw those exceptions: * - retrofit2.HttpException * - java.io.IOException * @@ -390,10 +390,10 @@ interface IlService { //region search /** - *

SWI supports only the parameters ‘q’ (must not be empty), ‘pageSize’ and 'next’
+     * 
SWI supports only the parameters ‘q’ (must not be empty), ‘pageSize’ and ‘next’
      * For easier client integration the parameter ‘includeAggregations’ is also allowed for SWI, but not supported by the backend.
      *
-     * RTS support all filter parameters except the ‘quality’ parameter.
+     * RTS supports all filter parameters except the ‘quality’ parameter.
      *
      * On the aggregations duration means
      * duration:0, count:2 -> Two medias with a duration up to 59999 milliseconds
diff --git a/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/SearchProvider.kt b/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/SearchProvider.kt
index 5b153c5..c42a36e 100644
--- a/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/SearchProvider.kt
+++ b/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/SearchProvider.kt
@@ -21,7 +21,7 @@ import ch.srg.dataProvider.integrationlayer.request.parameters.IlUrns
 class SearchProvider(private val ilService: IlService) {
 
     /**
-     * Search media result without Media object, only urns
+     * Search media result without a Media object, only urns
      */
     suspend fun searchMediaResult(
         bu: Bu,
@@ -33,7 +33,7 @@ class SearchProvider(private val ilService: IlService) {
     }
 
     /**
-     * Search media result without Media object, only urns
+     * Search media result without a Media object, only urns
      */
     suspend fun searchMediaResult(nextUrl: String): SearchResultMediaList {
         return ilService.getSearchMediaNextUrl(nextUrl)
@@ -74,7 +74,7 @@ class SearchProvider(private val ilService: IlService) {
     }
 
     /**
-     * Search show result without Media object, only urns
+     * Search show result without a Media object, only urns
      */
     suspend fun searchShowResult(
         bu: Bu,
@@ -86,7 +86,7 @@ class SearchProvider(private val ilService: IlService) {
     }
 
     /**
-     * Search show result without Media object, only urns
+     * Search show result without a Media object, only urns
      */
     suspend fun searchShowResultNextUrl(nextUrl: String): SearchResultShowList {
         return ilService.getSearchShowNextUrl(nextUrl)
diff --git a/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/image/DefaultImageUrlDecorator.kt b/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/image/DefaultImageUrlDecorator.kt
index b74e0a3..8482ef7 100644
--- a/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/image/DefaultImageUrlDecorator.kt
+++ b/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/image/DefaultImageUrlDecorator.kt
@@ -9,16 +9,12 @@ import ch.srg.dataProvider.integrationlayer.request.IlHost
  *
  * If the image url isn't supported by [DefaultImageUrlDecorator] the same url is returned.
  *
- * confluence doc : https://srgssr-ch.atlassian.net/wiki/spaces/SRGPLAY/pages/799082429/Project+-+Image+Service)
+ * Confluence doc: https://srgssr-ch.atlassian.net/wiki/spaces/SRGPLAY/pages/799082429/Project+-+Image+Service
  *
  * @param ilHost The [IlHost] of the integration layer image service.
  */
 class DefaultImageUrlDecorator(ilHost: IlHost) : ImageUrlDecorator {
-    private val imageServiceUri: Uri
-
-    init {
-        imageServiceUri = ilHost.hostUri.buildUpon().appendEncodedPath(IMAGES_SEGMENT).build()
-    }
+    private val imageServiceUri = ilHost.hostUri.buildUpon().appendEncodedPath(IMAGES_SEGMENT).build()
 
     override fun decorate(sourceUrl: String, widthPixels: Int): String {
         // Il image service only support some image url hostnames!
diff --git a/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/parameters/IlDateTime.kt b/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/parameters/IlDateTime.kt
index aab1bb7..f6bdc1a 100644
--- a/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/parameters/IlDateTime.kt
+++ b/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/parameters/IlDateTime.kt
@@ -1,7 +1,9 @@
 package ch.srg.dataProvider.integrationlayer.request.parameters
 
 import java.text.SimpleDateFormat
-import java.util.*
+import java.util.Calendar
+import java.util.Date
+import java.util.Locale
 
 /**
  * Format date for Integration layer that use Format: ‘yyyy-MM-ddTHH:mm:ss’ or ISO-8601 based format.
diff --git a/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/parameters/IlParam.kt b/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/parameters/IlParam.kt
index 28309c9..f4c3961 100644
--- a/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/parameters/IlParam.kt
+++ b/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/parameters/IlParam.kt
@@ -17,9 +17,7 @@ sealed class IlParam(val param: String) {
 
         other as IlParam
 
-        if (param != other.param) return false
-
-        return true
+        return param == other.param
     }
 
     override fun hashCode(): Int {
diff --git a/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/utils/IlUrn.java b/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/utils/IlUrn.java
index a61cf5c..e5393d4 100755
--- a/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/utils/IlUrn.java
+++ b/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/utils/IlUrn.java
@@ -34,7 +34,7 @@ public class IlUrn {
      */
     public IlUrn(@NonNull String urn) throws IllegalArgumentException {
         if (!parseBuMam(urn)
-                && !parseSwissTxt(urn)) {
+            && !parseSwissTxt(urn)) {
             throw new IllegalArgumentException(String.format("URN '%s' does not match a valid URN pattern.", urn));
         }
     }
@@ -51,7 +51,7 @@ private boolean parseBuMam(@NonNull String urn) {
                 assetType = ASSET_SHOW;
             }
 
-            id = matcher.group(3); // Do not transform ID since it is case sensitive.
+            id = matcher.group(3); // Do not transform ID since it is case-sensitive.
             underlying = "urn:" + bu + ":" + assetType + ":" + id;
             return true;
         } else {
@@ -105,7 +105,7 @@ public String getBu() {
     }
 
     /**
-     * Return Asset Type (one of audio or video)
+     * Return Asset Type (either audio or video)
      */
     public String getAssetType() {
         return assetType;
@@ -121,6 +121,7 @@ public String getId() {
     /**
      * Returns the underlying string representation.
      */
+    @NonNull
     @Override
     public String toString() {
         return underlying;
diff --git a/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/utils/StreamComparator.java b/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/utils/StreamComparator.java
index b575266..2b6c1a9 100644
--- a/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/utils/StreamComparator.java
+++ b/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/utils/StreamComparator.java
@@ -21,11 +21,11 @@ public class StreamComparator implements Comparator {
 
     public static final int SCORE_NOT_SUPPORTED = Integer.MAX_VALUE;
 
-    private List orderedQualities;
-    private List orderedStreaming;
+    private final List orderedQualities;
+    private final List orderedStreaming;
     @Nullable
-    private List supportedDrms;
-    private boolean dvrSupported;
+    private final List supportedDrms;
+    private final boolean dvrSupported;
 
     public StreamComparator(List orderedQualities, List orderedStreaming, @Nullable List supportedDrms, boolean dvrSupported) {
         this.orderedQualities = orderedQualities;
@@ -44,16 +44,16 @@ public int compare(Resource lhs, Resource rhs) {
 
     public int score(Resource r) {
         if (r.getStreamingMethod() == null
-                || (!dvrSupported && r.getDvr())
-                || (!isSupportedDrm(r.getDrmList()))) {
+            || (!dvrSupported && r.getDvr())
+            || (!isSupportedDrm(r.getDrmList()))) {
             return SCORE_NOT_SUPPORTED;
         }
-        int indexOfStreaming = orderedStreaming.indexOf(r.getStreamingMethod()); // will retrun -1 if not in the list
-        int indexOfQuality = orderedQualities.indexOf(r.getQuality()); // will retrun -1 if not in the list
+        int indexOfStreaming = orderedStreaming.indexOf(r.getStreamingMethod()); // will return -1 if not in the list
+        int indexOfQuality = orderedQualities.indexOf(r.getQuality()); // will return -1 if not in the list
 
         return (indexOfStreaming < 0 ? orderedStreaming.size() : indexOfStreaming) * HANDICAP_STREAMING
-                + (indexOfQuality < 0 ? orderedQualities.size() : indexOfQuality) * HANDICAP_QUALITY
-                + (r.getDvr() ? 0 : HANDICAP_DVR);
+            + (indexOfQuality < 0 ? orderedQualities.size() : indexOfQuality) * HANDICAP_QUALITY
+            + (r.getDvr() ? 0 : HANDICAP_DVR);
     }
 
     private boolean isSupportedDrm(List drmList) {
diff --git a/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/utils/UserAgentUtils.kt b/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/utils/UserAgentUtils.kt
index 50255b2..da14e59 100644
--- a/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/utils/UserAgentUtils.kt
+++ b/dataprovider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/utils/UserAgentUtils.kt
@@ -15,11 +15,14 @@ object UserAgentUtils {
 
     fun createUserAgent(application: Context): String {
         var version: String
-        var verCode: Int
+        var verCode: Long
         try {
             val pInfo = application.packageManager.getPackageInfo(application.packageName, 0)
+
+            @Suppress("DEPRECATION")
+            val versionCode = if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) pInfo.longVersionCode else pInfo.versionCode.toLong()
             version = pInfo.versionName ?: UNKNOWN_VERSION
-            verCode = pInfo.versionCode
+            verCode = versionCode
         } catch (ignored: PackageManager.NameNotFoundException) {
             version = UNKNOWN_VERSION
             verCode = 0
diff --git a/dataprovider-retrofit/src/test/java/ch/srg/dataProvider/integrationlayer/TestIlUrn.kt b/dataprovider-retrofit/src/test/java/ch/srg/dataProvider/integrationlayer/TestIlUrn.kt
index 79ebd2b..8dae394 100644
--- a/dataprovider-retrofit/src/test/java/ch/srg/dataProvider/integrationlayer/TestIlUrn.kt
+++ b/dataprovider-retrofit/src/test/java/ch/srg/dataProvider/integrationlayer/TestIlUrn.kt
@@ -2,7 +2,7 @@ package ch.srg.dataProvider.integrationlayer
 
 import androidx.test.ext.junit.runners.AndroidJUnit4
 import ch.srg.dataProvider.integrationlayer.utils.IlUrn
-import junit.framework.Assert
+import org.junit.Assert
 import org.junit.Test
 import org.junit.runner.RunWith
 
diff --git a/dataproviderdemo/build.gradle.kts b/dataproviderdemo/build.gradle.kts
index 9e84460..0520cbe 100644
--- a/dataproviderdemo/build.gradle.kts
+++ b/dataproviderdemo/build.gradle.kts
@@ -60,5 +60,6 @@ dependencies {
     implementation(libs.appcompat)
     implementation(libs.material)
     implementation(libs.constraintlayout)
+    implementation(libs.lifecycle.runtime)
     implementation(libs.lifecycle.viewmodel)
 }
diff --git a/dataproviderdemo/src/main/AndroidManifest.xml b/dataproviderdemo/src/main/AndroidManifest.xml
index d8822be..b6ac4af 100644
--- a/dataproviderdemo/src/main/AndroidManifest.xml
+++ b/dataproviderdemo/src/main/AndroidManifest.xml
@@ -19,4 +19,4 @@
         
     
 
-
\ No newline at end of file
+
diff --git a/dataproviderdemo/src/main/java/ch/srgssr/dataprovider/demo/MainActivity.kt b/dataproviderdemo/src/main/java/ch/srgssr/dataprovider/demo/MainActivity.kt
index 60bc7f4..a377463 100644
--- a/dataproviderdemo/src/main/java/ch/srgssr/dataprovider/demo/MainActivity.kt
+++ b/dataproviderdemo/src/main/java/ch/srgssr/dataprovider/demo/MainActivity.kt
@@ -3,7 +3,9 @@ package ch.srgssr.dataprovider.demo
 import android.os.Bundle
 import android.util.Log
 import androidx.appcompat.app.AppCompatActivity
+import androidx.lifecycle.Lifecycle
 import androidx.lifecycle.lifecycleScope
+import androidx.lifecycle.repeatOnLifecycle
 import ch.srg.dataProvider.integrationlayer.dependencies.modules.IlServiceModule
 import ch.srg.dataProvider.integrationlayer.dependencies.modules.OkHttpModule
 import ch.srg.dataProvider.integrationlayer.request.IlHost
@@ -11,6 +13,7 @@ import ch.srg.dataProvider.integrationlayer.request.IlService
 import ch.srg.dataProvider.integrationlayer.request.parameters.Bu
 import kotlinx.coroutines.flow.collectLatest
 import kotlinx.coroutines.flow.flow
+import kotlinx.coroutines.launch
 import okhttp3.OkHttpClient
 
 class MainActivity : AppCompatActivity() {
@@ -29,9 +32,11 @@ class MainActivity : AppCompatActivity() {
             emit(ilService.getTvLatestEpisodes(Bu.RTS))
         }
 
-        lifecycleScope.launchWhenResumed {
-            flowData.collectLatest {
-                Log.d("Coucou", "${it.list}")
+        lifecycleScope.launch {
+            lifecycle.repeatOnLifecycle(Lifecycle.State.RESUMED) {
+                flowData.collectLatest {
+                    Log.d("Coucou", "${it.list}")
+                }
             }
         }
     }
diff --git a/dataproviderdemo/src/main/res/values-night/themes.xml b/dataproviderdemo/src/main/res/values-night/themes.xml
index 78b4ab2..f9ee8ca 100644
--- a/dataproviderdemo/src/main/res/values-night/themes.xml
+++ b/dataproviderdemo/src/main/res/values-night/themes.xml
@@ -1,4 +1,4 @@
-
+
     
     
-
\ No newline at end of file
+
diff --git a/dataproviderdemo/src/main/res/values/themes.xml b/dataproviderdemo/src/main/res/values/themes.xml
index 37992f8..5fb3d1f 100644
--- a/dataproviderdemo/src/main/res/values/themes.xml
+++ b/dataproviderdemo/src/main/res/values/themes.xml
@@ -1,4 +1,4 @@
-
+
     
     
-
\ No newline at end of file
+
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 89a90c7..50eff3f 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -21,6 +21,7 @@ appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat"
 constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "constraintlayout" }
 ext-junit = { module = "androidx.test.ext:junit", version.ref = "androidx-junit" }
 junit = { module = "junit:junit", version.ref = "junit" }
+lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycle-viewmodel" }
 lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel", version.ref = "lifecycle-viewmodel" }
 logging-interceptor = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "logging-interceptor" }
 material = { module = "com.google.android.material:material", version.ref = "material" }