Skip to content

Commit

Permalink
Simplify navigation graph definition in "Lists" (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 authored Nov 16, 2023
1 parent ac9e954 commit 2d9cf99
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 293 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,24 @@ sealed interface ContentList {
val bu: Bu
}

data class TvTopics(override val bu: Bu) : ContentListWithBu {
interface ContentListFactory<T : ContentList> {
val route: String
val trackerTitle: String

fun parse(backStackEntry: NavBackStackEntry): T
}

data class TVTopics(override val bu: Bu) : ContentListWithBu {
override fun getDestinationRoute(): String {
return "$RootRoute/$bu/tv/topics"
}

companion object {
const val route = "$RootRoute/{bu}/tv/topics"
companion object : ContentListFactory<TVTopics> {
override val route = "$RootRoute/{bu}/tv/topics"
override val trackerTitle = "tv-topics"

fun parse(backStackEntry: NavBackStackEntry): TvTopics {
return TvTopics(backStackEntry.readBu())
override fun parse(backStackEntry: NavBackStackEntry): TVTopics {
return TVTopics(backStackEntry.readBu())
}
}
}
Expand All @@ -40,10 +48,13 @@ sealed interface ContentList {
return "$RootRoute/latestMediaByTopic/$urn"
}

companion object {
const val route = "$RootRoute/latestMediaByTopic/{topicUrn}"
companion object : ContentListFactory<LatestMediaForTopic> {
override val route = "$RootRoute/latestMediaByTopic/{topicUrn}"

fun parse(backStackEntry: NavBackStackEntry): LatestMediaForTopic {
// TODO Return the topic once https://github.com/SRGSSR/pillarbox-android/pull/306 is merged
override val trackerTitle = "Latest media for topic"

override fun parse(backStackEntry: NavBackStackEntry): LatestMediaForTopic {
return LatestMediaForTopic(urn = backStackEntry.arguments?.getString("topicUrn")!!)
}
}
Expand All @@ -54,25 +65,29 @@ sealed interface ContentList {
return "$RootRoute/latestMediaByShow/$urn"
}

companion object {
const val route = "$RootRoute/latestMediaByShow/{showUrn}"
companion object : ContentListFactory<LatestMediaForShow> {
override val route = "$RootRoute/latestMediaByShow/{showUrn}"

// TODO Return the show once https://github.com/SRGSSR/pillarbox-android/pull/306 is merged
override val trackerTitle = "Latest media for show"

fun parse(backStackEntry: NavBackStackEntry): LatestMediaForShow {
override fun parse(backStackEntry: NavBackStackEntry): LatestMediaForShow {
return LatestMediaForShow(urn = backStackEntry.arguments?.getString("showUrn")!!)
}
}
}

data class TvShows(override val bu: Bu) : ContentListWithBu {
data class TVShows(override val bu: Bu) : ContentListWithBu {
override fun getDestinationRoute(): String {
return "$RootRoute/$bu/tv/shows"
}

companion object {
const val route = "$RootRoute/{bu}/tv/shows"
companion object : ContentListFactory<TVShows> {
override val route = "$RootRoute/{bu}/tv/shows"
override val trackerTitle = "tv-shows"

fun parse(backStackEntry: NavBackStackEntry): TvShows {
return TvShows(backStackEntry.readBu())
override fun parse(backStackEntry: NavBackStackEntry): TVShows {
return TVShows(backStackEntry.readBu())
}
}
}
Expand All @@ -82,10 +97,11 @@ sealed interface ContentList {
return "$RootRoute/$bu/tv/latestMedia"
}

companion object {
const val route = "$RootRoute/{bu}/tv/latestMedia"
companion object : ContentListFactory<TVLatestMedias> {
override val route = "$RootRoute/{bu}/tv/latestMedia"
override val trackerTitle = "tv-latest-videos"

fun parse(backStackEntry: NavBackStackEntry): TVLatestMedias {
override fun parse(backStackEntry: NavBackStackEntry): TVLatestMedias {
return TVLatestMedias(backStackEntry.readBu())
}
}
Expand All @@ -96,10 +112,11 @@ sealed interface ContentList {
return "$RootRoute/$bu/tv/livestream"
}

companion object {
const val route = "$RootRoute/{bu}/tv/livestream"
companion object : ContentListFactory<TVLivestreams> {
override val route = "$RootRoute/{bu}/tv/livestream"
override val trackerTitle = "tv-livestreams"

fun parse(backStackEntry: NavBackStackEntry): TVLivestreams {
override fun parse(backStackEntry: NavBackStackEntry): TVLivestreams {
return TVLivestreams(backStackEntry.readBu())
}
}
Expand All @@ -110,10 +127,11 @@ sealed interface ContentList {
return "$RootRoute/$bu/tv/livecenter"
}

companion object {
const val route = "$RootRoute/{bu}/tv/livecenter"
companion object : ContentListFactory<TVLiveCenter> {
override val route = "$RootRoute/{bu}/tv/livecenter"
override val trackerTitle = "live-center"

fun parse(backStackEntry: NavBackStackEntry): TVLiveCenter {
override fun parse(backStackEntry: NavBackStackEntry): TVLiveCenter {
return TVLiveCenter(backStackEntry.readBu())
}
}
Expand All @@ -124,10 +142,11 @@ sealed interface ContentList {
return "$RootRoute/$bu/tv/liveweb"
}

companion object {
const val route = "$RootRoute/{bu}/tv/liveweb"
companion object : ContentListFactory<TVLiveWeb> {
override val route = "$RootRoute/{bu}/tv/liveweb"
override val trackerTitle = "live-web"

fun parse(backStackEntry: NavBackStackEntry): TVLiveWeb {
override fun parse(backStackEntry: NavBackStackEntry): TVLiveWeb {
return TVLiveWeb(backStackEntry.readBu())
}
}
Expand All @@ -138,10 +157,11 @@ sealed interface ContentList {
return "$RootRoute/$bu/radio/livestream"
}

companion object {
const val route = "$RootRoute/{bu}/radio/livestream"
companion object : ContentListFactory<RadioLiveStreams> {
override val route = "$RootRoute/{bu}/radio/livestream"
override val trackerTitle = "radio-livestreams"

fun parse(backStackEntry: NavBackStackEntry): RadioLiveStreams {
override fun parse(backStackEntry: NavBackStackEntry): RadioLiveStreams {
return RadioLiveStreams(backStackEntry.readBu())
}
}
Expand All @@ -152,10 +172,11 @@ sealed interface ContentList {
return "$RootRoute/${radioChannel.bu}/radio/shows/$radioChannel"
}

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

fun parse(backStackEntry: NavBackStackEntry): RadioShows {
override fun parse(backStackEntry: NavBackStackEntry): RadioShows {
return RadioShows(backStackEntry.readRadioChannel())
}
}
Expand All @@ -166,10 +187,11 @@ sealed interface ContentList {
return "$RootRoute/${radioChannel.bu}/radio/latestMedia/$radioChannel"
}

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

fun parse(backStackEntry: NavBackStackEntry): RadioLatestMedias {
override fun parse(backStackEntry: NavBackStackEntry): RadioLatestMedias {
return RadioLatestMedias(backStackEntry.readRadioChannel())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,30 @@ private val bus = listOf(Bu.RTS, Bu.SRF, Bu.RSI, Bu.RTR, Bu.SWI)
* All the sections available in the "Lists" tab.
*/
val contentListSections = listOf(
ContentListSection("TV Topics", bus.map { ContentList.TvTopics(it) }),
ContentListSection("TV Shows", bus.map { ContentList.TvShows(it) }),
ContentListSection("TV Latest medias", bus.map { ContentList.TVLatestMedias(it) }),
ContentListSection("TV Topics", bus.map { ContentList.TVTopics(it) }),
ContentListSection("TV Shows", bus.map { ContentList.TVShows(it) }),
ContentListSection("TV Latest Videos", bus.map { ContentList.TVLatestMedias(it) }),
ContentListSection("TV Livestreams", bus.map { ContentList.TVLivestreams(it) }),
ContentListSection("TV Live center", bus.map { ContentList.TVLiveCenter(it) }),
ContentListSection("TV Live web", bus.map { ContentList.TVLiveWeb(it) }),
ContentListSection("Radio livestream", bus.map { ContentList.RadioLiveStreams(it) }),
ContentListSection("Radio Latest medias", RadioChannel.entries.map { ContentList.RadioLatestMedias(it) }),
ContentListSection("TV Live Center", bus.map { ContentList.TVLiveCenter(it) }),
ContentListSection("TV Live Web", bus.map { ContentList.TVLiveWeb(it) }),
ContentListSection("Radio Livestreams", bus.map { ContentList.RadioLiveStreams(it) }),
ContentListSection("Radio Latest Audios", RadioChannel.entries.map { ContentList.RadioLatestMedias(it) }),
ContentListSection("Radio Shows", RadioChannel.entries.map { ContentList.RadioShows(it) }),
)

/**
* All the types of content list in the "Lists" tab.
*/
val contentListFactories = listOf(
ContentList.TVTopics,
ContentList.TVShows,
ContentList.TVLatestMedias,
ContentList.TVLivestreams,
ContentList.TVLiveCenter,
ContentList.TVLiveWeb,
ContentList.RadioLiveStreams,
ContentList.RadioLatestMedias,
ContentList.RadioShows,
ContentList.LatestMediaForShow,
ContentList.LatestMediaForTopic
)
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import androidx.tv.material3.Text
import ch.srgssr.pillarbox.demo.shared.ui.NavigationRoutes
import ch.srgssr.pillarbox.demo.shared.ui.integrationLayer.ContentList
import ch.srgssr.pillarbox.demo.shared.ui.integrationLayer.data.ContentListSection
import ch.srgssr.pillarbox.demo.shared.ui.integrationLayer.data.contentListFactories
import ch.srgssr.pillarbox.demo.shared.ui.integrationLayer.data.contentListSections
import ch.srgssr.pillarbox.demo.tv.ui.theme.PillarboxTheme

Expand Down Expand Up @@ -107,150 +108,17 @@ fun ListsHome(
)
}

composable(
route = ContentList.TvTopics.route,
arguments = listOf(
navArgument("bu") { type = NavType.StringType }
)
) {
val contentList = ContentList.TvTopics.parse(it)

BackHandler {
navController.popBackStack()
}

// TODO Integrate content (https://github.com/SRGSSR/pillarbox-android/issues/298)
Text(text = contentList.toString())
}

composable(
route = ContentList.TvShows.route,
arguments = listOf(
navArgument("bu") { type = NavType.StringType }
)
) {
val contentList = ContentList.TvShows.parse(it)

BackHandler {
navController.popBackStack()
}

// TODO Integrate content (https://github.com/SRGSSR/pillarbox-android/issues/298)
Text(text = contentList.toString())
}

composable(
route = ContentList.TVLatestMedias.route,
arguments = listOf(
navArgument("bu") { type = NavType.StringType }
)
) {
val contentList = ContentList.TVLatestMedias.parse(it)

BackHandler {
navController.popBackStack()
}

// TODO Integrate content (https://github.com/SRGSSR/pillarbox-android/issues/298)
Text(text = contentList.toString())
}

composable(
route = ContentList.TVLivestreams.route,
arguments = listOf(
navArgument("bu") { type = NavType.StringType }
)
) {
val contentList = ContentList.TVLivestreams.parse(it)

BackHandler {
navController.popBackStack()
}

// TODO Integrate content (https://github.com/SRGSSR/pillarbox-android/issues/298)
Text(text = contentList.toString())
}

composable(
route = ContentList.TVLiveCenter.route,
arguments = listOf(
navArgument("bu") { type = NavType.StringType }
)
) {
val contentList = ContentList.TVLiveCenter.parse(it)
contentListFactories.forEach { contentListFactory ->
composable(route = contentListFactory.route) {
val contentList = contentListFactory.parse(it)

BackHandler {
navController.popBackStack()
}

// TODO Integrate content (https://github.com/SRGSSR/pillarbox-android/issues/298)
Text(text = contentList.toString())
}

composable(
route = ContentList.TVLiveWeb.route,
arguments = listOf(
navArgument("bu") { type = NavType.StringType }
)
) {
val contentList = ContentList.TVLiveWeb.parse(it)

BackHandler {
navController.popBackStack()
}

// TODO Integrate content (https://github.com/SRGSSR/pillarbox-android/issues/298)
Text(text = contentList.toString())
}

composable(
route = ContentList.RadioLiveStreams.route,
arguments = listOf(
navArgument("bu") { type = NavType.StringType }
)
) {
val contentList = ContentList.RadioLiveStreams.parse(it)

BackHandler {
navController.popBackStack()
}

// TODO Integrate content (https://github.com/SRGSSR/pillarbox-android/issues/298)
Text(text = contentList.toString())
}

composable(
route = ContentList.RadioLatestMedias.route,
arguments = listOf(
navArgument("bu") { type = NavType.StringType },
navArgument("radioChannel") { type = NavType.StringType }
)
) {
val contentList = ContentList.RadioLatestMedias.parse(it)

BackHandler {
navController.popBackStack()
}

// TODO Integrate content (https://github.com/SRGSSR/pillarbox-android/issues/298)
Text(text = contentList.toString())
}

composable(
route = ContentList.RadioShows.route,
arguments = listOf(
navArgument("bu") { type = NavType.StringType },
navArgument("radioChannel") { type = NavType.StringType }
)
) {
val contentList = ContentList.RadioShows.parse(it)
BackHandler {
navController.popBackStack()
}

BackHandler {
navController.popBackStack()
// TODO Integrate content (https://github.com/SRGSSR/pillarbox-android/issues/298)
Text(text = contentList.toString())
}

// TODO Integrate content (https://github.com/SRGSSR/pillarbox-android/issues/298)
Text(text = contentList.toString())
}
}
}
Expand Down
Loading

0 comments on commit 2d9cf99

Please sign in to comment.