Skip to content

Commit

Permalink
Get the list of radio channels from the IL
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 committed Nov 30, 2023
1 parent 6e7bed7 commit ee2e662
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package ch.srgssr.pillarbox.demo.shared.ui.integrationLayer

import androidx.navigation.NavBackStackEntry
import ch.srg.dataProvider.integrationlayer.request.parameters.Bu
import ch.srgssr.pillarbox.demo.shared.ui.integrationLayer.data.RadioChannel

private const val RootRoute = "content"

Expand All @@ -19,20 +18,13 @@ sealed interface ContentList {

val destinationTitle: String

interface ContentListWithBu : ContentList {
sealed interface ContentListWithBu : ContentList {
val bu: Bu

override val destinationTitle: String
get() = bu.name.uppercase()
}

interface ContentListWithRadioChannel : ContentList {
val radioChannel: RadioChannel

override val destinationTitle: String
get() = radioChannel.label
}

interface ContentListFactory<T : ContentList> {
val route: String
val trackerTitle: String
Expand Down Expand Up @@ -177,28 +169,72 @@ sealed interface ContentList {
}
}

data class RadioShows(override val radioChannel: RadioChannel) : ContentListWithRadioChannel {
override val destinationRoute = "$RootRoute/${radioChannel.bu}/radio/shows/$radioChannel"
data class RadioShows(override val bu: Bu) : ContentListWithBu {
override val destinationRoute = "$RootRoute/$bu/radio/shows"

companion object : ContentListFactory<RadioShows> {
override val route = "$RootRoute/{bu}/radio/shows/{radioChannel}"
override val route = "$RootRoute/{bu}/radio/shows"
override val trackerTitle = "shows"

override fun parse(backStackEntry: NavBackStackEntry): RadioShows {
return RadioShows(backStackEntry.readRadioChannel())
return RadioShows(backStackEntry.readBu())
}
}
}

data class RadioShowsForChannel(
override val bu: Bu,
val channelId: String,
private val channelTitle: String
) : ContentListWithBu {
override val destinationRoute = "$RootRoute/$bu/radio/shows/$channelId/$channelTitle"
override val destinationTitle = channelTitle

companion object : ContentListFactory<RadioShowsForChannel> {
override val route = "$RootRoute/{bu}/radio/shows/{channelId}/{channelTitle}"
override val trackerTitle = "shows-for-channel"

override fun parse(backStackEntry: NavBackStackEntry): RadioShowsForChannel {
return RadioShowsForChannel(
bu = backStackEntry.readBu(),
channelId = backStackEntry.readChannelId(),
channelTitle = backStackEntry.readChannelTitle()
)
}
}
}

data class RadioLatestMedias(override val radioChannel: RadioChannel) : ContentListWithRadioChannel {
override val destinationRoute = "$RootRoute/${radioChannel.bu}/radio/latestMedia/$radioChannel"
data class RadioLatestMedias(override val bu: Bu) : ContentListWithBu {
override val destinationRoute = "$RootRoute/$bu/radio/latestMedia"

companion object : ContentListFactory<RadioLatestMedias> {
override val route = "$RootRoute/{bu}/radio/latestMedia/{radioChannel}"
override val route = "$RootRoute/{bu}/radio/latestMedia"
override val trackerTitle = "latest-audios"

override fun parse(backStackEntry: NavBackStackEntry): RadioLatestMedias {
return RadioLatestMedias(backStackEntry.readRadioChannel())
return RadioLatestMedias(backStackEntry.readBu())
}
}
}

data class RadioLatestMediasForChannel(
override val bu: Bu,
val channelId: String,
private val channelTitle: String
) : ContentListWithBu {
override val destinationRoute = "$RootRoute/$bu/radio/latestMedia/$channelId/$channelTitle"
override val destinationTitle = channelTitle

companion object : ContentListFactory<RadioLatestMediasForChannel> {
override val route = "$RootRoute/{bu}/radio/latestMedia/{channelId}/{channelTitle}"
override val trackerTitle = "latest-audios-for-channel"

override fun parse(backStackEntry: NavBackStackEntry): RadioLatestMediasForChannel {
return RadioLatestMediasForChannel(
bu = backStackEntry.readBu(),
channelId = backStackEntry.readChannelId(),
channelTitle = backStackEntry.readChannelTitle()
)
}
}
}
Expand All @@ -208,6 +244,10 @@ private fun NavBackStackEntry.readBu(): Bu {
return arguments?.getString("bu")?.let { Bu(it) } ?: Bu.RTS
}

private fun NavBackStackEntry.readRadioChannel(): RadioChannel {
return arguments?.getString("radioChannel")?.let { RadioChannel.valueOf(it) } ?: RadioChannel.RTR
private fun NavBackStackEntry.readChannelId(): String {
return arguments?.getString("channelId").orEmpty()
}

private fun NavBackStackEntry.readChannelTitle(): String {
return arguments?.getString("channelTitle").orEmpty()
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import ch.srgssr.pillarbox.demo.shared.di.PlayerModule
import ch.srgssr.pillarbox.demo.shared.ui.integrationLayer.data.Content
import ch.srgssr.pillarbox.demo.shared.ui.integrationLayer.data.ILRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map

/**
Expand Down Expand Up @@ -47,8 +46,13 @@ class ContentListViewModel(
is ContentList.TVLatestMedias -> ilRepository.getTvLatestMedia(bu = contentList.bu)
.mapPaging { Content.Media(it) }

is ContentList.RadioLatestMedias -> ilRepository.getRadioLatestMedia(contentList.radioChannel)
.mapPaging { Content.Media(it) }
is ContentList.RadioLatestMedias -> ilRepository.getRadioChannels(contentList.bu)
.mapPaging { Content.Channel(it) }

is ContentList.RadioLatestMediasForChannel -> ilRepository.getRadioLatestMedia(
bu = contentList.bu,
channelId = contentList.channelId
).mapPaging { Content.Media(it) }

is ContentList.TVShows -> ilRepository.getTVShows(contentList.bu)
.mapPaging { Content.Show(it) }
Expand All @@ -62,8 +66,13 @@ class ContentListViewModel(
is ContentList.LatestMediaForTopic -> ilRepository.getLatestMediaByTopicUrn(contentList.urn)
.mapPaging { Content.Media(it) }

is ContentList.RadioShows -> ilRepository.getRadioShows(contentList.radioChannel)
.mapPaging { Content.Show(it) }
is ContentList.RadioShows -> ilRepository.getRadioChannels(contentList.bu)
.mapPaging { Content.Channel(it) }

is ContentList.RadioShowsForChannel -> ilRepository.getRadioShows(
bu = contentList.bu,
radioChannelId = contentList.channelId
).mapPaging { Content.Show(it) }

is ContentList.TVLiveWeb -> ilRepository.getTvLiveWeb(bu = contentList.bu)
.mapPaging { Content.Media(it) }
Expand All @@ -76,11 +85,6 @@ class ContentListViewModel(

is ContentList.RadioLiveStreams -> ilRepository.getRadioLiveStream(bu = contentList.bu)
.mapPaging { Content.Media(it) }

else -> {
require(false) { "Can't find data for $contentList" }
flowOf(PagingData.empty())
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,36 @@ sealed interface Content {
*/
val urn = topic.urn
}

/**
* Channel.
*
* @param channel The data received from the Integration Layer.
*/
data class Channel(private val channel: ch.srg.dataProvider.integrationlayer.data.remote.Channel) : Content {
/**
* @property description The description of the channel.
*/
val description = channel.description

/**
* @property id The id of the channel.
*/
val id = channel.id

/**
* @property imageTitle The image image of the channel.
*/
val imageTitle = channel.imageTitle

/**
* @property imageUrl The image URL of the channel.
*/
val imageUrl = channel.imageUrl.rawUrl

/**
* @property title The title of the channel.
*/
val title = channel.title
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ val contentListSections = listOf(
ContentListSection("TV Live Center", (bus - Bu.SWI).map { ContentList.TVLiveCenter(it) }),
ContentListSection("TV Live Web", (bus - Bu.SWI).map { ContentList.TVLiveWeb(it) }),
ContentListSection("Radio Livestreams", (bus - Bu.SWI).map { ContentList.RadioLiveStreams(it) }),
ContentListSection("Radio Latest Audios", RadioChannel.entries.map { ContentList.RadioLatestMedias(it) }),
ContentListSection("Radio Shows", RadioChannel.entries.map { ContentList.RadioShows(it) }),
ContentListSection("Radio Latest Audios", (bus - Bu.SWI).map { ContentList.RadioLatestMedias(it) }),
ContentListSection("Radio Shows", (bus - Bu.SWI).map { ContentList.RadioShows(it) }),
)

/**
Expand All @@ -41,5 +41,7 @@ val contentListFactories = listOf(
ContentList.RadioLatestMedias,
ContentList.RadioShows,
ContentList.LatestMediaForShow,
ContentList.LatestMediaForTopic
ContentList.LatestMediaForTopic,
ContentList.RadioShowsForChannel,
ContentList.RadioLatestMediasForChannel,
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package ch.srgssr.pillarbox.demo.shared.ui.integrationLayer.data
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import ch.srg.dataProvider.integrationlayer.data.remote.Channel
import ch.srg.dataProvider.integrationlayer.data.remote.LiveCenterType
import ch.srg.dataProvider.integrationlayer.data.remote.Media
import ch.srg.dataProvider.integrationlayer.data.remote.MediaType
Expand Down Expand Up @@ -43,12 +44,13 @@ class ILRepository(
/**
* Get radio latest media
*
* @param radioChannel
* @param bu
* @param channelId
*/
fun getRadioLatestMedia(radioChannel: RadioChannel): Flow<PagingData<Media>> {
fun getRadioLatestMedia(bu: Bu, channelId: String): Flow<PagingData<Media>> {
return dataProviderPaging.getLatestMediaByChannelId(
bu = radioChannel.bu,
channelId = radioChannel.channelId,
bu = bu,
channelId = channelId,
type = IlMediaType(MediaType.AUDIO),
pageSize = PAGE_SIZE
)
Expand All @@ -66,12 +68,13 @@ class ILRepository(
/**
* Get radio shows
*
* @param radioChannel
* @param bu
* @param radioChannelId
*/
fun getRadioShows(radioChannel: RadioChannel): Flow<PagingData<Show>> {
fun getRadioShows(bu: Bu, radioChannelId: String): Flow<PagingData<Show>> {
return dataProviderPaging.getRadioAlphabeticalShowsByChannelId(
bu = radioChannel.bu,
radioChannelId = radioChannel.channelId,
bu = bu,
radioChannelId = radioChannelId,
pageSize = PAGE_SIZE
)
}
Expand Down Expand Up @@ -190,6 +193,28 @@ class ILRepository(
)
}

/**
* Get the list of radio channels for the provided [bu].
*
* @param bu The BU for which we want to get the radio channels.
*/
fun getRadioChannels(bu: Bu): Flow<PagingData<Channel>> {
return Pager(
config = PagingConfig(pageSize = PAGE_SIZE),
pagingSourceFactory = {
NextUrlPagingSource(
initialCall = {
ilService.getChannelList(
bu = bu,
transmissionType = IlTransmission(Transmission.RADIO)
)
},
nextCall = { null }
)
}
).flow
}

companion object {
private const val PAGE_SIZE = 20
}
Expand Down

This file was deleted.

Loading

0 comments on commit ee2e662

Please sign in to comment.