Skip to content

Commit

Permalink
Fix navigation in the TV demo app (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 authored Nov 16, 2023
1 parent 0e96d47 commit 1480acd
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,22 @@ private const val RootRoute = "content"
*/
@Suppress("UndocumentedPublicFunction", "UndocumentedPublicProperty", "UndocumentedPublicClass")
sealed interface ContentList {
fun getDestinationRoute(): String
val destinationRoute: String

fun getDestinationTitle(): String
val destinationTitle: String

interface ContentListWithBu : ContentList {
val bu: Bu

override fun getDestinationTitle(): String {
return bu.name.uppercase()
}
override val destinationTitle: String
get() = bu.name.uppercase()
}

interface ContentListWithRadioChannel : ContentList {
val radioChannel: RadioChannel

override fun getDestinationTitle(): String {
return radioChannel.label
}
override val destinationTitle: String
get() = radioChannel.label
}

interface ContentListFactory<T : ContentList> {
Expand All @@ -43,9 +41,7 @@ sealed interface ContentList {
}

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

companion object : ContentListFactory<TVTopics> {
override val route = "$RootRoute/{bu}/tv/topics"
Expand All @@ -61,13 +57,9 @@ sealed interface ContentList {
val urn: String,
val topic: String
) : ContentList {
override fun getDestinationRoute(): String {
return "$RootRoute/latestMediaByTopic/$urn?topic=$topic"
}
override val destinationRoute = "$RootRoute/latestMediaByTopic/$urn?topic=$topic"

override fun getDestinationTitle(): String {
return topic
}
override val destinationTitle = topic

companion object : ContentListFactory<LatestMediaForTopic> {
override val route = "$RootRoute/latestMediaByTopic/{topicUrn}?topic={topic}"
Expand All @@ -88,13 +80,9 @@ sealed interface ContentList {
val urn: String,
val show: String,
) : ContentList {
override fun getDestinationRoute(): String {
return "$RootRoute/latestMediaByShow/$urn?show=$show"
}
override val destinationRoute = "$RootRoute/latestMediaByShow/$urn?show=$show"

override fun getDestinationTitle(): String {
return show
}
override val destinationTitle = show

companion object : ContentListFactory<LatestMediaForShow> {
override val route = "$RootRoute/latestMediaByShow/{showUrn}?show={show}"
Expand All @@ -112,9 +100,7 @@ sealed interface ContentList {
}

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

companion object : ContentListFactory<TVShows> {
override val route = "$RootRoute/{bu}/tv/shows"
Expand All @@ -127,9 +113,7 @@ sealed interface ContentList {
}

data class TVLatestMedias(override val bu: Bu) : ContentListWithBu {
override fun getDestinationRoute(): String {
return "$RootRoute/$bu/tv/latestMedia"
}
override val destinationRoute = "$RootRoute/$bu/tv/latestMedia"

companion object : ContentListFactory<TVLatestMedias> {
override val route = "$RootRoute/{bu}/tv/latestMedia"
Expand All @@ -142,9 +126,7 @@ sealed interface ContentList {
}

data class TVLivestreams(override val bu: Bu) : ContentListWithBu {
override fun getDestinationRoute(): String {
return "$RootRoute/$bu/tv/livestream"
}
override val destinationRoute = "$RootRoute/$bu/tv/livestream"

companion object : ContentListFactory<TVLivestreams> {
override val route = "$RootRoute/{bu}/tv/livestream"
Expand All @@ -157,9 +139,7 @@ sealed interface ContentList {
}

data class TVLiveCenter(override val bu: Bu) : ContentListWithBu {
override fun getDestinationRoute(): String {
return "$RootRoute/$bu/tv/livecenter"
}
override val destinationRoute = "$RootRoute/$bu/tv/livecenter"

companion object : ContentListFactory<TVLiveCenter> {
override val route = "$RootRoute/{bu}/tv/livecenter"
Expand All @@ -172,9 +152,7 @@ sealed interface ContentList {
}

data class TVLiveWeb(override val bu: Bu) : ContentListWithBu {
override fun getDestinationRoute(): String {
return "$RootRoute/$bu/tv/liveweb"
}
override val destinationRoute = "$RootRoute/$bu/tv/liveweb"

companion object : ContentListFactory<TVLiveWeb> {
override val route = "$RootRoute/{bu}/tv/liveweb"
Expand All @@ -187,9 +165,7 @@ sealed interface ContentList {
}

data class RadioLiveStreams(override val bu: Bu) : ContentListWithBu {
override fun getDestinationRoute(): String {
return "$RootRoute/$bu/radio/livestream"
}
override val destinationRoute = "$RootRoute/$bu/radio/livestream"

companion object : ContentListFactory<RadioLiveStreams> {
override val route = "$RootRoute/{bu}/radio/livestream"
Expand All @@ -202,9 +178,7 @@ sealed interface ContentList {
}

data class RadioShows(override val radioChannel: RadioChannel) : ContentListWithRadioChannel {
override fun getDestinationRoute(): String {
return "$RootRoute/${radioChannel.bu}/radio/shows/$radioChannel"
}
override val destinationRoute = "$RootRoute/${radioChannel.bu}/radio/shows/$radioChannel"

companion object : ContentListFactory<RadioShows> {
override val route = "$RootRoute/{bu}/radio/shows/{radioChannel}"
Expand All @@ -217,9 +191,7 @@ sealed interface ContentList {
}

data class RadioLatestMedias(override val radioChannel: RadioChannel) : ContentListWithRadioChannel {
override fun getDestinationRoute(): String {
return "$RootRoute/${radioChannel.bu}/radio/latestMedia/$radioChannel"
}
override val destinationRoute = "$RootRoute/${radioChannel.bu}/radio/latestMedia/$radioChannel"

companion object : ContentListFactory<RadioLatestMedias> {
override val route = "$RootRoute/{bu}/radio/latestMedia/{radioChannel}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class MainActivity : ComponentActivity() {

var selectedDestination by remember { mutableStateOf(startDestination) }

navController.addOnDestinationChangedListener { _, destination, _ ->
destinations.find { it.route == destination.route }
?.takeIf { it != selectedDestination }
?.let { selectedDestination = it }
}

TVDemoTopBar(
destinations = destinations,
selectedDestination = selectedDestination,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ import androidx.compose.ui.unit.dp
import androidx.tv.foundation.PivotOffsets
import androidx.tv.foundation.lazy.list.TvLazyColumn
import androidx.tv.foundation.lazy.list.items
import androidx.tv.material3.ExperimentalTvMaterial3Api
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Surface
import ch.srgssr.pillarbox.demo.shared.data.DemoItem
import ch.srgssr.pillarbox.demo.shared.data.Playlist
import ch.srgssr.pillarbox.demo.tv.item.DemoItemView
import ch.srgssr.pillarbox.demo.tv.item.PlaylistHeader
import ch.srgssr.pillarbox.demo.tv.ui.theme.PillarboxTheme

/**
* Examples home
Expand Down Expand Up @@ -70,13 +68,10 @@ fun ExamplesHome(
}
}

@OptIn(ExperimentalTvMaterial3Api::class)
@Preview
@Composable
private fun ExamplesPreview() {
MaterialTheme() {
Surface {
ExamplesHome()
}
PillarboxTheme {
ExamplesHome()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.tv.material3.CardScale
import androidx.tv.material3.ExperimentalTvMaterial3Api
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Text
import ch.srgssr.pillarbox.demo.tv.ui.theme.PillarboxTheme

/**
* Demo item view
Expand Down Expand Up @@ -66,11 +67,10 @@ fun DemoItemView(
}
}

@OptIn(ExperimentalTvMaterial3Api::class)
@Preview
@Composable
private fun DemoItemPreview() {
MaterialTheme {
PillarboxTheme {
Column(
modifier = Modifier
.width(400.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.Modifier
import androidx.media3.session.MediaSession
import androidx.tv.material3.ExperimentalTvMaterial3Api
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Surface
import ch.srgssr.pillarbox.demo.shared.data.DemoItem
import ch.srgssr.pillarbox.demo.shared.di.PlayerModule
import ch.srgssr.pillarbox.demo.tv.player.compose.TvPlayerView
import ch.srgssr.pillarbox.demo.tv.ui.theme.PillarboxTheme
import ch.srgssr.pillarbox.player.PillarboxPlayer

/**
Expand Down Expand Up @@ -51,7 +51,7 @@ class PlayerActivity : ComponentActivity() {
}

setContent {
MaterialTheme {
PillarboxTheme {
Surface(modifier = Modifier.fillMaxSize()) {
TvPlayerView(player = player)
}
Expand Down
Loading

0 comments on commit 1480acd

Please sign in to comment.