diff --git a/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/data/Playlist.kt b/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/data/Playlist.kt index e164b0a15..01343914c 100644 --- a/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/data/Playlist.kt +++ b/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/data/Playlist.kt @@ -185,9 +185,7 @@ data class Playlist(val title: String, val items: List, val descriptio DemoItem.OnDemandHorizontalVideo, DemoItem.OnDemandSquareVideo, DemoItem.OnDemandVerticalVideo, - DemoItem.TokenProtectedVideo, DemoItem.SuperfluouslyTokenProtectedVideo, - DemoItem.DrmProtectedVideo, DemoItem.LiveVideo, DemoItem.DvrVideo, DemoItem.DvrAudio, diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/examples/ExampleViewModel.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/examples/ExampleViewModel.kt new file mode 100644 index 000000000..cf7ac3e31 --- /dev/null +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/examples/ExampleViewModel.kt @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023. SRG SSR. All rights reserved. + * License information is available from the LICENSE file. + */ +package ch.srgssr.pillarbox.demo.ui.examples + +import android.app.Application +import androidx.lifecycle.AndroidViewModel +import androidx.lifecycle.viewModelScope +import ch.srg.dataProvider.integrationlayer.request.parameters.Bu +import ch.srgssr.pillarbox.demo.shared.data.DemoItem +import ch.srgssr.pillarbox.demo.shared.data.Playlist +import ch.srgssr.pillarbox.demo.ui.integrationLayer.data.ILRepository +import ch.srgssr.pillarbox.demo.ui.integrationLayer.di.IntegrationLayerModule +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.stateIn + +/** + * Example view model + * + * @param application Android Application to create [ILRepository] + */ +class ExampleViewModel(application: Application) : AndroidViewModel(application) { + private val repository: ILRepository = IntegrationLayerModule.createIlRepository(application) + + /** + * Contents to display + */ + val contents: StateFlow> = flow { + val listDrmContent = repository.getLatestMediaByShowUrn(SHOW_URN, 2).getOrDefault(emptyList()) + val listTokenProtectedContent = repository.getTvLiveCenter(Bu.RTS, 2).getOrDefault(emptyList()) + val playlist = Playlist( + title = PROTECTED_CONTENT_TITLE, + items = (listDrmContent + listTokenProtectedContent).map { DemoItem(title = it.title, description = it.lead, uri = it.urn) } + ) + emit(LIST_STATIC_PLAYLIST + playlist) + }.stateIn(viewModelScope, started = SharingStarted.Eagerly, LIST_STATIC_PLAYLIST) + + companion object { + private const val SHOW_URN = "urn:rts:show:tv:532539" + private const val PROTECTED_CONTENT_TITLE = "Protected contents" + + private val LIST_STATIC_PLAYLIST = listOf( + Playlist.StreamUrls, + Playlist.StreamUrns, + Playlist.PlaySuisseStreams, + Playlist.StreamApples, + Playlist.StreamGoogles, + Playlist.BitmovinSamples, + Playlist.UnifiedStreaming, + Playlist.UnifiedStreamingDash, + ) + } +} diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/examples/ExamplesHome.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/examples/ExamplesHome.kt index c664cd6b8..5cdf2095d 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/examples/ExamplesHome.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/examples/ExamplesHome.kt @@ -16,13 +16,14 @@ import androidx.compose.material3.Card import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember +import androidx.compose.runtime.collectAsState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import androidx.lifecycle.viewmodel.compose.viewModel import ch.srgssr.pillarbox.demo.BuildConfig import ch.srgssr.pillarbox.demo.shared.data.DemoItem import ch.srgssr.pillarbox.demo.shared.data.Playlist @@ -38,20 +39,10 @@ import ch.srgssr.pillarbox.demo.ui.theme.PillarboxTheme */ @Composable fun ExamplesHome() { + val exampleViewModel: ExampleViewModel = viewModel() val context = LocalContext.current - val listItems = remember { - listOf( - Playlist.StreamUrls, - Playlist.StreamUrns, - Playlist.PlaySuisseStreams, - Playlist.StreamApples, - Playlist.StreamGoogles, - Playlist.BitmovinSamples, - Playlist.UnifiedStreaming, - Playlist.UnifiedStreamingDash, - ) - } - ListStreamView(playlistList = listItems) { + val listItems = exampleViewModel.contents.collectAsState() + ListStreamView(playlistList = listItems.value) { SimplePlayerActivity.startActivity(context, it) } } @@ -90,7 +81,12 @@ private fun ListStreamView(playlistList: List, onItemClicked: (DemoIte } } } - Box(modifier = Modifier.fillMaxWidth().padding(12.dp), contentAlignment = Alignment.Center) { + Box( + modifier = Modifier + .fillMaxWidth() + .padding(12.dp), + contentAlignment = Alignment.Center + ) { Text(text = BuildConfig.VERSION_NAME, style = MaterialTheme.typography.bodyLarge, fontStyle = FontStyle.Italic) } } diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/data/ILRepository.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/data/ILRepository.kt index 7305e224b..d186c544d 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/data/ILRepository.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/data/ILRepository.kt @@ -17,6 +17,7 @@ import ch.srg.dataProvider.integrationlayer.data.remote.Transmission import ch.srg.dataProvider.integrationlayer.request.IlService import ch.srg.dataProvider.integrationlayer.request.parameters.Bu 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.srgssr.dataprovider.paging.DataProviderPaging import ch.srgssr.dataprovider.paging.datasource.NextUrlPagingSource @@ -98,6 +99,17 @@ class ILRepository( return dataProviderPaging.getLatestMediaByShowUrn(showUrn = urn, pageSize = PAGE_SIZE) } + /** + * Get latest media by show urn + * + * @param urn + * @param pageSize + * @return + */ + suspend fun getLatestMediaByShowUrn(urn: String, pageSize: Int): Result> { + return runCatching { ilService.getLatestMediaByShowUrn(urn, pageSize.toIlPaging()).list } + } + /** * Get latest media by topic urn * @@ -153,6 +165,17 @@ class ILRepository( return dataProviderPaging.getLiveCenterVideos(bu = bu, pageSize = PAGE_SIZE, type = LiveCenterType.SCHEDULED_LIVESTREAM) } + /** + * Get tv live center + * + * @param bu + * @param pageSize + * @return + */ + suspend fun getTvLiveCenter(bu: Bu, pageSize: Int): Result> { + return runCatching { ilService.getLiveCenterVideos(bu = bu, pageSize = pageSize.toIlPaging()).list } + } + /** * Search *