@file:OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class) package tv.tivilux.nativeplayer.ui.screens import tv.tivilux.nativeplayer.ui.components.panelReveal import android.os.SystemClock import androidx.activity.compose.BackHandler import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.slideInHorizontally import androidx.compose.animation.slideOutHorizontally import androidx.compose.animation.core.tween import androidx.compose.foundation.background import androidx.compose.foundation.basicMarquee import androidx.compose.foundation.border import androidx.compose.foundation.clickable import androidx.compose.foundation.gestures.detectHorizontalDragGestures import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.material3.TextButton import androidx.compose.foundation.focusGroup import androidx.compose.foundation.focusable import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.LinearProgressIndicator 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.draw.clip import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.focus.onFocusChanged import androidx.compose.ui.geometry.Rect import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.boundsInRoot import androidx.compose.ui.layout.onGloballyPositioned 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.dp import androidx.compose.ui.unit.sp import androidx.compose.ui.window.Popup import androidx.compose.ui.window.PopupProperties import coil.compose.AsyncImage import kotlinx.coroutines.delay import tv.tivilux.nativeplayer.model.AppSettings import tv.tivilux.nativeplayer.model.Category import tv.tivilux.nativeplayer.model.EpgProgram import tv.tivilux.nativeplayer.model.MediaEntry import tv.tivilux.nativeplayer.ui.theme.LuxGold import tv.tivilux.nativeplayer.ui.theme.LuxGreen 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.LuxPanel2 import tv.tivilux.nativeplayer.ui.theme.LuxText import java.text.SimpleDateFormat import java.util.Date import java.util.Locale import kotlin.math.max import kotlin.math.min /** * v0.4.6 TV GUIDE CORE * * The guide deliberately owns ONE remote focus target. Holding UP/DOWN changes an integer * selection instead of asking Compose's spatial focus engine to search through hundreds of * recycled channel/program focus nodes. This is both faster and substantially more stable on * low-memory Android TV / onn. / Fire TV hardware. * * Navigation mirrors the TV-first flow requested for TiviLux: * Guide -> LEFT -> Groups -> LEFT -> Main TiviLux menu * Guide -> HOLD OK -> right-side Guide Settings * Guide -> OK -> tune highlighted channel (browsing never retunes by itself) */ @Composable fun LiveScreen( categories: List, selectedCategory: String?, channels: List, tunedChannel: MediaEntry?, epgByChannel: Map>, settings: AppSettings, onPreviewBoundsChanged: (Rect?) -> Unit, onDrawerOffsetTargetChanged: (Dp) -> Unit = {}, drawerOffset: () -> Dp = { 0.dp }, onCategory: (String?) -> Unit, onChannel: (MediaEntry) -> Unit, onNeedEpg: (MediaEntry) -> Unit, onPlayFullScreen: (MediaEntry) -> Unit, onOpenMultiView: () -> Unit, onShortBack: () -> Unit, onOpenSettings: () -> Unit, onSettingsChanged: (AppSettings) -> Unit, onRequestMainMenu: () -> Unit, onFavorite: (MediaEntry) -> Unit, onHideChannel: (MediaEntry) -> Unit, isFavorite: (MediaEntry) -> Boolean, favoriteKeys: Set, initialAnchorChannelId: String?, onGuideInteractionChanged: (Boolean) -> Unit, favoritesGuide: Boolean = false, categorySort: String = settings.channelSort, onCategorySortChanged: (String) -> Unit = {}, manualOrder: List = emptyList(), onManualOrderChanged: (List) -> Unit = {}, interactive: Boolean = true, ) { var nowEpoch by remember { mutableStateOf(System.currentTimeMillis() / 1000L) } LaunchedEffect(Unit) { while (true) { delay(15_000) nowEpoch = System.currentTimeMillis() / 1000L } } // Keep the last preview bounds when Live TV temporarily becomes fullscreen. The shared // TextureView can therefore resize straight back into the exact preview rectangle instead // of collapsing to 1px/black while the guide is measured again. DisposableEffect(Unit) { onDispose { onGuideInteractionChanged(false) onDrawerOffsetTargetChanged(0.dp) } } val offsetSeconds = settings.epgTimeOffsetHours * 3600L val effectiveSort = if (favoritesGuide) settings.favoriteChannelSort else categorySort var editingChannelIds by remember(selectedCategory, favoritesGuide) { mutableStateOf?>(null) } val baseChannels = remember(channels, effectiveSort, manualOrder, editingChannelIds) { when (effectiveSort) { "Name", "A-Z" -> channels.sortedBy { it.name.lowercase(Locale.getDefault()) } "Channel #" -> channels.sortedWith( compareBy { if (it.number > 0) it.number else Int.MAX_VALUE } .thenBy { it.name } ) "Manual" -> { val rank = (editingChannelIds ?: manualOrder).withIndex().associate { it.value to it.index } val providerRank = channels.withIndex().associate { it.value.id to it.index } channels.sortedWith( compareBy { rank[it.id] ?: Int.MAX_VALUE } .thenBy { providerRank[it.id] ?: Int.MAX_VALUE } ) } else -> channels } } val displayChannels = remember(baseChannels, settings.favoritesFirst, favoriteKeys, favoritesGuide, effectiveSort) { if (!favoritesGuide && effectiveSort != "Manual" && settings.favoritesFirst) { baseChannels.sortedByDescending { favoriteKeys.contains("${it.type.name}:${it.id}") } } else baseChannels } val guideListState = rememberLazyListState() val guideFocusRequester = remember { FocusRequester() } var focusedIndex by remember(selectedCategory) { mutableStateOf(0) } var guideOffsetHalfHours by remember { mutableStateOf(0) } var groupsVisible by remember { mutableStateOf(false) } var quickSettingsVisible by remember { mutableStateOf(false) } var reorderMode by remember(selectedCategory, favoritesGuide) { mutableStateOf(false) } var pickedChannelId by remember(selectedCategory, favoritesGuide) { mutableStateOf(null) } var selectHeld by remember { mutableStateOf(false) } var longSelectTriggered by remember { mutableStateOf(false) } var backHeld by remember { mutableStateOf(false) } var longBackTriggered by remember { mutableStateOf(false) } // Build 80: BACK from a future EPG window snaps straight to NOW without leaving the Guide. // Swallow the matching KeyUp so it cannot also invoke the normal short-BACK action. var swallowBackToNowRelease by remember { mutableStateOf(false) } var lastVerticalMoveAt by remember { mutableStateOf(0L) } var guideMoving by remember { mutableStateOf(false) } // Build 81: consume the Android/TV BACK dispatch before the parent navigation layer // whenever the EPG timeline is away from NOW. This is intentionally separate from // the DPAD key handler because some TV firmwares route KEYCODE_BACK through the // activity back dispatcher before Compose receives an onPreviewKeyEvent. BackHandler(enabled = interactive && guideOffsetHalfHours != 0 && !groupsVisible && !quickSettingsVisible && !reorderMode) { guideOffsetHalfHours = 0 backHeld = false longBackTriggered = false swallowBackToNowRelease = true } fun finishChannelReorder() { editingChannelIds?.let(onManualOrderChanged) pickedChannelId = null reorderMode = false editingChannelIds = null } BackHandler(enabled = interactive && reorderMode) { finishChannelReorder() } val focusedChannel = displayChannels.getOrNull(focusedIndex) val focusedPrograms = focusedChannel?.let { epgByChannel[it.id].orEmpty() }.orEmpty() val focusedProgram = focusedPrograms.firstOrNull { nowEpoch in (it.startEpoch + offsetSeconds) until (it.endEpoch + offsetSeconds) } ?: focusedPrograms.firstOrNull() LaunchedEffect(interactive, groupsVisible, quickSettingsVisible, reorderMode, displayChannels.size) { if (interactive && !groupsVisible && !quickSettingsVisible && displayChannels.isNotEmpty()) { androidx.compose.runtime.withFrameNanos { } runCatching { guideFocusRequester.requestFocus() } } } // Normal entry starts at row 1. Returning from fullscreen/Sports provides a one-shot anchor. LaunchedEffect(selectedCategory, displayChannels, initialAnchorChannelId) { if (reorderMode) return@LaunchedEffect if (displayChannels.isEmpty()) { focusedIndex = 0 return@LaunchedEffect } val target = initialAnchorChannelId ?.let { id -> displayChannels.indexOfFirst { it.id == id } } ?.takeIf { it >= 0 } ?: 0 focusedIndex = target.coerceIn(0, displayChannels.lastIndex) guideListState.scrollToItem(focusedIndex) } // Step #2 performance pass: keep DPAD scrolling on the input path instead of launching a // frame-synchronised coroutine for every focused row. The key handler below uses // requestScrollToItem(), which schedules the viewport change for the next measure pass and // avoids an extra withFrameNanos + scrollToItem suspend cycle on every remote press. // This effect is now only a safety net for list mutations (Favorites/category changes). LaunchedEffect(displayChannels.size, favoritesGuide) { if (displayChannels.isEmpty()) return@LaunchedEffect val clampedIndex = focusedIndex.coerceIn(0, displayChannels.lastIndex) if (clampedIndex != focusedIndex) focusedIndex = clampedIndex val visibleItems = guideListState.layoutInfo.visibleItemsInfo if (visibleItems.isNotEmpty() && clampedIndex !in visibleItems.first().index..visibleItems.last().index ) { guideListState.requestScrollToItem((clampedIndex - 2).coerceAtLeast(0)) } } // No EPG network work while the D-pad is flying. 250ms after the last movement, fetch only // the selected channel plus a tiny look-ahead window. Bulk/cached EPG remains visible during // the scroll, so channel/program text never intentionally disappears anymore. LaunchedEffect(focusedIndex, displayChannels) { if (displayChannels.isEmpty()) return@LaunchedEffect delay(250) onGuideInteractionChanged(false) val first = (focusedIndex - 2).coerceAtLeast(0) val last = (focusedIndex + 5).coerceAtMost(displayChannels.lastIndex) for (index in first..last) onNeedEpg(displayChannels[index]) } // Build 76: suspend decorative marquee animation while the D-pad is moving. Text // animation was competing with TextureView video composition on lower-power TV boxes. LaunchedEffect(focusedIndex) { if (!guideMoving) return@LaunchedEffect delay(180) guideMoving = false } LaunchedEffect(selectHeld, settings.remoteShortcutsEnabled, interactive) { if (selectHeld && settings.remoteShortcutsEnabled && interactive) { delay(600) if (selectHeld && !longSelectTriggered) { longSelectTriggered = true quickSettingsVisible = true } } } LaunchedEffect(backHeld, tunedChannel?.id, interactive) { if (backHeld && tunedChannel != null && interactive) { delay(650) if (backHeld && !longBackTriggered) { longBackTriggered = true onPlayFullScreen(tunedChannel) } } } val phoneTouch = isPhoneTouchDevice() BoxWithConstraints( Modifier .fillMaxSize() // Phone touch: horizontal swipes open/close Groups; vertical guide scrolling // remains owned by LazyColumn. No change to DPAD key handling. .then(if (phoneTouch) Modifier.pointerInput(interactive, groupsVisible, quickSettingsVisible) { var horizontalDrag = 0f detectHorizontalDragGestures( onDragStart = { horizontalDrag = 0f }, onHorizontalDrag = { change, amount -> horizontalDrag += amount change.consume() }, onDragEnd = { if (interactive && !quickSettingsVisible) { if (horizontalDrag > 90f) groupsVisible = true else if (horizontalDrag < -90f) groupsVisible = false } horizontalDrag = 0f }, onDragCancel = { horizontalDrag = 0f }, ) } else Modifier) .focusRequester(guideFocusRequester) .focusable(enabled = interactive && !groupsVisible && !quickSettingsVisible) .onPreviewKeyEvent { event -> if (!interactive || groupsVisible || quickSettingsVisible) return@onPreviewKeyEvent false if (reorderMode) { if (event.type == KeyEventType.KeyDown) { when (event.key) { Key.DirectionUp, Key.DirectionDown -> { if (displayChannels.isNotEmpty()) { val delta = if (event.key == Key.DirectionDown) 1 else -1 val next = (focusedIndex + delta).coerceIn(0, displayChannels.lastIndex) val picked = pickedChannelId if (picked != null && next != focusedIndex) { val ids = displayChannels.map { it.id }.toMutableList() val from = ids.indexOf(picked) if (from >= 0) { ids.removeAt(from) ids.add(next, picked) editingChannelIds = ids } } focusedIndex = next guideListState.requestScrollToItem((next - 2).coerceAtLeast(0)) } } Key.Enter, Key.DirectionCenter -> { pickedChannelId = if (pickedChannelId == null) displayChannels.getOrNull(focusedIndex)?.id else null } Key.Back -> finishChannelReorder() else -> Unit } } return@onPreviewKeyEvent true } when (event.key) { Key.DirectionUp, Key.DirectionDown -> { if (event.type == KeyEventType.KeyDown && displayChannels.isNotEmpty()) { val now = SystemClock.uptimeMillis() // Ignore pathological duplicate events faster than a TV can draw. if (now - lastVerticalMoveAt >= 28L) { lastVerticalMoveAt = now val delta = if (event.key == Key.DirectionDown) 1 else -1 val nextIndex = (focusedIndex + delta).coerceIn(0, displayChannels.lastIndex) focusedIndex = nextIndex guideMoving = true // v0.4.51: Favorites Guide uses a synthetic/filtered channel list. // Do NOT infer scrollability from visibleItemsInfo.size: a partially // clipped bottom row still counts as "visible", which made a short // Favorites list appear non-scrollable. Request the desired viewport // position immediately from the DPAD event so the highlighted favorite // can never move underneath the bottom edge/TV safe area. Keep it around // the third row while moving, matching the normal Guide's comfortable zone. // Keep the selected row inside a comfortable viewport zone without // waiting for a coroutine/frame round-trip. This applies to the normal // Guide as well as Favorites and is the hot path for rapid DPAD use. val visible = guideListState.layoutInfo.visibleItemsInfo if (visible.isNotEmpty()) { val visibleCount = max(1, visible.size) val firstVisible = visible.first().index val lastVisible = visible.last().index val safeInset = min(2, max(1, visibleCount / 3)) val safeTop = (firstVisible + safeInset).coerceAtMost(lastVisible) val safeBottom = (lastVisible - safeInset).coerceAtLeast(firstVisible) val maxFirst = (displayChannels.size - visibleCount).coerceAtLeast(0) // Build 87: use the proven Favorites viewport behavior for EVERY // category. Keeping the focused channel around the third visible row // guarantees that the final channel can move fully above the bottom // TV safe-area instead of receiving focus while remaining clipped. val targetFirst = (nextIndex - 2).coerceAtLeast(0) if (targetFirst != firstVisible) { guideListState.requestScrollToItem(targetFirst) } } else { guideListState.requestScrollToItem((nextIndex - 2).coerceAtLeast(0)) } onGuideInteractionChanged(true) } } true } Key.DirectionLeft -> { if (event.type == KeyEventType.KeyDown) { // Build 83: while browsing future Guide time, LEFT walks the timeline // back toward NOW instead of opening Groups. Once NOW is reached, the // existing LEFT-to-open-Groups behavior resumes unchanged. if (guideOffsetHalfHours > 0) { guideOffsetHalfHours = (guideOffsetHalfHours - 1).coerceAtLeast(0) } else { groupsVisible = true } } true } Key.DirectionRight -> { if (event.type == KeyEventType.KeyDown) { guideOffsetHalfHours = (guideOffsetHalfHours + 1).coerceAtMost(96) } true } Key.Enter, Key.DirectionCenter -> { if (!settings.remoteShortcutsEnabled) { if (event.type == KeyEventType.KeyUp) { focusedChannel?.let { channel -> if (tunedChannel?.id == channel.id) onPlayFullScreen(channel) else onChannel(channel) } } return@onPreviewKeyEvent true } when (event.type) { KeyEventType.KeyDown -> { if (!selectHeld) { selectHeld = true longSelectTriggered = false } true } KeyEventType.KeyUp -> { val wasLong = longSelectTriggered selectHeld = false longSelectTriggered = false if (!wasLong) { focusedChannel?.let { channel -> if (tunedChannel?.id == channel.id) onPlayFullScreen(channel) else onChannel(channel) } } true } else -> true } } Key.Back -> { // Build 80: when the user has browsed into future EPG time, the first // BACK is a dedicated "Back to Now" command. Keep the same channel, // player and EPG cache; only reset the horizontal guide window. if (guideOffsetHalfHours != 0 || swallowBackToNowRelease) { when (event.type) { KeyEventType.KeyDown -> { guideOffsetHalfHours = 0 swallowBackToNowRelease = true backHeld = false longBackTriggered = false true } KeyEventType.KeyUp -> { swallowBackToNowRelease = false true } else -> true } } else { when (event.type) { KeyEventType.KeyDown -> { if (!backHeld) { backHeld = true longBackTriggered = false } true } KeyEventType.KeyUp -> { val wasLong = longBackTriggered backHeld = false longBackTriggered = false if (!wasLong) onShortBack() true } else -> true } } } else -> false } } ) { val compact = maxWidth < 820.dp || maxHeight < 560.dp // v0.4.6: the live preview is a permanent part of the TV Guide layout. // A stale saved setting can no longer make the preview disappear after an update. val topHeight = if (compact) 174.dp else 216.dp val channelWidth = if (compact) 214.dp else 264.dp val rowHeight = when (settings.guideDensity) { "Compact" -> 46.dp "Spacious" -> 68.dp else -> 56.dp } // TiviMate-style drawer behavior: Groups gets its own lane and the *entire* Live TV // surface glides horizontally with it. Use an offset instead of start padding so opening // Groups never changes the guide/preview width. That keeps the shared TextureView at a // stable size while its bounds move smoothly, eliminating the old jump/resize effect. val groupDrawerWidth = if (compact) 280.dp else 320.dp // The Groups drawer itself keeps its full readable width, but the guide/preview only // glides a modest distance. Moving the content by the full drawer width pushed the // preview far too deep into the right side of the screen on 1080p TV layouts. // Build 79: keep the Guide and hardware video surface completely stationary while // Groups is open. The category drawer is a foreground Popup, so shifting the entire // Guide underneath it only adds a costly/visually uneven SurfaceView + Compose // transition on TV hardware. TiviMate-style behavior here is immediate: drawer overlays // the already-rendered Guide; closing it simply reveals the same pixels/focus position. val groupContentShift = 0.dp LaunchedEffect(groupsVisible, groupContentShift) { // TiviLuxApp owns the ONE drawer animation used by both the Compose Guide and the // persistent native PlayerView. Sharing the same animated offset prevents the video // surface from drifting away from its preview frame while Live Groups is open. onDrawerOffsetTargetChanged(if (groupsVisible) groupContentShift else 0.dp) } Column( Modifier .fillMaxSize() .graphicsLayer { translationX = drawerOffset().toPx() } .padding(12.dp), verticalArrangement = Arrangement.spacedBy(10.dp), ) { LiveHeader( selectedChannel = focusedChannel, currentProgram = focusedProgram, // The shared Android video surface lives above Compose. Hide/collapse it while // the full-screen manual reorder overlay is active so it can never cover rows. showPreview = true, topHeight = topHeight, // Store only the Guide's true resting preview rectangle. While Groups is opening // or closing, both the Guide and native PlayerView are translated by drawerOffset, // so accepting transformed bounds here would count that movement twice. Resume // base-bounds updates only after the shared drawer animation is fully back at 0dp. onPreviewBoundsChanged = { bounds -> if (bounds == null || (!groupsVisible && drawerOffset() <= 0.5.dp)) { onPreviewBoundsChanged(bounds) } }, showDescription = settings.showProgramDescriptions, showProgress = settings.showProgramProgress, onOpenCategories = { groupsVisible = true }, onOpenFullScreen = { tunedChannel?.let(onPlayFullScreen) }, canOpenFullScreen = tunedChannel != null, phoneTouch = phoneTouch, nowEpoch = nowEpoch, offsetSeconds = offsetSeconds, ) Column( Modifier.weight(1f).fillMaxWidth() .background(LuxPanel.copy(alpha = .92f), RoundedCornerShape(14.dp)) .border(1.dp, LuxLine, RoundedCornerShape(14.dp)) ) { if (reorderMode) { Text( text = if (pickedChannelId == null) "EDIT CHANNEL ORDER • OK: Pick up • BACK: Save & exit" else "MOVING CHANNEL • UP/DOWN: Move • OK: Drop • BACK: Save & exit", color = LuxGold, fontWeight = FontWeight.Bold, fontSize = 15.sp, modifier = Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 8.dp), ) } GuideHeader(nowEpoch, channelWidth, settings, guideOffsetHalfHours) LazyColumn( modifier = Modifier.fillMaxSize(), state = guideListState, // v0.4.70: reserve one full Guide row below every category, not only Favorites. // This gives the final focused channel enough real scroll range to clear TV // overscan / the bottom viewport edge while preserving the existing DPAD path. contentPadding = PaddingValues(bottom = rowHeight), ) { itemsIndexed(displayChannels, key = { _, item -> item.id }, contentType = { _, _ -> "guide-row" }) { index, channel -> GuideRow( channel = channel, programs = epgByChannel[channel.id].orEmpty(), focused = index == focusedIndex, tuned = tunedChannel?.id == channel.id, nowEpoch = nowEpoch, channelWidth = channelWidth, rowHeight = rowHeight, settings = settings, guideOffsetHalfHours = guideOffsetHalfHours, allowMarquee = !guideMoving, onTap = { focusedIndex = index onGuideInteractionChanged(false) onChannel(channel) }, ) } } } } // v0.4.45: render Live Groups in a separate foreground window. // The persistent Media3 PlayerView is owned by TiviLuxApp and is composed after the // Guide, so a normal in-tree drawer could appear *behind* the TextureView preview. // Popup gives the Groups/categories panel its own foreground layer, exactly like the // main TiviLux rail visually behaves, without touching playback or Sports state. if (groupsVisible) { Popup( alignment = Alignment.CenterStart, properties = PopupProperties( focusable = true, dismissOnBackPress = false, dismissOnClickOutside = false, clippingEnabled = true, ), ) { Box(Modifier.width(groupDrawerWidth).fillMaxHeight()) { GroupDrawer( categories = categories, selectedCategory = selectedCategory, drawerWidth = groupDrawerWidth, onCategory = { id -> onCategory(id) groupsVisible = false }, onOpenMultiView = { groupsVisible = false onPreviewBoundsChanged(null) onOpenMultiView() }, onCloseToGuide = { groupsVisible = false }, onMainMenu = { groupsVisible = false onRequestMainMenu() }, ) } } } if (quickSettingsVisible) { GuideQuickSettingsPanel( settings = settings, favoritesGuide = favoritesGuide, categorySort = categorySort, onCategorySortChanged = onCategorySortChanged, focusedChannel = focusedChannel, onSettingsChanged = onSettingsChanged, isFocusedFavorite = focusedChannel?.let(isFavorite) == true, onFavorite = { channel -> onFavorite(channel) }, onStartReorder = { // Collapse the shared TextureView before the modal is composed. Android views // sit above Compose, so waiting one frame can leave the old preview rectangle // covering the first reorder rows on real TV hardware. quickSettingsVisible = false editingChannelIds = displayChannels.map { it.id } if (effectiveSort != "Manual") onCategorySortChanged("Manual") pickedChannelId = null reorderMode = true }, onHideChannel = { channel -> quickSettingsVisible = false onHideChannel(channel) }, onOpenMultiView = { quickSettingsVisible = false onPreviewBoundsChanged(null) onOpenMultiView() }, onOpenFullSettings = { quickSettingsVisible = false onOpenSettings() }, onClose = { quickSettingsVisible = false }, consumeOpeningSelectRelease = true, ) } } } @Composable private fun LiveHeader( selectedChannel: MediaEntry?, currentProgram: EpgProgram?, showPreview: Boolean, topHeight: Dp, onPreviewBoundsChanged: (Rect?) -> Unit, showDescription: Boolean, showProgress: Boolean, onOpenCategories: () -> Unit, onOpenFullScreen: () -> Unit, canOpenFullScreen: Boolean, phoneTouch: Boolean, nowEpoch: Long, offsetSeconds: Long, ) { LaunchedEffect(showPreview) { if (!showPreview) onPreviewBoundsChanged(null) } val compactHeader = topHeight < 200.dp Row( Modifier.fillMaxWidth().height(topHeight) .background(LuxPanel.copy(alpha = .92f), RoundedCornerShape(16.dp)) .border(1.dp, LuxLine, RoundedCornerShape(16.dp)) .padding(10.dp), horizontalArrangement = Arrangement.spacedBy(14.dp), ) { if (showPreview) { Box( Modifier.fillMaxHeight().weight(.39f) .clip(RoundedCornerShape(12.dp)) .border(1.dp, Color(0xFF394553), RoundedCornerShape(12.dp)) .background(Color.Black) .then(if (phoneTouch && canOpenFullScreen) Modifier.clickable(onClick = onOpenFullScreen) else Modifier) .onGloballyPositioned { coordinates -> onPreviewBoundsChanged(coordinates.boundsInRoot()) } ) } Column(Modifier.weight(if (showPreview) .61f else 1f).fillMaxHeight()) { Column(Modifier.weight(1f).fillMaxWidth()) { Row( Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically, ) { Row(verticalAlignment = Alignment.CenterVertically) { TextButton(onClick = onOpenCategories, contentPadding = PaddingValues(horizontal = 5.dp, vertical = 0.dp)) { Text("☰ CATEGORIES", color = LuxGold, fontSize = 10.sp, fontWeight = FontWeight.Bold) } if (canOpenFullScreen) { TextButton( onClick = onOpenFullScreen, contentPadding = PaddingValues(horizontal = if (phoneTouch) 12.dp else 5.dp, vertical = if (phoneTouch) 8.dp else 0.dp), modifier = if (phoneTouch) Modifier.heightIn(min = 44.dp) else Modifier, ) { Text("⛶ FULLSCREEN", color = LuxGold, fontSize = if (phoneTouch) 12.sp else 10.sp, fontWeight = FontWeight.Bold) } } } Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) { Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp)) { Box(Modifier.width(7.dp).height(7.dp).background(LuxGreen, RoundedCornerShape(50))) Text("GUIDE ONLINE", color = LuxMuted, fontSize = 9.sp) } Text(formatClock(nowEpoch), color = LuxText, fontSize = 11.sp, fontWeight = FontWeight.SemiBold) } } Text( selectedChannel?.name ?: "Choose a channel", color = LuxText, fontSize = if (compactHeader) 20.sp else 24.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Clip, modifier = Modifier.fillMaxWidth().basicMarquee(), ) if (currentProgram != null) { Spacer(Modifier.height(4.dp)) Text( currentProgram.title, color = LuxGold, fontSize = if (compactHeader) 13.sp else 15.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Clip, modifier = Modifier.fillMaxWidth().basicMarquee(), ) Text( "${formatTime(currentProgram.startEpoch + offsetSeconds)} – ${formatTime(currentProgram.endEpoch + offsetSeconds)}", color = LuxMuted, fontSize = 11.sp, ) if (showProgress) { LinearProgressIndicator( progress = { programProgress(currentProgram, nowEpoch, offsetSeconds) }, modifier = Modifier.fillMaxWidth(.72f).height(3.dp).padding(top = 2.dp), color = LuxGold, trackColor = Color.White.copy(alpha = .10f), ) } if (showDescription && currentProgram.description.isNotBlank()) { Text( currentProgram.description, color = LuxMuted, fontSize = 11.sp, lineHeight = 15.sp, maxLines = if (compactHeader) 2 else 3, overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(top = 5.dp), ) } } else { Text("No Information", color = LuxMuted, fontSize = 12.sp) } } } } } @Composable private fun GuideHeader(nowEpoch: Long, channelWidth: Dp, settings: AppSettings, guideOffsetHalfHours: Int) { val start = guideWindowStart(nowEpoch, guideOffsetHalfHours) Row( Modifier.fillMaxWidth().height(42.dp).background(Color(0xFF111820)), verticalAlignment = Alignment.CenterVertically, ) { Text( "CHANNEL", color = LuxMuted, fontSize = 9.sp, fontWeight = FontWeight.Bold, modifier = Modifier.width(channelWidth).padding(start = 12.dp), letterSpacing = 1.2.sp, ) Row(Modifier.weight(1f).fillMaxHeight()) { repeat(4) { index -> Box( Modifier.weight(1f).fillMaxHeight().border(0.5.dp, LuxLine.copy(alpha = .65f)), contentAlignment = Alignment.CenterStart, ) { Text( formatTime(start + index * 1800L), color = LuxMuted, fontSize = guideFont(settings), modifier = Modifier.padding(start = 8.dp), ) } } } } } @Composable private fun GuideRow( channel: MediaEntry, programs: List, focused: Boolean, tuned: Boolean, nowEpoch: Long, channelWidth: Dp, rowHeight: Dp, settings: AppSettings, guideOffsetHalfHours: Int, allowMarquee: Boolean, onTap: () -> Unit, ) { val selectedVisual = tuned && settings.highlightCurrentChannel val rowBackground = when { focused -> Color(0xFF4B3B24) selectedVisual -> Color(0xFF192A34) else -> LuxPanel2.copy(alpha = .52f) } Row( Modifier.fillMaxWidth().height(rowHeight) .clickable(onClick = onTap) .background(rowBackground) .border(1.dp, if (focused) LuxGold else LuxLine.copy(alpha = .55f)) ) { Row( Modifier.width(channelWidth).fillMaxHeight().padding(horizontal = 8.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp), ) { if (settings.showChannelLogos) { Box( Modifier.width(52.dp).height(42.dp) .background(Color(0xFF121A21), RoundedCornerShape(5.dp)), contentAlignment = Alignment.Center, ) { Text( channel.name.take(1).uppercase(), color = LuxMuted.copy(alpha = .65f), fontSize = 12.sp, fontWeight = FontWeight.Bold, ) if (channel.image.isNotBlank()) { AsyncImage( model = channel.image, contentDescription = channel.name, modifier = Modifier.fillMaxSize(), contentScale = ContentScale.Fit, ) } } } Column(Modifier.weight(1f)) { Text( channel.name, color = LuxText, fontSize = guideFont(settings), fontWeight = if (focused) FontWeight.Bold else FontWeight.SemiBold, maxLines = 1, overflow = if (focused) TextOverflow.Clip else TextOverflow.Ellipsis, modifier = Modifier.fillMaxWidth().then(if (focused && allowMarquee) Modifier.basicMarquee() else Modifier), ) if (settings.showChannelNumbers && channel.number > 0) { Text("CH ${channel.number}", color = LuxMuted, fontSize = 9.sp) } } if (tuned) Text("●", color = LuxGreen, fontSize = 8.sp) } GuideTimeline( modifier = Modifier.weight(1f).fillMaxHeight(), programs = programs, nowEpoch = nowEpoch, settings = settings, selectedChannel = selectedVisual, guideOffsetHalfHours = guideOffsetHalfHours, focused = focused, allowMarquee = allowMarquee, ) } } @Composable private fun GuideTimeline( modifier: Modifier, programs: List, nowEpoch: Long, settings: AppSettings, selectedChannel: Boolean, guideOffsetHalfHours: Int, focused: Boolean, allowMarquee: Boolean, ) { val start = guideWindowStart(nowEpoch, guideOffsetHalfHours) val end = start + 7200L val shift = settings.epgTimeOffsetHours * 3600L val visible = remember(programs, start, end, shift) { programs.asSequence().filter { (it.endEpoch + shift) > start && (it.startEpoch + shift) < end }.take(8).toList() } BoxWithConstraints(modifier) { if (visible.isEmpty()) { Box(Modifier.fillMaxSize(), contentAlignment = Alignment.CenterStart) { Text( "No Information", color = LuxMuted.copy(alpha = .70f), fontSize = guideFont(settings), modifier = Modifier.padding(start = 10.dp), ) } } else { visible.forEach { program -> val pStart = max(start, program.startEpoch + shift) val pEnd = min(end, program.endEpoch + shift) val leftFraction = ((pStart - start).toFloat() / 7200f).coerceIn(0f, 1f) val widthFraction = ((pEnd - pStart).toFloat() / 7200f).coerceAtLeast(.045f) val isCurrent = nowEpoch in (program.startEpoch + shift) until (program.endEpoch + shift) val shouldMarquee = allowMarquee && focused && (isCurrent || program == visible.first()) Box( Modifier .offset(x = maxWidth * leftFraction) .width(maxWidth * widthFraction) .fillMaxHeight() .padding(1.dp) .clip(RoundedCornerShape(5.dp)) .background( when { focused -> Color(0xFF5A4729) isCurrent && settings.highlightCurrentProgram -> Color(0xFF263B4A) selectedChannel -> Color(0xFF202E39) else -> Color(0xFF172129) } ) .border(1.dp, if (focused) LuxGold.copy(alpha = .60f) else LuxLine.copy(alpha = .55f), RoundedCornerShape(5.dp)) .padding(horizontal = 8.dp, vertical = 5.dp) ) { Column { Text( program.title.ifBlank { "No information" }, color = LuxText, fontSize = guideFont(settings), fontWeight = if (isCurrent || focused) FontWeight.SemiBold else FontWeight.Normal, maxLines = if (shouldMarquee) 1 else if (settings.twoLineProgramTitles) 2 else 1, overflow = if (shouldMarquee) TextOverflow.Clip else TextOverflow.Ellipsis, modifier = Modifier.fillMaxWidth().then(if (shouldMarquee) Modifier.basicMarquee() else Modifier), ) if (settings.twoLineProgramTitles && program.title.isNotBlank()) { Text( "${formatTime(program.startEpoch + shift)} – ${formatTime(program.endEpoch + shift)}", color = LuxMuted, fontSize = 8.sp, maxLines = 1, ) } } } } } if (settings.fullHeightTimeIndicator && nowEpoch in start until end) { val fraction = ((nowEpoch - start).toFloat() / 7200f).coerceIn(0f, 1f) Box(Modifier.offset(x = maxWidth * fraction).width(2.dp).fillMaxHeight().background(LuxGold.copy(alpha = .9f))) } } } @Composable private fun BoxScope.GroupDrawer( categories: List, selectedCategory: String?, drawerWidth: Dp, onCategory: (String?) -> Unit, onOpenMultiView: () -> Unit, onCloseToGuide: () -> Unit, onMainMenu: () -> Unit, ) { val firstFocus = remember { FocusRequester() } val listState = rememberLazyListState() val selectedProviderIndex = categories.indexOfFirst { it.id == selectedCategory } val targetIndex = if (selectedCategory == null || selectedProviderIndex < 0) 0 else selectedProviderIndex + 2 LaunchedEffect(categories, selectedCategory) { val itemCount = categories.size + 2 if (itemCount > 0) listState.scrollToItem(targetIndex.coerceIn(0, itemCount - 1)) androidx.compose.runtime.withFrameNanos { } runCatching { firstFocus.requestFocus() } } Column( Modifier.align(Alignment.CenterStart) .panelReveal() .fillMaxHeight() .width(drawerWidth) .focusGroup() .background(Color(0xF5090D12)) .border(1.dp, LuxLine) .onPreviewKeyEvent { event -> if (event.type != KeyEventType.KeyDown) return@onPreviewKeyEvent false when (event.key) { Key.DirectionLeft -> { onMainMenu() true } Key.DirectionRight, Key.Back -> { onCloseToGuide() true } else -> false } } .padding(16.dp) ) { Text("LIVE GROUPS", color = LuxGold, fontSize = 10.sp, fontWeight = FontWeight.Bold, letterSpacing = 1.5.sp) Text("LEFT • TiviLux menu RIGHT • Guide", color = LuxMuted, fontSize = 9.sp, modifier = Modifier.padding(top = 3.dp, bottom = 12.dp)) LazyColumn(Modifier.weight(1f), state = listState, verticalArrangement = Arrangement.spacedBy(3.dp)) { item { DrawerCategoryRow( name = "All Channels", selected = selectedCategory == null, modifier = if (targetIndex == 0) Modifier.focusRequester(firstFocus) else Modifier, ) { onCategory(null) } } item { DrawerCategoryRow( name = "MultiView • 2 × 2", selected = false, ) { onOpenMultiView() } } itemsIndexed(categories, key = { _, item -> item.id }) { index, category -> DrawerCategoryRow( category.name, selectedCategory == category.id, modifier = if (index + 2 == targetIndex) Modifier.focusRequester(firstFocus) else Modifier, ) { onCategory(category.id) } } } } } @Composable private fun DrawerCategoryRow( name: String, selected: Boolean, modifier: Modifier = Modifier, onClick: () -> Unit, ) { var focused by remember { mutableStateOf(false) } Box( modifier.fillMaxWidth() .clip(RoundedCornerShape(8.dp)) .background(if (selected || focused) Color(0xFF24313C) else Color.Transparent) .border(1.dp, if (focused) LuxGold else Color.Transparent, RoundedCornerShape(8.dp)) .onFocusChanged { focused = it.isFocused } .focusable() .clickable(onClick = onClick) .padding(horizontal = 11.dp, vertical = 10.dp) ) { Text( name, color = if (selected || focused) LuxText else LuxMuted, fontSize = 11.sp, fontWeight = if (selected) FontWeight.Bold else FontWeight.Normal, maxLines = 1, overflow = TextOverflow.Ellipsis, ) } } @Composable private fun BoxScope.GuideQuickSettingsPanel( settings: AppSettings, favoritesGuide: Boolean, categorySort: String, onCategorySortChanged: (String) -> Unit, focusedChannel: MediaEntry?, onSettingsChanged: (AppSettings) -> Unit, isFocusedFavorite: Boolean, onFavorite: (MediaEntry) -> Unit, onStartReorder: () -> Unit, onHideChannel: (MediaEntry) -> Unit, onOpenMultiView: () -> Unit, onOpenFullSettings: () -> Unit, onClose: () -> Unit, consumeOpeningSelectRelease: Boolean = false, ) { // Build 79: HOLD OK opens this panel. The physical OK key is still down when focus moves // to the first row (Add/Remove Favorite). Consume that opening press through its matching // KeyUp so the release can never activate the newly-focused Favorite action. var swallowOpeningSelect by remember { mutableStateOf(consumeOpeningSelectRelease) } val firstFocus = remember { FocusRequester() } LaunchedEffect(Unit) { androidx.compose.runtime.withFrameNanos { } runCatching { firstFocus.requestFocus() } } val currentSort = if (favoritesGuide) settings.favoriteChannelSort else categorySort val displaySort = if (currentSort == "Name") "A-Z" else currentSort Column( Modifier.align(Alignment.CenterEnd) .fillMaxHeight() .width(350.dp) .focusGroup() .background(Color(0xF5090D12)) .border(1.dp, LuxLine) .onPreviewKeyEvent { event -> if (swallowOpeningSelect && (event.key == Key.Enter || event.key == Key.DirectionCenter)) { if (event.type == KeyEventType.KeyUp) swallowOpeningSelect = false true } else if (event.type == KeyEventType.KeyDown && (event.key == Key.Back || event.key == Key.DirectionLeft)) { onClose() true } else false } .padding(16.dp), verticalArrangement = Arrangement.spacedBy(6.dp), ) { Text(if (favoritesGuide) "FAVORITES GUIDE" else "GUIDE SETTINGS", color = LuxGold, fontSize = 10.sp, fontWeight = FontWeight.Bold, letterSpacing = 1.5.sp) Text("HOLD OK • opens this panel", color = LuxMuted, fontSize = 9.sp, modifier = Modifier.padding(bottom = 8.dp)) if (focusedChannel != null) { QuickSettingRow( if (isFocusedFavorite) "Remove from Favorites" else "Add to Favorites", if (isFocusedFavorite) "REMOVE" else "ADD", Modifier.focusRequester(firstFocus), ) { onFavorite(focusedChannel) } } QuickSettingRow( "Channel order", displaySort, if (focusedChannel == null) Modifier.focusRequester(firstFocus) else Modifier, ) { val next = when (currentSort) { "Provider" -> "A-Z" "Name", "A-Z" -> "Manual" else -> "Provider" } if (favoritesGuide) onSettingsChanged(settings.copy(favoriteChannelSort = next)) else onCategorySortChanged(next) } if (currentSort == "Manual") { QuickSettingRow("Reorder channels", "OPEN") { onStartReorder() } } QuickSettingRow("Channel logos", if (settings.showChannelLogos) "ON" else "OFF") { onSettingsChanged(settings.copy(showChannelLogos = !settings.showChannelLogos)) } QuickSettingRow("Channel numbers", if (settings.showChannelNumbers) "ON" else "OFF") { onSettingsChanged(settings.copy(showChannelNumbers = !settings.showChannelNumbers)) } if (!favoritesGuide && currentSort != "Manual") { QuickSettingRow("Favorites first", if (settings.favoritesFirst) "ON" else "OFF") { onSettingsChanged(settings.copy(favoritesFirst = !settings.favoritesFirst)) } } QuickSettingRow("Guide density", settings.guideDensity) { val next = when (settings.guideDensity) { "Compact" -> "Comfortable" "Comfortable" -> "Spacious" else -> "Compact" } onSettingsChanged(settings.copy(guideDensity = next)) } QuickSettingRow("Program descriptions", if (settings.showProgramDescriptions) "ON" else "OFF") { onSettingsChanged(settings.copy(showProgramDescriptions = !settings.showProgramDescriptions)) } if (focusedChannel != null) { QuickSettingRow("Hide this channel", "HIDE") { onHideChannel(focusedChannel) } } Spacer(Modifier.height(8.dp)) QuickSettingRow("MultiView", "OPEN 2×2") { onOpenMultiView() } QuickSettingRow("Theme", settings.colorTheme) { val names = tv.tivilux.nativeplayer.ui.theme.TiviLuxThemeNames val next = names[(names.indexOf(settings.colorTheme).coerceAtLeast(0) + 1) % names.size] onSettingsChanged(settings.copy(colorTheme = next)) } QuickSettingRow("Theme Studio", "OPEN") { tv.tivilux.nativeplayer.ui.theme.ThemeStudioNavigation.openOnNextSettings = true onOpenFullSettings() } QuickSettingRow("All settings", "OPEN") { onOpenFullSettings() } Spacer(Modifier.weight(1f)) Text("BACK / LEFT • close", color = LuxMuted, fontSize = 9.sp) } } /** * D-pad-first manual ordering. OK picks up/drops a channel, UP/DOWN moves it one position, * LEFT sends it to the top and RIGHT sends it to the bottom. BACK saves the order. * The caller merges a category-sized reorder back into the complete profile order. */ @Composable private fun BoxScope.ChannelReorderOverlay( channels: List, favoritesGuide: Boolean, onSave: (List) -> Unit, ) { var working by remember(channels) { mutableStateOf(channels.toList()) } var focusedIndex by remember(channels) { mutableStateOf(0) } var moving by remember { mutableStateOf(false) } val focusRequester = remember { FocusRequester() } val listState = rememberLazyListState() LaunchedEffect(Unit) { androidx.compose.runtime.withFrameNanos { } runCatching { focusRequester.requestFocus() } } LaunchedEffect(focusedIndex, working.size) { if (working.isEmpty()) return@LaunchedEffect val visible = listState.layoutInfo.visibleItemsInfo if (visible.isEmpty()) { listState.scrollToItem(focusedIndex.coerceIn(0, working.lastIndex)) return@LaunchedEffect } val first = visible.first().index val last = visible.last().index when { focusedIndex <= first + 1 -> listState.scrollToItem((focusedIndex - 1).coerceAtLeast(0)) focusedIndex >= last - 1 -> listState.scrollToItem((focusedIndex - (visible.size - 2)).coerceAtLeast(0)) } } fun moveSelected(target: Int) { if (working.isEmpty()) return val from = focusedIndex.coerceIn(0, working.lastIndex) val to = target.coerceIn(0, working.lastIndex) if (from == to) return val copy = working.toMutableList() val item = copy.removeAt(from) copy.add(to, item) working = copy focusedIndex = to } Box( Modifier.align(Alignment.Center) .fillMaxSize() .background(Color(0xF70A0E13)) .focusRequester(focusRequester) .focusable() .onPreviewKeyEvent { event -> if (event.type != KeyEventType.KeyDown) return@onPreviewKeyEvent true if (working.isEmpty()) { if (event.key == Key.Back) onSave(emptyList()) return@onPreviewKeyEvent true } when (event.key) { Key.DirectionUp -> { if (moving) moveSelected(focusedIndex - 1) else focusedIndex = (focusedIndex - 1).coerceAtLeast(0) true } Key.DirectionDown -> { if (moving) moveSelected(focusedIndex + 1) else focusedIndex = (focusedIndex + 1).coerceAtMost(working.lastIndex) true } Key.DirectionLeft -> { if (moving) moveSelected(0) true } Key.DirectionRight -> { if (moving) moveSelected(working.lastIndex) true } Key.Enter, Key.DirectionCenter -> { moving = !moving true } Key.Back -> { onSave(working.map { it.id }) true } else -> true } } .padding(horizontal = 58.dp, vertical = 34.dp) ) { Column(Modifier.fillMaxSize()) { Text( if (favoritesGuide) "MANUAL FAVORITES ORDER" else "MANUAL TV GUIDE ORDER", color = LuxGold, fontSize = 11.sp, fontWeight = FontWeight.Bold, letterSpacing = 1.6.sp, ) Text("Put every channel exactly where you want it.", color = LuxText, fontSize = 28.sp, fontWeight = FontWeight.SemiBold) Text( if (moving) "MOVING • ↑ / ↓ move • LEFT top • RIGHT bottom • OK drop • BACK save" else "↑ / ↓ select • OK pick up • BACK save & close", color = if (moving) LuxGold else LuxMuted, fontSize = 10.sp, modifier = Modifier.padding(top = 4.dp, bottom = 16.dp), ) LazyColumn( modifier = Modifier.fillMaxWidth().weight(1f) .background(LuxPanel.copy(alpha = .94f), RoundedCornerShape(16.dp)) .border(1.dp, LuxLine, RoundedCornerShape(16.dp)) .padding(vertical = 6.dp), state = listState, ) { itemsIndexed(working, key = { _, item -> item.id }) { index, channel -> val selected = index == focusedIndex Row( Modifier.fillMaxWidth() .padding(horizontal = 8.dp, vertical = 2.dp) .background( when { selected && moving -> Color(0xFF5A4729) selected -> Color(0xFF24313C) else -> Color.Transparent }, RoundedCornerShape(10.dp), ) .border(1.dp, if (selected) LuxGold else Color.Transparent, RoundedCornerShape(10.dp)) .padding(horizontal = 14.dp, vertical = 11.dp), verticalAlignment = Alignment.CenterVertically, ) { Text("${index + 1}", color = if (selected) LuxGold else LuxMuted, fontSize = 10.sp, modifier = Modifier.width(42.dp)) if (channel.image.isNotBlank()) { AsyncImage( model = channel.image, contentDescription = null, modifier = Modifier.size(34.dp).padding(3.dp), contentScale = ContentScale.Fit, ) Spacer(Modifier.width(10.dp)) } Text( channel.name, color = LuxText, fontSize = 13.sp, fontWeight = if (selected) FontWeight.SemiBold else FontWeight.Normal, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f), ) if (channel.number > 0) Text("CH ${channel.number}", color = LuxMuted, fontSize = 9.sp) if (selected) { Spacer(Modifier.width(14.dp)) Text(if (moving) "MOVING" else "PICK UP", color = LuxGold, fontSize = 9.sp, fontWeight = FontWeight.Bold) } } } } } } } @Composable private fun QuickSettingRow( label: String, value: String, modifier: Modifier = Modifier, onClick: () -> Unit, ) { var focused by remember { mutableStateOf(false) } Row( modifier.fillMaxWidth() .clip(RoundedCornerShape(9.dp)) .background(if (focused) Color(0xFF263743) else Color(0xFF131A21)) .border(1.dp, if (focused) LuxGold else LuxLine.copy(alpha = .55f), RoundedCornerShape(9.dp)) .onFocusChanged { focused = it.isFocused } .focusable() .clickable(onClick = onClick) .padding(horizontal = 12.dp, vertical = 11.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween, ) { Text(label, color = LuxText, fontSize = 11.sp, fontWeight = if (focused) FontWeight.SemiBold else FontWeight.Normal) Text(value, color = if (focused) LuxGold else LuxMuted, fontSize = 9.sp, fontWeight = FontWeight.Bold) } } private fun guideWindowStart(nowEpoch: Long, offsetHalfHours: Int = 0): Long = ((nowEpoch / 1800L) * 1800L) + (offsetHalfHours * 1800L) private fun programProgress(program: EpgProgram, nowEpoch: Long, shift: Long): Float { val start = program.startEpoch + shift val end = program.endEpoch + shift if (end <= start) return 0f return ((nowEpoch - start).toFloat() / (end - start).toFloat()).coerceIn(0f, 1f) } private fun guideFont(settings: AppSettings) = when (settings.guideFontSize) { "Small" -> 9.sp "Large" -> 13.sp else -> 11.sp } private fun formatTime(epoch: Long): String = SimpleDateFormat("h:mm a", Locale.getDefault()).format(Date(epoch * 1000L)) private fun formatClock(epoch: Long): String = SimpleDateFormat("h:mm a", Locale.getDefault()).format(Date(epoch * 1000L))