Skip to content

Commit

Permalink
Add paging endpoints (#11)
Browse files Browse the repository at this point in the history
- Update android studio codestyles
- Add useful endpoints
  • Loading branch information
StaehliJ authored Jun 30, 2023
1 parent bdb09ed commit e4ff0ec
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 33 deletions.
125 changes: 125 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ object Config {
const val minSdk = 21

const val major = 0
const val minor = 2
const val patch = 1
const val minor = 3
const val patch = 0
const val versionName = "$major.$minor.$patch"

const val maven_group = "ch.srg.data.provider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import ch.srg.dataProvider.integrationlayer.data.remote.SearchResultWithMediaLis
import ch.srg.dataProvider.integrationlayer.data.remote.SearchResultWithShowList
import ch.srg.dataProvider.integrationlayer.data.remote.Show
import ch.srg.dataProvider.integrationlayer.data.remote.Song
import ch.srg.dataProvider.integrationlayer.data.remote.Transmission
import ch.srg.dataProvider.integrationlayer.request.IlService
import ch.srg.dataProvider.integrationlayer.request.SearchProvider
import ch.srg.dataProvider.integrationlayer.request.parameters.Bu
import ch.srg.dataProvider.integrationlayer.request.parameters.IlDate
import ch.srg.dataProvider.integrationlayer.request.parameters.IlDateTime
import ch.srg.dataProvider.integrationlayer.request.parameters.IlMediaType
import ch.srg.dataProvider.integrationlayer.request.parameters.IlPaging.Unlimited.toIlPaging
import ch.srg.dataProvider.integrationlayer.request.parameters.IlTransmission
import ch.srg.dataProvider.integrationlayer.request.parameters.IlUrns
import ch.srgssr.dataprovider.paging.datasource.NextUrlPagingSource
import ch.srgssr.dataprovider.paging.datasource.UrnsPagingSource
Expand Down Expand Up @@ -57,8 +59,7 @@ class DataProviderPaging @Inject constructor(

fun getLatestMediaByShowUrn(showUrn: String, pageSize: Int = DefaultPageSize): Flow<PagingData<Media>> {
return createNextUrlPagingData(
pageSize = pageSize,
initialCall = { ilService.getLatestMediaByShowUrn(showUrn, it.toIlPaging()) },
pageSize = pageSize, initialCall = { ilService.getLatestMediaByShowUrn(showUrn, it.toIlPaging()) },
nextCall = { ilService.getMediaListNextUrl(it) }
)
}
Expand All @@ -72,16 +73,19 @@ class DataProviderPaging @Inject constructor(
pageSize: Int = DefaultPageSize
): Flow<PagingData<Media>> {
return Pager(config = pageSize.toPagingConfig(), pagingSourceFactory = {
UrnsPagingSource(urns = listShowUrns, call = { urns ->
ilService.getLatestMediaByShowUrns(
showUrns = IlUrns(urns),
onlyEpisodes = if (filter == MediaFilter.EPISODE_ONLY) true else null,
excludeEpisodes = if (filter == MediaFilter.EPISODE_EXCLUDED) true else null,
maxPublishedDate = maxPublishDate?.let { IlDateTime(it) },
minPublishedDate = minPublishDate?.let { IlDateTime(it) },
types = types
)
})
UrnsPagingSource(
urns = listShowUrns,
call = { urns ->
ilService.getLatestMediaByShowUrns(
showUrns = IlUrns(urns),
onlyEpisodes = if (filter == MediaFilter.EPISODE_ONLY) true else null,
excludeEpisodes = if (filter == MediaFilter.EPISODE_EXCLUDED) true else null,
maxPublishedDate = maxPublishDate?.let { IlDateTime(it) },
minPublishedDate = minPublishDate?.let { IlDateTime(it) },
types = types
)
}
)
}).flow
}

Expand Down Expand Up @@ -133,6 +137,14 @@ class DataProviderPaging @Inject constructor(
)
}

fun getTvLatestEpisodes(bu: Bu, pageSize: Int = DefaultPageSize): Flow<PagingData<Media>> {
return createNextUrlPagingData(
pageSize = pageSize,
initialCall = { ilService.getTvLatestEpisodes(bu, it.toIlPaging()) },
nextCall = { ilService.getMediaListNextUrl(it) }
)
}

fun getTrendingMedias(bu: Bu, type: IlMediaType, onlyEpisodes: Boolean = false, pageSize: Int = DefaultPageSize): Flow<PagingData<Media>> {
return createNextUrlPagingData(
pageSize = pageSize,
Expand Down Expand Up @@ -202,6 +214,7 @@ class DataProviderPaging @Inject constructor(
): Flow<PagingData<Media>> {
return createNextUrlPagingData(
pageSize = pageSize,

initialCall = { ilService.getRadioMostClickedMediasByChannelId(bu, channelId, onlyEpisodes, it.toIlPaging()) },
nextCall = { ilService.getMediaListNextUrl(it) }
)
Expand All @@ -218,11 +231,39 @@ class DataProviderPaging @Inject constructor(
fun getRadioSongListByChannelId(bu: Bu, channelId: String, pageSize: Int = DefaultPageSize): Flow<PagingData<Song>> {
return createNextUrlPagingData(
pageSize = pageSize,
initialCall = { ilService.getRadioSongListByChannelId(bu, channelId, it.toIlPaging()) },
initialCall = { ilService.getRadioSongListByChannelId(bu = bu, channelId = channelId, pageSize = it.toIlPaging()) },
nextCall = { ilService.getSongListNextUrl(it) }
)
}

fun getAllAlphabeticalShows(bu: Bu, transmission: Transmission, radioChannelId: String? = null): Flow<PagingData<Show>> {
return createNextUrlPagingData(
pageSize = DefaultPageSize,
initialCall = {
ilService.getAllAlphabeticalShows(
bu = bu, transmission = IlTransmission(transmission),
radioChannelId = radioChannelId
)
}, nextCall = { ilService.getShowListNextUrl(it) }
)
}

fun getTvAlphabeticalShows(bu: Bu, pageSize: Int = DefaultPageSize): Flow<PagingData<Show>> {
return createNextUrlPagingData(
pageSize = pageSize,
initialCall = { ilService.getTvAlphabeticalShows(bu = bu, pageSize = it.toIlPaging()) },
nextCall = { ilService.getShowListNextUrl(it) }
)
}

fun getTvAlphabeticalShows(bu: Bu, radioChannelId: String, pageSize: Int = DefaultPageSize): Flow<PagingData<Show>> {
return createNextUrlPagingData(
pageSize = pageSize,
initialCall = { ilService.getRadioAlphabeticalRadioShowsByChannelId(bu = bu, channelId = radioChannelId, pageSize = it.toIlPaging()) },
nextCall = { ilService.getShowListNextUrl(it) }
)
}

/**
* Search media.
*
Expand All @@ -239,13 +280,17 @@ class DataProviderPaging @Inject constructor(
lastResult: MutableSharedFlow<SearchResultWithMediaList>? = null,
pageSize: Int = DefaultPageSize
): Flow<PagingData<Media>> {
return createNextUrlPagingData(pageSize, initialCall = {
val result = searchProvider.searchMedias(bu, searchTerm, queryParameters)
lastResult?.emit(result)
result
}, nextCall = {
return createNextUrlPagingData(
pageSize,
initialCall = {
val result = searchProvider.searchMedias(bu, searchTerm, queryParameters)
lastResult?.emit(result)
result
},
nextCall = {
searchProvider.searchMediaWithNextUrl(it)
})
}
)
}

/**
Expand All @@ -263,17 +308,17 @@ class DataProviderPaging @Inject constructor(
lastResult: MutableSharedFlow<SearchResultWithShowList>? = null,
pageSize: Int = DefaultPageSize
): Flow<PagingData<Show>> {
return createNextUrlPagingData(pageSize, initialCall = {
val result = searchProvider.searchShows(
bu,
searchTerm,
IlMediaType(queryParameters.mediaType ?: MediaType.VIDEO)
)
lastResult?.emit(result)
result
}, nextCall = {
return createNextUrlPagingData(
pageSize,
initialCall = {
val result = searchProvider.searchShows(bu, searchTerm, IlMediaType(queryParameters.mediaType ?: MediaType.VIDEO))
lastResult?.emit(result)
result
},
nextCall = {
searchProvider.searchShowWithNextUrl(it)
})
}
)
}

companion object {
Expand All @@ -287,8 +332,7 @@ class DataProviderPaging @Inject constructor(
nextCall: suspend (next: String) -> ListResult<T>?
): Flow<PagingData<T>> = Pager(config = pageSize.toPagingConfig(), pagingSourceFactory = {
NextUrlPagingSource(
initialCall = initialCall,
nextCall = nextCall
initialCall = initialCall, nextCall = nextCall
)
}).flow
}
Expand Down

0 comments on commit e4ff0ec

Please sign in to comment.