diff --git a/features/playlist/src/main/java/com/m3u/features/playlist/components/ImmersiveBackground.kt b/features/playlist/src/main/java/com/m3u/features/playlist/components/ImmersiveBackground.kt index 350ff7352..d24f32527 100644 --- a/features/playlist/src/main/java/com/m3u/features/playlist/components/ImmersiveBackground.kt +++ b/features/playlist/src/main/java/com/m3u/features/playlist/components/ImmersiveBackground.kt @@ -26,6 +26,7 @@ import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.Dp +import androidx.tv.material3.LocalContentColor import androidx.tv.material3.MaterialTheme import androidx.tv.material3.Text import coil.compose.AsyncImage @@ -111,6 +112,7 @@ internal fun ImmersiveBackground( text = it.readText(), style = MaterialTheme.typography.headlineMedium, fontWeight = FontWeight.SemiBold, + color = LocalContentColor.current.copy(0.67f), maxLines = 1 ) } diff --git a/features/stream/src/main/java/com/m3u/features/stream/components/PlayerPanel.kt b/features/stream/src/main/java/com/m3u/features/stream/components/PlayerPanel.kt index 6a2b56f22..af9e8d4c1 100644 --- a/features/stream/src/main/java/com/m3u/features/stream/components/PlayerPanel.kt +++ b/features/stream/src/main/java/com/m3u/features/stream/components/PlayerPanel.kt @@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.LazyRow +import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.shape.AbsoluteRoundedCornerShape import androidx.compose.material3.Card @@ -30,6 +31,8 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.paging.compose.LazyPagingItems import androidx.tv.material3.surfaceColorAtElevation +import com.m3u.core.util.collections.indexOf +import com.m3u.data.database.model.Episode import com.m3u.data.database.model.Programme import com.m3u.data.database.model.ProgrammeRange import com.m3u.data.database.model.Stream @@ -104,8 +107,8 @@ internal fun PlayerPanel( if (!isSeriesPlaylist) { ChannelGallery( - channels = channels, - streamId = streamId, + // TODO + value = ChannelGalleryValue.PagingChannel(channels, streamId), isPanelExpanded = isPanelExpanded ) } @@ -123,22 +126,16 @@ internal fun PlayerPanel( } @Composable -// TODO: Support Xtream Series Episodes. private fun ChannelGallery( - channels: LazyPagingItems, - streamId: Int, + value: ChannelGalleryValue, isPanelExpanded: Boolean, modifier: Modifier = Modifier ) { val spacing = LocalSpacing.current - val helper = LocalHelper.current - val lazyListState = rememberLazyListState() - val coroutineScope = rememberCoroutineScope() ScrollToCurrentEffect( - neighboring = channels, - streamId = streamId, + value = value, isPanelExpanded = isPanelExpanded, lazyListState = lazyListState ) @@ -149,18 +146,42 @@ private fun ChannelGallery( contentPadding = PaddingValues(spacing.medium), modifier = modifier ) { - items(channels.itemCount) { i -> - channels[i]?.let { stream -> - val isPlaying = stream.id == streamId - ChannelGalleryItem( - stream = stream, - isPlaying = isPlaying - ) + when (value) { + is ChannelGalleryValue.PagingChannel -> { + val channels = value.channels + val streamId = value.streamId + items(channels.itemCount) { i -> + channels[i]?.let { stream -> + val isPlaying = stream.id == streamId + ChannelGalleryItem( + stream = stream, + isPlaying = isPlaying + ) + } + } + } + + is ChannelGalleryValue.XtreamEpisode -> { + items(value.episodes) { series -> + // TODO + } } } } } +private sealed class ChannelGalleryValue { + data class PagingChannel( + val channels: LazyPagingItems, + val streamId: Int + ) : ChannelGalleryValue() + + data class XtreamEpisode( + val episodes: List, + val seriesId: Int + ) : ChannelGalleryValue() +} + @Composable private fun ChannelGalleryItem( stream: Stream, @@ -231,23 +252,39 @@ private fun ChannelGalleryItem( @Composable private fun ScrollToCurrentEffect( - neighboring: LazyPagingItems, - streamId: Int, + value: ChannelGalleryValue, isPanelExpanded: Boolean, lazyListState: LazyListState, scrollOffset: Int = -120 ) { if (isPanelExpanded) { - LaunchedEffect(neighboring.itemCount) { - var index = -1 - for (i in 0 until neighboring.itemCount) { - if (neighboring[i]?.id == streamId) { - index = i - break + when (value) { + is ChannelGalleryValue.PagingChannel -> { + val channels = value.channels + val streamId = value.streamId + LaunchedEffect(channels.itemCount) { + var index = -1 + for (i in 0 until channels.itemCount) { + if (channels[i]?.id == streamId) { + index = i + break + } + } + if (index != -1) { + lazyListState.animateScrollToItem(index, scrollOffset) + } } } - if (index != -1) { - lazyListState.animateScrollToItem(index, scrollOffset) + + is ChannelGalleryValue.XtreamEpisode -> { + val episodes = value.episodes + val seriesId = value.seriesId + LaunchedEffect(episodes.size) { + val index = episodes.indexOf { it.id == seriesId } + if (index != -1) { + lazyListState.animateScrollToItem(index, scrollOffset) + } + } } } } diff --git a/features/stream/src/main/java/com/m3u/features/stream/components/ProgrammeGuide.kt b/features/stream/src/main/java/com/m3u/features/stream/components/ProgrammeGuide.kt index 733a4ae86..f02331180 100644 --- a/features/stream/src/main/java/com/m3u/features/stream/components/ProgrammeGuide.kt +++ b/features/stream/src/main/java/com/m3u/features/stream/components/ProgrammeGuide.kt @@ -286,7 +286,6 @@ private fun ProgrammeCell( ) { val spacing = LocalSpacing.current val preferences = hiltPreferences() - val coroutineScope = rememberCoroutineScope() val tv = isTelevision() val clockMode = preferences.twelveHourClock val content = @Composable {