package tv.tivilux.nativeplayer.ui.screens import androidx.activity.compose.BackHandler import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.clickable import androidx.compose.foundation.focusable import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.focus.onFocusChanged import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.key.Key import androidx.compose.ui.input.key.KeyEventType import androidx.compose.ui.input.key.key import androidx.compose.ui.input.key.onPreviewKeyEvent import androidx.compose.ui.input.key.type import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import kotlinx.coroutines.delay import androidx.media3.exoplayer.ExoPlayer import androidx.media3.common.Player import tv.tivilux.nativeplayer.TvRemoteKeyRouter import tv.tivilux.nativeplayer.model.Category import tv.tivilux.nativeplayer.model.ContentType import tv.tivilux.nativeplayer.model.EpgProgram import tv.tivilux.nativeplayer.model.MediaEntry import tv.tivilux.nativeplayer.data.SupportReportContext import tv.tivilux.nativeplayer.ui.components.VideoSurface import tv.tivilux.nativeplayer.ui.components.SupportIssue import tv.tivilux.nativeplayer.ui.components.SupportReportDialog import tv.tivilux.nativeplayer.ui.theme.LuxGold import tv.tivilux.nativeplayer.ui.theme.LuxLine import tv.tivilux.nativeplayer.ui.theme.LuxMuted import tv.tivilux.nativeplayer.ui.theme.LuxPanel import tv.tivilux.nativeplayer.ui.theme.LuxText import java.text.SimpleDateFormat import java.util.Date import java.util.Locale enum class LivePlayerPanel { NONE, CHANNELS, GROUPS, CONTROLS, HISTORY } enum class LiveInfoPlacement { NONE, BOTTOM, TOP_RIGHT } @androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class) @Composable fun PlayerScreen( item: MediaEntry?, url: String?, urlCandidates: List = emptyList(), bufferPreset: String, livePlayer: ExoPlayer, vodPlayer: ExoPlayer, initialPositionMs: Long = 0L, videoSurfaceOwnedExternally: Boolean = false, remoteShortcutsEnabled: Boolean, showFullscreenClock: Boolean = true, fullscreenClockSize: String = "Medium", fullscreenClockPosition: String = "Top Right", liveChannels: List, liveCategories: List, recentChannels: List, selectedLiveCategory: String?, epgByChannel: Map>, isFavorite: Boolean, accountHint: String = "", profileName: String = "", launchedFromSports: Boolean = false, onBack: () -> Unit, onOpenGuide: () -> Unit, onOpenSearch: () -> Unit, onOpenSettings: () -> Unit, onPreviousChannel: () -> Unit, onChannelUp: () -> Unit, onChannelDown: () -> Unit, onTuneChannel: (MediaEntry) -> Unit, onSelectCategory: (String?) -> Unit, onToggleFavorite: () -> Unit, onRemoveFromHistory: () -> Unit, onPlaybackProgress: (Long, Long, Boolean) -> Unit, ) { val liveMode = item?.type == ContentType.LIVE val vodCandidates = remember(item?.id, url, urlCandidates) { (urlCandidates + listOfNotNull(url)).filter { it.isNotBlank() }.distinct() } var vodCandidateIndex by remember(item?.id, vodCandidates) { mutableStateOf(0) } val playbackUrl = if (liveMode) url else vodCandidates.getOrNull(vodCandidateIndex) ?: url var panel by remember { mutableStateOf(LivePlayerPanel.NONE) } var infoPlacement by remember { mutableStateOf(LiveInfoPlacement.NONE) } var heldKey by remember { mutableStateOf(null) } var longActionFired by remember { mutableStateOf(false) } var statusMessage by remember { mutableStateOf(null) } var showSupportReport by remember { mutableStateOf(false) } var hudVisible by remember { mutableStateOf(liveMode) } var vodHudVisible by remember(item?.id) { mutableStateOf(!liveMode) } var vodHudRefresh by remember { mutableStateOf(0) } var vodTransportFeedback by remember(item?.id) { mutableStateOf(null) } var vodTransportFeedbackRefresh by remember { mutableStateOf(0) } var vodSeekAccumulatorSeconds by remember(item?.id) { mutableStateOf(0) } var vodSeekBurstBasePositionMs by remember(item?.id) { mutableStateOf(0L) } var vodPositionMs by remember(item?.id) { mutableStateOf(0L) } var vodDurationMs by remember(item?.id) { mutableStateOf(0L) } var vodBufferedPositionMs by remember(item?.id) { mutableStateOf(0L) } var hudRefresh by remember { mutableStateOf(0) } var guideTransitionLocked by remember { mutableStateOf(false) } // Fullscreen playback needs its own stable focus owner. When the HUD auto-hides, // focus previously remained on a tile that was removed from composition (or on the // warm guide behind the player), so DPAD_RIGHT never reached PlayerScreen. val fullscreenFocusRequester = remember { FocusRequester() } val currentChannelPrograms = item?.let { epgByChannel[it.id] }.orEmpty() val currentProgram = remember(item?.id, currentChannelPrograms) { val now = System.currentTimeMillis() / 1000L currentChannelPrograms.firstOrNull { now in it.startEpoch until it.endEpoch } } LaunchedEffect(infoPlacement) { if (infoPlacement != LiveInfoPlacement.NONE) { delay(5000) infoPlacement = LiveInfoPlacement.NONE } } LaunchedEffect(statusMessage) { if (statusMessage != null) { delay(2200) statusMessage = null } } LaunchedEffect(hudRefresh, panel, liveMode) { if (liveMode && panel == LivePlayerPanel.NONE && hudVisible) { delay(5000) if (panel == LivePlayerPanel.NONE) hudVisible = false } } LaunchedEffect(item?.id, liveMode) { if (!liveMode) { vodHudVisible = true vodHudRefresh++ } } LaunchedEffect(vodHudRefresh, item?.id, liveMode) { if (!liveMode && vodHudVisible) { delay(4500) vodHudVisible = false } } LaunchedEffect(vodTransportFeedbackRefresh, item?.id, liveMode) { if (!liveMode && vodTransportFeedback != null) { delay(650) vodTransportFeedback = null vodSeekAccumulatorSeconds = 0 vodSeekBurstBasePositionMs = vodPlayer.currentPosition.coerceAtLeast(0L) } } // Only sample UI progress while its HUD is visible. Resume/history persistence // below reads the player directly and keeps its independent ten-second cadence. LaunchedEffect(item?.id, liveMode, vodPlayer, vodHudVisible) { if (liveMode || item == null || !vodHudVisible) return@LaunchedEffect while (true) { vodPositionMs = vodPlayer.currentPosition.coerceAtLeast(0L) vodDurationMs = vodPlayer.duration.takeIf { it > 0L } ?: 0L vodBufferedPositionMs = vodPlayer.bufferedPosition.coerceAtLeast(vodPositionMs) delay(350) } } LaunchedEffect(item?.id, liveMode, vodPlayer) { if (liveMode || item == null) return@LaunchedEffect while (true) { delay(10_000) val duration = vodPlayer.duration.takeIf { it > 0L } ?: 0L onPlaybackProgress(vodPlayer.currentPosition.coerceAtLeast(0L), duration, false) } } DisposableEffect(item?.id, liveMode, vodPlayer, vodCandidateIndex, vodCandidates) { if (liveMode || item == null || vodCandidates.size <= 1) { onDispose { } } else { val listener = object : Player.Listener { override fun onPlayerError(error: androidx.media3.common.PlaybackException) { if (vodCandidateIndex < vodCandidates.lastIndex) { vodCandidateIndex += 1 vodTransportFeedback = "Trying alternate VOD stream" } else { vodTransportFeedback = "VOD stream unavailable" } vodTransportFeedbackRefresh++ vodHudVisible = true vodHudRefresh++ } } vodPlayer.addListener(listener) onDispose { vodPlayer.removeListener(listener) } } } DisposableEffect(item?.id, liveMode, vodPlayer) { if (liveMode || item == null) { onDispose { } } else { val listener = object : Player.Listener { override fun onPlaybackStateChanged(playbackState: Int) { if (playbackState == Player.STATE_ENDED) { val duration = vodPlayer.duration.takeIf { it > 0L } ?: vodPlayer.currentPosition onPlaybackProgress(duration.coerceAtLeast(0L), duration.coerceAtLeast(0L), true) } } } vodPlayer.addListener(listener) onDispose { vodPlayer.removeListener(listener) } } } LaunchedEffect(heldKey, liveMode, remoteShortcutsEnabled) { val key = heldKey ?: return@LaunchedEffect if (!liveMode || !remoteShortcutsEnabled) return@LaunchedEffect delay(650) if (heldKey != key || longActionFired) return@LaunchedEffect longActionFired = true when (key) { Key.Enter, Key.DirectionCenter -> panel = LivePlayerPanel.CONTROLS Key.DirectionLeft -> panel = LivePlayerPanel.CHANNELS Key.DirectionRight -> infoPlacement = LiveInfoPlacement.TOP_RIGHT else -> Unit } } fun openGuideOnce() { if (guideTransitionLocked) return guideTransitionLocked = true panel = LivePlayerPanel.NONE hudVisible = false infoPlacement = LiveInfoPlacement.NONE onOpenGuide() } fun handleFullscreenBack() { when { panel != LivePlayerPanel.NONE -> panel = LivePlayerPanel.NONE !liveMode -> { val duration = vodPlayer.duration.takeIf { it > 0L } ?: 0L onPlaybackProgress(vodPlayer.currentPosition.coerceAtLeast(0L), duration, false) onBack() } else -> { // Fullscreen Live TV BACK always returns to the Guide that owns the playing // channel. It never falls through to Home; the Guide keeps the existing // two-step BACK exit behavior from v0.4.22. openGuideOnce() } } } fun seekVodBy(deltaSeconds: Int) { val directionChanged = (vodSeekAccumulatorSeconds > 0 && deltaSeconds < 0) || (vodSeekAccumulatorSeconds < 0 && deltaSeconds > 0) if (vodSeekAccumulatorSeconds == 0 || directionChanged) { vodSeekBurstBasePositionMs = vodPlayer.currentPosition.coerceAtLeast(0L) vodSeekAccumulatorSeconds = 0 } vodSeekAccumulatorSeconds += deltaSeconds val duration = vodPlayer.duration.takeIf { it > 0L } ?: Long.MAX_VALUE val targetPosition = ( vodSeekBurstBasePositionMs + (vodSeekAccumulatorSeconds * 1_000L) ).coerceIn(0L, duration) // Seek from the captured burst base instead of repeatedly trusting ExoPlayer's // asynchronously-updated currentPosition. Rapid presses now share one exact seek base. vodPlayer.seekTo(targetPosition) vodPositionMs = targetPosition vodTransportFeedback = if (vodSeekAccumulatorSeconds < 0) { "${kotlin.math.abs(vodSeekAccumulatorSeconds)}s back" } else { "${vodSeekAccumulatorSeconds}s forward" } vodTransportFeedbackRefresh++ vodHudVisible = true vodHudRefresh++ } fun openSupportReport() { // The support dialog is a true modal. Remove the Live TV HUD/control deck from the // focus/input path before showing it so DPAD events cannot continue operating the // quick-map buttons behind the dialog. Playback itself remains untouched. heldKey = null longActionFired = false panel = LivePlayerPanel.NONE hudVisible = false infoPlacement = LiveInfoPlacement.NONE showSupportReport = true } // Activity-level routing normalizes Google Streamer / Google TV / onn. / Shield / Fire TV // hardware keys. UP/DOWN always surf channels in fullscreen instead of moving focus into // the bottom HUD. Dedicated CHANNEL_UP/DOWN buttons are mapped to the same actions. DisposableEffect(liveMode, panel, hudVisible, remoteShortcutsEnabled, item?.id, showSupportReport) { if (liveMode && remoteShortcutsEnabled && panel == LivePlayerPanel.NONE && !showSupportReport) { TvRemoteKeyRouter.fullscreenChannelUpHandler = { hudVisible = false infoPlacement = LiveInfoPlacement.NONE onChannelUp() true } TvRemoteKeyRouter.fullscreenChannelDownHandler = { hudVisible = false infoPlacement = LiveInfoPlacement.NONE onChannelDown() true } } else { TvRemoteKeyRouter.fullscreenChannelUpHandler = null TvRemoteKeyRouter.fullscreenChannelDownHandler = null } if (liveMode && remoteShortcutsEnabled && panel == LivePlayerPanel.NONE && !hudVisible && !showSupportReport) { TvRemoteKeyRouter.hiddenFullscreenRightHandler = { onPreviousChannel() true } } else { TvRemoteKeyRouter.hiddenFullscreenRightHandler = null } onDispose { TvRemoteKeyRouter.hiddenFullscreenRightHandler = null TvRemoteKeyRouter.fullscreenChannelUpHandler = null TvRemoteKeyRouter.fullscreenChannelDownHandler = null } } // Reclaim focus whenever fullscreen has no modal panel and the HUD is hidden. // This makes hardware DPAD events deterministic even after the HUD disappears. LaunchedEffect(liveMode, panel, hudVisible, item?.id, showSupportReport) { if (!showSupportReport && (!liveMode || (panel == LivePlayerPanel.NONE && !hudVisible))) { delay(40) runCatching { fullscreenFocusRequester.requestFocus() } } } BackHandler(enabled = !showSupportReport) { handleFullscreenBack() } Box( Modifier .fillMaxSize() .background(if (videoSurfaceOwnedExternally) Color.Transparent else Color.Black) .focusRequester(fullscreenFocusRequester) .focusable() .onPreviewKeyEvent { event -> // Support reporting is modal. Never let the fullscreen quick-map shortcuts // consume DPAD/OK while the report dialog owns focus. Returning false here // allows the focused controls inside SupportReportDialog to receive the event. if (showSupportReport) return@onPreviewKeyEvent false // VOD playback controls are player-level shortcuts. They work even with // every overlay hidden: LEFT/RIGHT perform a quick 10-second seek and OK toggles pause. if (!liveMode) { if (event.type != KeyEventType.KeyDown) { return@onPreviewKeyEvent event.key in setOf( Key.DirectionLeft, Key.DirectionRight, Key.Enter, Key.DirectionCenter ) } when (event.key) { Key.DirectionLeft -> { seekVodBy(-10) true } Key.DirectionRight -> { seekVodBy(10) true } Key.Enter, Key.DirectionCenter -> { vodSeekAccumulatorSeconds = 0 if (vodPlayer.isPlaying) { vodPlayer.pause() vodTransportFeedback = "Paused" } else { vodPlayer.play() vodTransportFeedback = "Playing" } vodTransportFeedbackRefresh++ vodHudVisible = true vodHudRefresh++ true } else -> false } } else { if (!remoteShortcutsEnabled) return@onPreviewKeyEvent false // LEFT from clean fullscreen is a direct one-press Groups shortcut. // Do not reveal the bottom HUD first and do not require LEFT twice. if (panel == LivePlayerPanel.NONE && event.key == Key.DirectionLeft) { when (event.type) { KeyEventType.KeyDown -> { hudVisible = false infoPlacement = LiveInfoPlacement.NONE heldKey = null longActionFired = false } KeyEventType.KeyUp -> panel = LivePlayerPanel.GROUPS else -> Unit } return@onPreviewKeyEvent true } // If Activity-level routing is unavailable (keyboard/emulator/etc.), keep // the same rule here: fullscreen UP/DOWN surf channels and never open HUD. if (panel == LivePlayerPanel.NONE && event.key in setOf(Key.DirectionUp, Key.DirectionDown)) { if (event.type == KeyEventType.KeyUp) { hudVisible = false infoPlacement = LiveInfoPlacement.NONE if (event.key == Key.DirectionUp) onChannelUp() else onChannelDown() } return@onPreviewKeyEvent true } if (panel != LivePlayerPanel.NONE) { if (panel == LivePlayerPanel.CHANNELS && event.key == Key.DirectionLeft) { if (event.type == KeyEventType.KeyUp) panel = LivePlayerPanel.GROUPS return@onPreviewKeyEvent true } if (panel == LivePlayerPanel.GROUPS && event.key == Key.DirectionRight) { if (event.type == KeyEventType.KeyUp) panel = LivePlayerPanel.CHANNELS return@onPreviewKeyEvent true } return@onPreviewKeyEvent false } // Hidden-HUD RIGHT is handled at Activity level by TvRemoteKeyRouter. // IMPORTANT: when the HUD is visible, do NOT consume RIGHT here; the focused // HUD tile must receive LEFT/RIGHT so the user can navigate to Favorites, // Guide, History, Search, Settings, recent channels, etc. if (hudVisible) { if (event.key in setOf( Key.Enter, Key.DirectionCenter, Key.DirectionLeft, Key.DirectionRight, Key.DirectionUp, Key.DirectionDown ) ) return@onPreviewKeyEvent false } val actionable = event.key in setOf( Key.Enter, Key.DirectionCenter, Key.DirectionLeft, ) if (!actionable) return@onPreviewKeyEvent false when (event.type) { KeyEventType.KeyDown -> { hudVisible = true hudRefresh++ if (heldKey == null) { heldKey = event.key longActionFired = false } true } KeyEventType.KeyUp -> { val key = heldKey ?: event.key val wasLong = longActionFired heldKey = null longActionFired = false if (!wasLong) { when (key) { Key.Enter, Key.DirectionCenter -> { hudVisible = true hudRefresh++ } Key.DirectionLeft -> panel = LivePlayerPanel.CHANNELS else -> Unit } } true } else -> true } } } ) { if (!videoSurfaceOwnedExternally) { VideoSurface( url = playbackUrl, modifier = Modifier.fillMaxSize(), autoPlay = true, controller = false, bufferPreset = bufferPreset, preferSurfaceView = true, externalPlayer = if (liveMode) livePlayer else vodPlayer, startPositionMs = if (liveMode) 0L else initialPositionMs, ) } val showLiveHud = liveMode && panel == LivePlayerPanel.NONE && hudVisible if (!liveMode && vodHudVisible) { VodPlaybackHud( item = item, player = vodPlayer, positionMs = vodPositionMs, durationMs = vodDurationMs, bufferedPositionMs = vodBufferedPositionMs, transportFeedback = vodTransportFeedback, ) } else if (showLiveHud) { // The top-left channel/program bug belongs to the same HUD as the bottom tiles. // They now appear and disappear together, leaving completely clean fullscreen video. LiveNowBug(item, currentProgram) } when (infoPlacement) { LiveInfoPlacement.BOTTOM -> ProgramInfoBottom(item, currentProgram) LiveInfoPlacement.TOP_RIGHT -> ProgramInfoTopRight(item, currentProgram) LiveInfoPlacement.NONE -> Unit } when (panel) { LivePlayerPanel.CHANNELS -> ChannelListPanel( channels = liveChannels, current = item, epgByChannel = epgByChannel, onTune = onTuneChannel, onClose = { panel = LivePlayerPanel.NONE }, ) LivePlayerPanel.GROUPS -> GroupListPanel( categories = liveCategories, selectedCategory = selectedLiveCategory, onSelect = { categoryId -> onSelectCategory(categoryId) panel = LivePlayerPanel.CHANNELS }, onClose = { panel = LivePlayerPanel.NONE }, ) LivePlayerPanel.CONTROLS -> ControlDeckPanel( item = item, program = currentProgram, recentChannels = recentChannels, isFavorite = isFavorite, onGuide = { openGuideOnce() }, onHistory = { panel = LivePlayerPanel.HISTORY }, onFavorite = onToggleFavorite, onSearch = onOpenSearch, onReport = { openSupportReport() }, onSettings = onOpenSettings, onTune = { channel -> onTuneChannel(channel) panel = LivePlayerPanel.NONE hudVisible = true hudRefresh++ }, onClose = { panel = LivePlayerPanel.NONE }, ) LivePlayerPanel.HISTORY -> HistoryPanel( channels = recentChannels, current = item, epgByChannel = epgByChannel, onTune = { channel -> onTuneChannel(channel) panel = LivePlayerPanel.NONE hudVisible = true hudRefresh++ }, onClose = { panel = LivePlayerPanel.CONTROLS }, ) LivePlayerPanel.NONE -> Unit } if (showLiveHud) { LiveControlHud( item = item, program = currentProgram, recentChannels = recentChannels, isFavorite = isFavorite, onGuide = { openGuideOnce() }, onHistory = { hudVisible = false panel = LivePlayerPanel.HISTORY }, onFavorite = onToggleFavorite, onSearch = onOpenSearch, onReport = { openSupportReport() }, onSettings = onOpenSettings, onTune = { channel -> onTuneChannel(channel) hudVisible = true hudRefresh++ }, onClose = { hudVisible = false }, onInteraction = { hudRefresh++ }, ) } // Always-on, non-focusable device clock for fullscreen LIVE playback only. // Overlay-only: does not modify player, stream, or remote key handling. if (liveMode && showFullscreenClock) { var clockText by remember { mutableStateOf("") } LaunchedEffect(Unit) { val formatter = SimpleDateFormat("h:mm a", Locale.getDefault()) while (true) { clockText = formatter.format(Date()) delay(1_000L * (60 - (System.currentTimeMillis() / 1_000L) % 60)) } } Box( modifier = Modifier .align(when (fullscreenClockPosition) { "Top Left" -> Alignment.TopStart "Bottom Left" -> Alignment.BottomStart "Bottom Right" -> Alignment.BottomEnd else -> Alignment.TopEnd }) .padding( start = if (fullscreenClockPosition.endsWith("Left")) 24.dp else 0.dp, end = if (fullscreenClockPosition.endsWith("Right")) 24.dp else 0.dp, top = if (fullscreenClockPosition.startsWith("Top")) 20.dp else 0.dp, bottom = if (fullscreenClockPosition.startsWith("Bottom")) 20.dp else 0.dp ) // Transparent, non-interactive text-only overlay; TV-safe margins. ) { Text(text = clockText, color = Color.White, fontSize = when (fullscreenClockSize) { "Small" -> 15.sp; "Large" -> 27.sp; else -> 20.sp }, fontWeight = FontWeight.SemiBold, style = androidx.compose.ui.text.TextStyle(shadow = androidx.compose.ui.graphics.Shadow(color = Color.Black.copy(alpha = 0.85f), blurRadius = 4f))) } } if (showSupportReport) { val activePlayer = if (liveMode) livePlayer else vodPlayer val format = activePlayer.videoFormat val playerState = when (activePlayer.playbackState) { Player.STATE_BUFFERING -> "Buffering" Player.STATE_READY -> if (activePlayer.isPlaying) "Playing" else "Ready / Paused" Player.STATE_ENDED -> "Ended" else -> "Idle" } SupportReportDialog( details = SupportReportContext( accountHint = accountHint, profile = profileName, channelName = item?.name.orEmpty(), channelNumber = item?.number?.takeIf { it > 0 }?.toString().orEmpty(), program = currentProgram?.title.orEmpty(), contentType = item?.type?.name.orEmpty(), sportsEvent = if (launchedFromSports) currentProgram?.title.orEmpty() else "", sportsFeed = if (launchedFromSports) item?.name.orEmpty() else "", resolution = format?.takeIf { it.width > 0 && it.height > 0 }?.let { "${it.width}x${it.height}" }.orEmpty(), codec = format?.sampleMimeType.orEmpty(), playerState = playerState, bufferedPercent = activePlayer.bufferedPercentage.takeIf { it >= 0 }?.toString().orEmpty(), ), initialIssue = when { launchedFromSports -> SupportIssue.SPORTS liveMode -> SupportIssue.BUFFERING else -> SupportIssue.VOD }, onDismiss = { showSupportReport = false hudVisible = false }, ) } statusMessage?.let { message -> Box( Modifier.align(Alignment.BottomCenter).padding(bottom = 34.dp) .background(Color(0xE811161C), RoundedCornerShape(10.dp)) .border(1.dp, LuxLine, RoundedCornerShape(10.dp)) .padding(horizontal = 16.dp, vertical = 10.dp) ) { Text(message, color = LuxText, fontSize = 11.sp, fontWeight = FontWeight.SemiBold) } } } } @androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class) @Composable private fun BoxScope.VodPlaybackHud( item: MediaEntry?, player: ExoPlayer, positionMs: Long, durationMs: Long, bufferedPositionMs: Long, transportFeedback: String?, ) { val safeDuration = durationMs.coerceAtLeast(0L) val safePosition = positionMs.coerceIn(0L, if (safeDuration > 0L) safeDuration else Long.MAX_VALUE) val fraction = if (safeDuration > 0L) { (safePosition.toFloat() / safeDuration.toFloat()).coerceIn(0f, 1f) } else 0f val bufferedFraction = if (safeDuration > 0L) { (bufferedPositionMs.coerceAtLeast(safePosition).toFloat() / safeDuration.toFloat()).coerceIn(0f, 1f) } else 0f val title = when { item == null -> "TiviLux Player" item.type == ContentType.EPISODE && item.seriesName.isNotBlank() && item.season > 0 && item.episodeNumber > 0 -> "${item.seriesName} - S${item.season.toString().padStart(2, '0')}E${item.episodeNumber.toString().padStart(2, '0')} - ${item.name}" item.type == ContentType.EPISODE && item.seriesName.isNotBlank() -> "${item.seriesName} - ${item.name}" else -> item.name } val videoFormat = player.videoFormat Text( SimpleDateFormat("EEE, MMM d, h:mm a", Locale.getDefault()).format(Date()), color = Color.White.copy(alpha = .88f), fontSize = 10.sp, modifier = Modifier.align(Alignment.TopEnd).padding(top = 18.dp, end = 24.dp), ) Column( Modifier.align(Alignment.BottomCenter) .fillMaxWidth() .background( Brush.verticalGradient( listOf( Color.Transparent, Color.Black.copy(alpha = .58f), Color.Black.copy(alpha = .94f), ) ) ) .padding(start = 34.dp, end = 34.dp, top = 64.dp, bottom = 24.dp), verticalArrangement = Arrangement.spacedBy(10.dp), ) { Row( Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically, ) { Text( title, color = Color.White, fontSize = 19.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f).padding(end = 14.dp), ) Row(horizontalArrangement = Arrangement.spacedBy(5.dp)) { if (videoFormat != null && videoFormat.width > 0 && videoFormat.height > 0) { VodTechBadge("${videoFormat.width}x${videoFormat.height}") } if (videoFormat != null && videoFormat.frameRate > 0f) { VodTechBadge("${videoFormat.frameRate.toInt()} FPS") } } } Box( Modifier.fillMaxWidth().height(4.dp) .background(Color.White.copy(alpha = .16f), RoundedCornerShape(50)) ) { if (bufferedFraction > 0f) { Box( Modifier.fillMaxWidth(bufferedFraction).fillMaxHeight() .background(Color.White.copy(alpha = .34f), RoundedCornerShape(50)) ) } if (fraction > 0f) { Box( Modifier.fillMaxWidth(fraction).fillMaxHeight() .background(LuxGold, RoundedCornerShape(50)) ) } } Row( Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, ) { Text( "${formatPlayerTime(safePosition)} / ${formatPlayerTime(safeDuration)}", color = Color.White, fontSize = 12.sp, fontWeight = FontWeight.SemiBold, modifier = Modifier.weight(1f), ) val stateLabel = transportFeedback ?: if (player.isPlaying) "Playing" else "Paused" Box( Modifier .background(Color.White.copy(alpha = .10f), RoundedCornerShape(20.dp)) .border(1.dp, Color.White.copy(alpha = .10f), RoundedCornerShape(20.dp)) .padding(horizontal = 12.dp, vertical = 5.dp), contentAlignment = Alignment.Center, ) { Text( stateLabel, color = Color.White.copy(alpha = .90f), fontSize = 10.sp, fontWeight = FontWeight.SemiBold, ) } Spacer(Modifier.weight(1f)) } } } @Composable private fun VodTechBadge(text: String) { Box( Modifier.background(Color(0xFFD8EEE8), RoundedCornerShape(3.dp)) .padding(horizontal = 5.dp, vertical = 2.dp) ) { Text(text, color = Color(0xFF23333A), fontSize = 7.sp, fontWeight = FontWeight.Bold) } } private fun formatPlayerTime(valueMs: Long): String { if (valueMs <= 0L) return "0:00" val totalSeconds = valueMs / 1000L val hours = totalSeconds / 3600L val minutes = (totalSeconds % 3600L) / 60L val seconds = totalSeconds % 60L return if (hours > 0L) { "%d:%02d:%02d".format(Locale.US, hours, minutes, seconds) } else { "%d:%02d".format(Locale.US, minutes, seconds) } } @Composable private fun LiveNowBug(item: MediaEntry?, program: EpgProgram?) { Column( Modifier.padding(18.dp) .background(Color.Black.copy(alpha = .62f), RoundedCornerShape(10.dp)) .padding(horizontal = 12.dp, vertical = 8.dp) ) { Text(item?.name ?: "LIVE TV", color = LuxText, fontSize = 13.sp, fontWeight = FontWeight.SemiBold) if (program != null) { Text(program.title, color = LuxMuted, fontSize = 10.sp, maxLines = 1, overflow = TextOverflow.Ellipsis) } } } @Composable private fun ChannelListPanel( channels: List, current: MediaEntry?, epgByChannel: Map>, onTune: (MediaEntry) -> Unit, onClose: () -> Unit, ) { val now = System.currentTimeMillis() / 1000L val menuFocus = remember { FocusRequester() } val listState = androidx.compose.foundation.lazy.rememberLazyListState() var selectedIndex by remember(channels, current?.id) { mutableStateOf(channels.indexOfFirst { it.id == current?.id }.takeIf { it >= 0 } ?: 0) } LaunchedEffect(channels.size, current?.id) { if (channels.isNotEmpty()) { selectedIndex = channels.indexOfFirst { it.id == current?.id }.takeIf { it >= 0 } ?: 0 listState.scrollToItem(selectedIndex.coerceIn(0, channels.lastIndex)) } delay(50) runCatching { menuFocus.requestFocus() } } LaunchedEffect(selectedIndex, channels.size) { if (channels.isEmpty()) return@LaunchedEffect val visible = listState.layoutInfo.visibleItemsInfo if (visible.isEmpty() || selectedIndex < visible.first().index || selectedIndex > visible.last().index) { listState.animateScrollToItem(selectedIndex.coerceIn(0, channels.lastIndex)) } } Column( Modifier.fillMaxHeight().width(390.dp) .background(Color(0xF20A0F14)) .border(1.dp, LuxLine) .focusRequester(menuFocus) .focusable() .onPreviewKeyEvent { event -> val handled = event.key in setOf(Key.DirectionUp, Key.DirectionDown, Key.Enter, Key.DirectionCenter) if (!handled) return@onPreviewKeyEvent false if (event.type == KeyEventType.KeyDown) { when (event.key) { Key.DirectionUp -> if (channels.isNotEmpty()) selectedIndex = (selectedIndex - 1).coerceAtLeast(0) Key.DirectionDown -> if (channels.isNotEmpty()) selectedIndex = (selectedIndex + 1).coerceAtMost(channels.lastIndex) Key.Enter, Key.DirectionCenter -> channels.getOrNull(selectedIndex)?.let(onTune) else -> Unit } } true } .padding(14.dp) ) { Text("CHANNELS", color = LuxGold, fontSize = 10.sp, fontWeight = FontWeight.Bold, letterSpacing = 1.4.sp) Text("↑ / ↓ browse • OK tunes • LEFT groups • BACK closes", color = LuxMuted, fontSize = 9.sp, modifier = Modifier.padding(top = 2.dp, bottom = 10.dp)) LazyColumn(Modifier.weight(1f), state = listState, verticalArrangement = Arrangement.spacedBy(4.dp)) { itemsIndexed(channels, key = { _, item -> item.id }) { index, channel -> val program = epgByChannel[channel.id].orEmpty().firstOrNull { now in it.startEpoch until it.endEpoch } ChannelListRow( channel = channel, program = program, current = current?.id == channel.id, selected = index == selectedIndex, ) { selectedIndex = index onTune(channel) } } } Spacer(Modifier.height(8.dp)) Text("BACK • CLOSE", color = LuxMuted, fontSize = 9.sp, fontWeight = FontWeight.Bold) } } @Composable private fun ChannelListRow( channel: MediaEntry, program: EpgProgram?, current: Boolean, selected: Boolean, onClick: () -> Unit, ) { Row( Modifier.fillMaxWidth() .background( when { selected -> Color(0xFF253746) current -> Color(0xFF172630) else -> Color.Transparent }, RoundedCornerShape(8.dp) ) .border(1.dp, if (selected) LuxGold else Color.Transparent, RoundedCornerShape(8.dp)) .clickable(onClick = onClick) .padding(horizontal = 10.dp, vertical = 9.dp), verticalAlignment = Alignment.CenterVertically, ) { Column(Modifier.weight(1f)) { Text(channel.name, color = LuxText, fontSize = 12.sp, fontWeight = if (selected || current) FontWeight.Bold else FontWeight.Medium, maxLines = 1, overflow = TextOverflow.Ellipsis) Text(program?.title ?: "No program information", color = LuxMuted, fontSize = 9.sp, maxLines = 1, overflow = TextOverflow.Ellipsis) } if (current) Text("LIVE", color = LuxGold, fontSize = 8.sp, fontWeight = FontWeight.Bold) } } @Composable private fun GroupListPanel( categories: List, selectedCategory: String?, onSelect: (String?) -> Unit, onClose: () -> Unit, ) { val menuFocus = remember { FocusRequester() } val listState = androidx.compose.foundation.lazy.rememberLazyListState() var selectedIndex by remember(categories, selectedCategory) { mutableStateOf( if (selectedCategory == null) 0 else categories.indexOfFirst { it.id == selectedCategory }.takeIf { it >= 0 }?.plus(1) ?: 0 ) } val rowCount = categories.size + 1 LaunchedEffect(categories.size, selectedCategory) { selectedIndex = if (selectedCategory == null) 0 else categories.indexOfFirst { it.id == selectedCategory }.takeIf { it >= 0 }?.plus(1) ?: 0 if (rowCount > 0) listState.scrollToItem(selectedIndex.coerceIn(0, rowCount - 1)) delay(50) runCatching { menuFocus.requestFocus() } } LaunchedEffect(selectedIndex, rowCount) { if (rowCount <= 0) return@LaunchedEffect val visible = listState.layoutInfo.visibleItemsInfo if (visible.isEmpty() || selectedIndex < visible.first().index || selectedIndex > visible.last().index) { listState.animateScrollToItem(selectedIndex.coerceIn(0, rowCount - 1)) } } Column( Modifier.fillMaxHeight().width(330.dp) .background(Color(0xF20A0F14)) .border(1.dp, LuxLine) .focusRequester(menuFocus) .focusable() .onPreviewKeyEvent { event -> val handled = event.key in setOf(Key.DirectionUp, Key.DirectionDown, Key.Enter, Key.DirectionCenter) if (!handled) return@onPreviewKeyEvent false if (event.type == KeyEventType.KeyDown) { when (event.key) { Key.DirectionUp -> selectedIndex = (selectedIndex - 1).coerceAtLeast(0) Key.DirectionDown -> selectedIndex = (selectedIndex + 1).coerceAtMost((rowCount - 1).coerceAtLeast(0)) Key.Enter, Key.DirectionCenter -> { if (selectedIndex == 0) onSelect(null) else categories.getOrNull(selectedIndex - 1)?.let { onSelect(it.id) } } else -> Unit } } true } .padding(14.dp) ) { Text("GROUPS", color = LuxGold, fontSize = 10.sp, fontWeight = FontWeight.Bold, letterSpacing = 1.4.sp) Text("↑ / ↓ browse • OK selects • RIGHT channels • BACK closes", color = LuxMuted, fontSize = 9.sp, modifier = Modifier.padding(top = 2.dp, bottom = 10.dp)) LazyColumn(Modifier.weight(1f), state = listState, verticalArrangement = Arrangement.spacedBy(4.dp)) { item { GroupListRow("All Channels", selectedCategory == null, selected = selectedIndex == 0) { selectedIndex = 0 onSelect(null) } } itemsIndexed(categories, key = { _, item -> item.id }) { index, category -> GroupListRow( name = category.name, active = selectedCategory == category.id, selected = selectedIndex == index + 1, ) { selectedIndex = index + 1 onSelect(category.id) } } } Spacer(Modifier.height(8.dp)) Text("BACK • CLOSE", color = LuxMuted, fontSize = 9.sp, fontWeight = FontWeight.Bold) } } @Composable private fun GroupListRow(name: String, active: Boolean, selected: Boolean, onClick: () -> Unit) { Box( Modifier.fillMaxWidth() .background(if (selected || active) Color(0xFF21303C) else Color.Transparent, RoundedCornerShape(8.dp)) .border(1.dp, if (selected) LuxGold else Color.Transparent, RoundedCornerShape(8.dp)) .clickable(onClick = onClick) .padding(horizontal = 10.dp, vertical = 10.dp) ) { Text(name, color = if (selected || active) LuxText else LuxMuted, fontSize = 11.sp, maxLines = 1, overflow = TextOverflow.Ellipsis) } } @Composable private fun BoxScope.ControlDeckPanel( item: MediaEntry?, program: EpgProgram?, recentChannels: List, isFavorite: Boolean, onGuide: () -> Unit, onHistory: () -> Unit, onFavorite: () -> Unit, onSearch: () -> Unit, onReport: () -> Unit, onSettings: () -> Unit, onTune: (MediaEntry) -> Unit, onClose: () -> Unit, ) { val firstAction = remember { FocusRequester() } LaunchedEffect(Unit) { kotlinx.coroutines.delay(40) runCatching { firstAction.requestFocus() } } Column( Modifier.align(Alignment.BottomCenter) .fillMaxWidth() .background(Color(0xEE0A0F14)) .border(1.dp, LuxLine) .padding(horizontal = 18.dp, vertical = 14.dp), verticalArrangement = Arrangement.spacedBy(10.dp), ) { Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.Bottom, horizontalArrangement = Arrangement.SpaceBetween) { Column(Modifier.weight(1f)) { Text(item?.name ?: "LIVE TV", color = LuxMuted, fontSize = 10.sp, fontWeight = FontWeight.Bold) Text(program?.title ?: "No program information", color = LuxText, fontSize = 20.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis) if (program != null) Text("${time(program.startEpoch)} – ${time(program.endEpoch)}", color = LuxMuted, fontSize = 10.sp) } Text("LONG OK • CONTROLS", color = LuxGold, fontSize = 9.sp, fontWeight = FontWeight.Bold) } LazyRow(horizontalArrangement = Arrangement.spacedBy(9.dp)) { item { ControlTile("▦", "TV GUIDE", onGuide, Modifier.focusRequester(firstAction)) } item { ControlTile("↶", "HISTORY", onHistory) } item { ControlTile(if (isFavorite) "♥" else "♡", if (isFavorite) "REMOVE FAVORITE" else "ADD FAVORITE", onFavorite) } item { ControlTile("⌕", "SEARCH", onSearch) } item { ControlTile("!", "REPORT", onReport) } item { ControlTile("⚙", "SETTINGS", onSettings) } items(recentChannels.take(8), key = { "recent:${it.id}" }) { channel -> RecentChannelTile(channel, current = channel.id == item?.id) { onTune(channel) } } item { ControlTile("×", "CLOSE", onClose) } } } } @Composable private fun BoxScope.HistoryPanel( channels: List, current: MediaEntry?, epgByChannel: Map>, onTune: (MediaEntry) -> Unit, onClose: () -> Unit, ) { val now = System.currentTimeMillis() / 1000L Column( Modifier.align(Alignment.CenterStart) .padding(start = 24.dp) .width(430.dp) .fillMaxHeight(.82f) .background(Color(0xF20A0F14), RoundedCornerShape(16.dp)) .border(1.dp, LuxLine, RoundedCornerShape(16.dp)) .padding(14.dp) ) { Text("WATCH HISTORY", color = LuxGold, fontSize = 10.sp, fontWeight = FontWeight.Bold, letterSpacing = 1.4.sp) Text("Recently tuned channels", color = LuxMuted, fontSize = 9.sp, modifier = Modifier.padding(top = 2.dp, bottom = 10.dp)) if (channels.isEmpty()) { Box(Modifier.weight(1f).fillMaxWidth(), contentAlignment = Alignment.Center) { Text("No recent channels yet", color = LuxMuted, fontSize = 12.sp) } } else { LazyColumn(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) { items(channels, key = { "history:${it.id}" }) { channel -> val program = epgByChannel[channel.id].orEmpty().firstOrNull { now in it.startEpoch until it.endEpoch } ChannelListRow(channel, program, current?.id == channel.id, selected = false) { onTune(channel) } } } } Spacer(Modifier.height(8.dp)) SmallAction("BACK TO CONTROLS", onClose) } } @Composable private fun BoxScope.LiveControlHud( item: MediaEntry?, program: EpgProgram?, recentChannels: List, isFavorite: Boolean, onGuide: () -> Unit, onHistory: () -> Unit, onFavorite: () -> Unit, onSearch: () -> Unit, onReport: () -> Unit, onSettings: () -> Unit, onTune: (MediaEntry) -> Unit, onClose: () -> Unit, onInteraction: () -> Unit, ) { val firstAction = remember { FocusRequester() } LaunchedEffect(Unit) { delay(60) runCatching { firstAction.requestFocus() } } Column( Modifier.align(Alignment.BottomCenter) .fillMaxWidth() .background(Color(0xE60A0F14)) .border(1.dp, LuxLine) .onPreviewKeyEvent { event -> if (event.type == KeyEventType.KeyDown) onInteraction() false } .padding(horizontal = 18.dp, vertical = 12.dp), verticalArrangement = Arrangement.spacedBy(9.dp), ) { Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.Bottom, horizontalArrangement = Arrangement.SpaceBetween) { Column(Modifier.weight(1f)) { Text(item?.name ?: "LIVE TV", color = LuxMuted, fontSize = 9.sp, fontWeight = FontWeight.Bold) Text(program?.title ?: "No program information", color = LuxText, fontSize = 18.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis) if (program != null) Text("${time(program.startEpoch)} – ${time(program.endEpoch)}", color = LuxMuted, fontSize = 9.sp) } Text("D-PAD TO MOVE • OK TO SELECT • BACK TO HIDE", color = LuxGold, fontSize = 8.sp, fontWeight = FontWeight.Bold) } LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) { item { ControlTile("▦", "TV GUIDE", onGuide, Modifier.focusRequester(firstAction)) } item { ControlTile("↶", "HISTORY", onHistory) } item { ControlTile(if (isFavorite) "♥" else "♡", if (isFavorite) "REMOVE FAVORITE" else "ADD FAVORITE", onFavorite) } item { ControlTile("⌕", "SEARCH", onSearch) } item { ControlTile("!", "REPORT", onReport) } item { ControlTile("⚙", "SETTINGS", onSettings) } items(recentChannels.take(6), key = { "hud:${it.id}" }) { channel -> RecentChannelTile(channel, current = channel.id == item?.id) { onTune(channel) } } item { ControlTile("×", "CLOSE", onClose) } } } } @Composable private fun ControlTile(symbol: String, label: String, onClick: () -> Unit, modifier: Modifier = Modifier) { var focused by remember { mutableStateOf(false) } Column( modifier.width(118.dp).height(76.dp) .background(if (focused) Color(0xFF304451) else Color(0xFF1B252E), RoundedCornerShape(10.dp)) .border(1.dp, if (focused) LuxGold else LuxLine, RoundedCornerShape(10.dp)) .onFocusChanged { focused = it.isFocused } .focusable() .clickable(onClick = onClick) .padding(10.dp), verticalArrangement = Arrangement.SpaceBetween, ) { Text(symbol, color = if (focused) LuxGold else LuxText, fontSize = 21.sp, fontWeight = FontWeight.Bold) Text(label, color = if (focused) LuxText else LuxMuted, fontSize = 9.sp, fontWeight = FontWeight.Bold, maxLines = 1) } } @Composable private fun RecentChannelTile(channel: MediaEntry, current: Boolean, onClick: () -> Unit) { var focused by remember { mutableStateOf(false) } Column( Modifier.width(150.dp).height(76.dp) .background( when { focused -> Color(0xFF304451) current -> Color(0xFF1A3542) else -> Color(0xFF1B252E) }, RoundedCornerShape(10.dp) ) .border(1.dp, if (focused) LuxGold else if (current) Color(0xFF3C7088) else LuxLine, RoundedCornerShape(10.dp)) .onFocusChanged { focused = it.isFocused } .focusable() .clickable(onClick = onClick) .padding(10.dp), verticalArrangement = Arrangement.SpaceBetween, ) { Text(if (current) "NOW PLAYING" else "RECENT", color = if (current) LuxGold else LuxMuted, fontSize = 8.sp, fontWeight = FontWeight.Bold) Text(channel.name, color = LuxText, fontSize = 10.sp, fontWeight = FontWeight.SemiBold, maxLines = 2, overflow = TextOverflow.Ellipsis) } } @Composable private fun HudTile(symbol: String, label: String) { Column( Modifier.width(95.dp).height(62.dp) .background(Color(0xCC1B252E), RoundedCornerShape(8.dp)) .border(1.dp, LuxLine, RoundedCornerShape(8.dp)) .padding(8.dp), verticalArrangement = Arrangement.SpaceBetween, ) { Text(symbol, color = LuxText, fontSize = 17.sp, fontWeight = FontWeight.Bold) Text(label, color = LuxMuted, fontSize = 8.sp, fontWeight = FontWeight.Bold, maxLines = 1) } } @Composable private fun HudRecentTile(channel: MediaEntry, current: Boolean) { Column( Modifier.width(120.dp).height(62.dp) .background(if (current) Color(0xCC1A3542) else Color(0xCC1B252E), RoundedCornerShape(8.dp)) .border(1.dp, if (current) Color(0xFF3C7088) else LuxLine, RoundedCornerShape(8.dp)) .padding(8.dp), verticalArrangement = Arrangement.SpaceBetween, ) { Text(if (current) "LIVE" else "RECENT", color = if (current) LuxGold else LuxMuted, fontSize = 7.sp, fontWeight = FontWeight.Bold) Text(channel.name, color = LuxText, fontSize = 8.sp, fontWeight = FontWeight.SemiBold, maxLines = 2, overflow = TextOverflow.Ellipsis) } } @Composable private fun SmallAction(label: String, onClick: () -> Unit) { var focused by remember { mutableStateOf(false) } Box( Modifier.fillMaxWidth() .background(if (focused) Color(0xFF2E4050) else LuxPanel, RoundedCornerShape(9.dp)) .border(1.dp, if (focused) LuxGold else LuxLine, RoundedCornerShape(9.dp)) .onFocusChanged { focused = it.isFocused } .focusable() .clickable(onClick = onClick) .padding(horizontal = 12.dp, vertical = 10.dp) ) { Text(label, color = if (focused) LuxGold else LuxText, fontSize = 10.sp, fontWeight = FontWeight.Bold) } } @Composable private fun BoxScope.ProgramInfoBottom(item: MediaEntry?, program: EpgProgram?) { Column( Modifier.align(Alignment.BottomCenter).fillMaxWidth().padding(24.dp) .background(Color(0xE811161C), RoundedCornerShape(14.dp)) .border(1.dp, LuxLine, RoundedCornerShape(14.dp)) .padding(16.dp) ) { Text(item?.name ?: "LIVE TV", color = LuxGold, fontSize = 10.sp, fontWeight = FontWeight.Bold) Text(program?.title ?: "No program information", color = LuxText, fontSize = 19.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis) if (program != null) { Text("${time(program.startEpoch)} – ${time(program.endEpoch)}", color = LuxMuted, fontSize = 10.sp) if (program.description.isNotBlank()) { Text(program.description, color = LuxMuted, fontSize = 11.sp, maxLines = 2, overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(top = 5.dp)) } } } } @Composable private fun BoxScope.ProgramInfoTopRight(item: MediaEntry?, program: EpgProgram?) { Column( Modifier.align(Alignment.TopEnd).width(390.dp).padding(top = 26.dp, end = 26.dp) .background(Color(0xED11161C), RoundedCornerShape(14.dp)) .border(1.dp, LuxLine, RoundedCornerShape(14.dp)) .padding(14.dp) ) { Text("PROGRAM INFO", color = LuxGold, fontSize = 9.sp, fontWeight = FontWeight.Bold) Text(item?.name ?: "LIVE TV", color = LuxMuted, fontSize = 9.sp) Text(program?.title ?: "No program information", color = LuxText, fontSize = 16.sp, fontWeight = FontWeight.SemiBold, modifier = Modifier.padding(top = 4.dp)) if (program != null) { Text("${time(program.startEpoch)} – ${time(program.endEpoch)}", color = LuxMuted, fontSize = 9.sp) if (program.description.isNotBlank()) { Text(program.description, color = LuxMuted, fontSize = 10.sp, maxLines = 4, overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(top = 5.dp)) } } } } private fun time(epoch: Long): String = SimpleDateFormat("h:mm a", Locale.getDefault()).format(Date(epoch * 1000L))