package tv.tivilux.nativeplayer.ui.screens import androidx.activity.compose.BackHandler import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.animation.slideInVertically import androidx.compose.animation.slideOutVertically import androidx.compose.foundation.Image 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.CircularProgressIndicator import androidx.compose.material3.Text import androidx.compose.runtime.Composable 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.draw.scale 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.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.graphics.Color import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource 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 androidx.compose.ui.window.Dialog import androidx.compose.ui.window.DialogProperties import coil.compose.AsyncImage import kotlinx.coroutines.delay import tv.tivilux.nativeplayer.R import tv.tivilux.nativeplayer.model.MediaEntry import tv.tivilux.nativeplayer.model.SportLeague import tv.tivilux.nativeplayer.model.SportsEvent import tv.tivilux.nativeplayer.model.SportsLeagueSummary import tv.tivilux.nativeplayer.ui.components.LuxButton 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.Calendar import java.util.Date import java.util.Locale import java.util.TimeZone // One-line emergency rollback. The GOLDEN SportsScreen remains compiled in the same APK source. private const val SPORTS_NEXT_UI_ENABLED = true /** * TiviLux Sports Zone NEXT. * * This screen deliberately leaves the proven sports repositories, schedule loading, EPG matching, * provider fallbacks and playback callbacks untouched. The only added intelligence is display-time * ranking of feeds that TiviLux has ALREADY matched. Choosing a feed still sends the original * MediaEntry to the existing onPlayChannel callback. * * SportsScreen.kt remains in the project as the production fallback. */ @Composable fun SportsScreenV2( selectedLeague: SportLeague, summaries: List, events: List, channels: List, scanning: Boolean, scanCompleted: Int, scanTotal: Int, preparing: Boolean, loadingStage: String, readyNoticeToken: Long, readyNoticePending: Boolean, onReadyNoticeShown: (Long) -> Unit, onLeague: (SportLeague) -> Unit, onRefresh: () -> Unit, onPlayChannel: (MediaEntry) -> Unit, ) { if (!SPORTS_NEXT_UI_ENABLED) { SportsScreen( selectedLeague = selectedLeague, summaries = summaries, events = events, channels = channels, scanning = scanning, scanCompleted = scanCompleted, scanTotal = scanTotal, preparing = preparing, loadingStage = loadingStage, readyNoticeToken = readyNoticeToken, readyNoticePending = readyNoticePending, onReadyNoticeShown = onReadyNoticeShown, onLeague = onLeague, onRefresh = onRefresh, onPlayChannel = onPlayChannel, ) return } var now by remember { mutableStateOf(System.currentTimeMillis() / 1000L) } var showReadyBanner by remember { mutableStateOf(false) } var feedPicker by remember { mutableStateOf(null) } // Explicit TV focus lanes keep DPAD navigation deterministic: // category rail -> featured game -> main game row, with RIGHT reserved for the compact Up Next panel. val selectedLeagueFocus = remember { FocusRequester() } val featuredFocus = remember { FocusRequester() } val upNextFocus = remember { FocusRequester() } val primaryGamesFocus = remember { FocusRequester() } LaunchedEffect(Unit) { while (true) { delay(30_000) now = System.currentTimeMillis() / 1000L } } LaunchedEffect(readyNoticeToken) { if (readyNoticePending && readyNoticeToken > 0L) { showReadyBanner = true onReadyNoticeShown(readyNoticeToken) delay(3_800) showReadyBanner = false } } val priorityLeague = sportsPriorityV2() val safeEvents = remember(events) { events.distinctBy { it.id } } val safeChannels = remember(channels) { channels.distinctBy { it.id } } val orderedEvents = remember(safeEvents, selectedLeague, priorityLeague, now) { safeEvents.sortedWith( compareBy { event -> if (selectedLeague == SportLeague.ALL && priorityLeague != null && event.league == priorityLeague) 0 else 1 }.thenBy { event -> if (event.isLive(now)) 0 else if (event.startEpoch > now) 1 else 2 } .thenBy { event -> if (priorityLeague == SportLeague.COLLEGE_FOOTBALL && event.league == SportLeague.COLLEGE_FOOTBALL) collegeRankTierV2(event) else 3 } .thenBy { bestCollegeRankV2(it) } .thenBy { it.startEpoch } ) } val live = orderedEvents.filter { it.isLive(now) } val upcoming = orderedEvents.filter { it.startEpoch > now && !it.completed } val earlier = orderedEvents.filter { it.completed || (!it.isLive(now) && it.endEpoch <= now) } val top25 = if (priorityLeague == SportLeague.COLLEGE_FOOTBALL) { orderedEvents.filter { it.league == SportLeague.COLLEGE_FOOTBALL && !it.completed && (it.awayRank in 1..25 || it.homeRank in 1..25) } } else emptyList() val primetime = if (priorityLeague == SportLeague.COLLEGE_FOOTBALL) { orderedEvents.filter { it.league == SportLeague.COLLEGE_FOOTBALL && !it.completed && easternHourV2(it.startEpoch) >= 18 } } else emptyList() val allCollege = if (priorityLeague == SportLeague.COLLEGE_FOOTBALL) { orderedEvents.filter { it.league == SportLeague.COLLEGE_FOOTBALL && !it.completed } } else emptyList() val preferredFeatured = priorityLeague?.let { league -> live.firstOrNull { it.league == league } } ?: priorityLeague?.let { league -> upcoming.firstOrNull { it.league == league } } ?: live.firstOrNull() ?: upcoming.firstOrNull() ?: earlier.lastOrNull() var featuredId by remember(selectedLeague) { mutableStateOf(null) } LaunchedEffect(safeEvents, selectedLeague, priorityLeague) { val current = safeEvents.firstOrNull { it.id == featuredId } val shouldPromotePriority = selectedLeague == SportLeague.ALL && priorityLeague != null && current != null && current.league != priorityLeague && safeEvents.any { it.league == priorityLeague && (it.isLive(now) || it.startEpoch > now) } if (featuredId == null || current == null || shouldPromotePriority) featuredId = preferredFeatured?.id } val featured = safeEvents.firstOrNull { it.id == featuredId } ?: preferredFeatured fun openEvent(event: SportsEvent) { when (event.feeds.size) { 0 -> Unit 1 -> onPlayChannel(event.feeds.first()) else -> feedPicker = event } } BackHandler(feedPicker != null) { feedPicker = null } Box(Modifier.fillMaxSize()) { LazyColumn( Modifier.fillMaxSize().padding(horizontal = 22.dp, vertical = 16.dp), verticalArrangement = Arrangement.spacedBy(14.dp), contentPadding = PaddingValues(bottom = 34.dp), ) { item { SportsHeaderV2( liveCount = live.size, eventCount = safeEvents.size, feedCount = safeChannels.size, scanning = scanning, scanCompleted = scanCompleted, scanTotal = scanTotal, preparing = preparing, loadingStage = loadingStage, onRefresh = onRefresh, ) } item { LeagueRailV2( selectedLeague = selectedLeague, summaries = summaries, priorityLeague = if (selectedLeague == SportLeague.ALL) priorityLeague else null, selectedFocusRequester = selectedLeagueFocus, downFocusRequester = featuredFocus, onLeague = onLeague, ) } item { Row( Modifier.fillMaxWidth().height(292.dp), horizontalArrangement = Arrangement.spacedBy(12.dp), ) { FeaturedGameV2( event = featured, now = now, modifier = Modifier.weight(2.35f).fillMaxHeight(), focusRequester = featuredFocus, upFocusRequester = selectedLeagueFocus, rightFocusRequester = upNextFocus, downFocusRequester = primaryGamesFocus, hasRightTarget = upcoming.any { it.id != featured?.id }, hasDownTarget = live.isNotEmpty() || upcoming.isNotEmpty(), onOpenGame = { featured?.let(::openEvent) }, onBestFeed = { featured?.let { event -> rankFeedsV2(event).firstOrNull()?.feed?.let(onPlayChannel) } }, onOpenFeeds = { featured?.takeIf { it.feeds.isNotEmpty() }?.let { feedPicker = it } }, ) UpNextPanelV2( events = upcoming.filter { it.id != featured?.id }.take(5), now = now, modifier = Modifier.weight(.85f).fillMaxHeight(), firstFocusRequester = upNextFocus, leftFocusRequester = featuredFocus, onFocusEvent = { featuredId = it.id }, onOpenEvent = ::openEvent, ) } } if (live.isNotEmpty()) { item { SectionTitleV2("LIVE NOW", "Focus a matchup to move it into the featured window") } item { LazyRow(horizontalArrangement = Arrangement.spacedBy(11.dp), contentPadding = PaddingValues(end = 24.dp)) { itemsIndexed(live, key = { _, event -> "live:${event.id}" }) { index, event -> SportsEventCardV2( event = event, now = now, modifier = Modifier.width(430.dp).height(245.dp), focusRequester = if (index == 0) primaryGamesFocus else null, upFocusRequester = if (index == 0) featuredFocus else null, onFocused = { featuredId = event.id }, onClick = { openEvent(event) }, ) } } } } item { MatchedFeedsBarV2( event = featured, preparing = preparing, onOpenFeeds = { featured?.takeIf { it.feeds.isNotEmpty() }?.let { feedPicker = it } }, ) } if (top25.isNotEmpty() && selectedLeague in setOf(SportLeague.ALL, SportLeague.COLLEGE_FOOTBALL)) { item { SectionTitleV2("TOP 25 SHOWCASE", "Ranked College Football is automatically elevated on Saturday") } item { LazyRow(horizontalArrangement = Arrangement.spacedBy(11.dp), contentPadding = PaddingValues(end = 24.dp)) { items(top25, key = { "top25:${it.id}" }) { event -> SportsEventCardV2( event = event, now = now, modifier = Modifier.width(430.dp).height(245.dp), onFocused = { featuredId = event.id }, onClick = { openEvent(event) }, ) } } } } if (upcoming.isNotEmpty()) { item { SectionTitleV2("UP NEXT", "Verified schedule + matched provider feeds") } item { LazyRow(horizontalArrangement = Arrangement.spacedBy(11.dp), contentPadding = PaddingValues(end = 24.dp)) { itemsIndexed(upcoming, key = { _, event -> "up:${event.id}" }) { index, event -> val isPrimaryTarget = live.isEmpty() && index == 0 SportsEventCardV2( event = event, now = now, modifier = Modifier.width(430.dp).height(245.dp), focusRequester = if (isPrimaryTarget) primaryGamesFocus else null, upFocusRequester = if (isPrimaryTarget) featuredFocus else null, onFocused = { featuredId = event.id }, onClick = { openEvent(event) }, ) } } } } if (primetime.isNotEmpty() && selectedLeague in setOf(SportLeague.ALL, SportLeague.COLLEGE_FOOTBALL)) { item { SectionTitleV2("SATURDAY PRIMETIME", "Evening College Football window sorted by live state and ranking") } item { LazyRow(horizontalArrangement = Arrangement.spacedBy(11.dp), contentPadding = PaddingValues(end = 24.dp)) { items(primetime, key = { "prime:${it.id}" }) { event -> SportsEventCardV2( event = event, now = now, modifier = Modifier.width(430.dp).height(245.dp), onFocused = { featuredId = event.id }, onClick = { openEvent(event) }, ) } } } } if (allCollege.isNotEmpty() && selectedLeague in setOf(SportLeague.ALL, SportLeague.COLLEGE_FOOTBALL)) { item { SectionTitleV2("ALL COLLEGE GAMES", "The complete Saturday slate remains available") } item { LazyRow(horizontalArrangement = Arrangement.spacedBy(11.dp), contentPadding = PaddingValues(end = 24.dp)) { items(allCollege, key = { "cfb:${it.id}" }) { event -> SportsEventCardV2( event = event, now = now, modifier = Modifier.width(430.dp).height(245.dp), onFocused = { featuredId = event.id }, onClick = { openEvent(event) }, ) } } } } item { SectionTitleV2( if (selectedLeague == SportLeague.ALL) "TEAM & LEAGUE CHANNELS" else "${selectedLeague.label.uppercase()} CHANNELS", "Dedicated provider channels remain available when schedule or EPG matching is incomplete", ) } if (safeChannels.isEmpty()) { item { EmptySportsStateV2(scanning) } } else { item { LazyRow(horizontalArrangement = Arrangement.spacedBy(10.dp), contentPadding = PaddingValues(end = 24.dp)) { items(safeChannels, key = { "ch:${it.id}" }) { channel -> SportsChannelCardV2(channel, Modifier.width(238.dp).height(96.dp)) { onPlayChannel(channel) } } } } } if (earlier.isNotEmpty()) { item { SectionTitleV2("RECENT RESULTS", "Final scores from completed games") } item { LazyRow(horizontalArrangement = Arrangement.spacedBy(10.dp), contentPadding = PaddingValues(end = 24.dp)) { items(earlier.reversed(), key = { "earlier:${it.id}" }) { event -> SportsEventCardV2( event = event, now = now, modifier = Modifier.width(430.dp).height(245.dp), onFocused = { featuredId = event.id }, onClick = { openEvent(event) }, ) } } } } } AnimatedVisibility( visible = showReadyBanner, modifier = Modifier.align(Alignment.TopEnd).padding(top = 20.dp, end = 26.dp), enter = slideInVertically(initialOffsetY = { -it }) + fadeIn(), exit = slideOutVertically(targetOffsetY = { -it }) + fadeOut(), ) { SportsReadyBannerV2() } feedPicker?.let { event -> FeedPickerV2( event = event, now = now, onDismiss = { feedPicker = null }, onPlay = { feed -> feedPicker = null onPlayChannel(feed) }, ) } } } @Composable private fun SportsHeaderV2( liveCount: Int, eventCount: Int, feedCount: Int, scanning: Boolean, scanCompleted: Int, scanTotal: Int, preparing: Boolean, loadingStage: String, onRefresh: () -> Unit, ) { Row( Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween, ) { Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(16.dp)) { Image( painter = painterResource(R.drawable.tivilux_wordmark), contentDescription = "TiviLux", modifier = Modifier.width(142.dp).height(48.dp), ) Box(Modifier.width(1.dp).height(34.dp).background(LuxLine)) Column(verticalArrangement = Arrangement.spacedBy(2.dp)) { Text("SPORTS ZONE", color = LuxText, fontSize = 23.sp, fontWeight = FontWeight.Black, letterSpacing = .7.sp) Text( when { scanning && scanTotal > 0 -> "Matching provider feeds $scanCompleted/$scanTotal" preparing && loadingStage.isNotBlank() -> loadingStage preparing -> "Preparing Game Center…" else -> "Live games • more feeds • all sports" }, color = LuxMuted, fontSize = 9.sp, ) } } Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically) { StatTileV2("LIVE", liveCount.toString(), live = liveCount > 0) StatTileV2("EVENTS", eventCount.toString()) StatTileV2("FEEDS", feedCount.toString()) LuxButton(if (scanning) "SCANNING…" else "REFRESH", onRefresh, enabled = !scanning) } } } @Composable private fun StatTileV2(label: String, value: String, live: Boolean = false) { Row( Modifier.widthIn(min = 88.dp).background(Color(0x77111820), RoundedCornerShape(13.dp)) .border(1.dp, if (live) LuxGreen.copy(alpha = .48f) else LuxLine, RoundedCornerShape(13.dp)) .padding(horizontal = 12.dp, vertical = 9.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(7.dp), ) { if (live) Box(Modifier.size(7.dp).background(LuxGreen, RoundedCornerShape(50))) Column { Text(value, color = LuxText, fontSize = 13.sp, fontWeight = FontWeight.Black) Text(label, color = LuxMuted, fontSize = 7.sp, fontWeight = FontWeight.Bold, letterSpacing = .7.sp) } } } @Composable private fun LeagueRailV2( selectedLeague: SportLeague, summaries: List, priorityLeague: SportLeague?, selectedFocusRequester: FocusRequester, downFocusRequester: FocusRequester, onLeague: (SportLeague) -> Unit, ) { val allChannels = summaries.sumOf { it.channelCount } val allEvents = summaries.sumOf { it.eventCount } val ordered = summaries.sortedWith( compareBy { if (priorityLeague != null && it.league == priorityLeague) 0 else 1 } .thenBy { it.league.ordinal } ) val items = listOf(SportsLeagueSummary(SportLeague.ALL, allChannels, allEvents, summaries.sumOf { it.liveCount })) + ordered LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp), contentPadding = PaddingValues(end = 24.dp)) { items(items, key = { "league:${it.league.name}" }) { summary -> LeagueChipV2( summary = summary, selected = selectedLeague == summary.league, priority = priorityLeague == summary.league, selectedFocusRequester = selectedFocusRequester, downFocusRequester = downFocusRequester, ) { onLeague(summary.league) } } } } @Composable private fun LeagueChipV2( summary: SportsLeagueSummary, selected: Boolean, priority: Boolean, selectedFocusRequester: FocusRequester, downFocusRequester: FocusRequester, onClick: () -> Unit, ) { var focused by remember { mutableStateOf(false) } val countText = when { summary.liveCount > 0 -> "${summary.liveCount} LIVE" summary.eventCount > 0 -> "${summary.eventCount} GAMES" else -> "${summary.channelCount} CH" } Column( Modifier.widthIn(min = 108.dp).clip(RoundedCornerShape(13.dp)) .background( if (selected || focused) Brush.verticalGradient(listOf(Color(0xFF332817), Color(0xFF181B21))) else Brush.verticalGradient(listOf(Color(0xFF171C23), Color(0xFF12161C))) ) .border(1.dp, if (focused || selected) LuxGold else if (priority) LuxGold.copy(alpha = .35f) else LuxLine, RoundedCornerShape(13.dp)) .then(if (selected) Modifier.focusRequester(selectedFocusRequester) else Modifier) .onFocusChanged { focused = it.isFocused } .onPreviewKeyEvent { event -> if (event.type == KeyEventType.KeyDown && event.key == Key.DirectionDown) { runCatching { downFocusRequester.requestFocus() } true } else false } .focusable().clickable(onClick = onClick) .padding(horizontal = 12.dp, vertical = 9.dp), verticalArrangement = Arrangement.spacedBy(2.dp), ) { Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp)) { if (summary.liveCount > 0) Box(Modifier.size(6.dp).background(LuxGreen, RoundedCornerShape(50))) Text(summary.league.label, color = LuxText, fontSize = 10.sp, fontWeight = FontWeight.Bold, maxLines = 1) } Text(countText, color = if (selected) LuxGold else LuxMuted, fontSize = 7.sp, fontWeight = FontWeight.Bold) } } @Composable private fun FeaturedGameV2( event: SportsEvent?, now: Long, modifier: Modifier, focusRequester: FocusRequester, upFocusRequester: FocusRequester, rightFocusRequester: FocusRequester, downFocusRequester: FocusRequester, hasRightTarget: Boolean, hasDownTarget: Boolean, onOpenGame: () -> Unit, onBestFeed: () -> Unit, onOpenFeeds: () -> Unit, ) { var focused by remember { mutableStateOf(false) } Box( modifier.clip(RoundedCornerShape(22.dp)) .background( Brush.horizontalGradient(listOf(Color(0xFF08121D), Color(0xFF10263B), Color(0xFF10161E))) ) .border(2.dp, if (focused) LuxGold else LuxGold.copy(alpha = .28f), RoundedCornerShape(22.dp)) .focusRequester(focusRequester) .onFocusChanged { focused = it.isFocused } .onPreviewKeyEvent { keyEvent -> if (keyEvent.type != KeyEventType.KeyDown) return@onPreviewKeyEvent false when (keyEvent.key) { Key.DirectionUp -> { runCatching { upFocusRequester.requestFocus() } true } Key.DirectionRight -> { if (hasRightTarget) { runCatching { rightFocusRequester.requestFocus() } true } else false } Key.DirectionDown -> { if (hasDownTarget) { runCatching { downFocusRequester.requestFocus() } true } else false } else -> false } } .focusable() .clickable(enabled = event?.feeds?.isNotEmpty() == true, onClick = onOpenGame), ) { Box( Modifier.fillMaxSize().background( Brush.verticalGradient(listOf(Color.Transparent, Color(0x8F071019))) ) ) if (event == null) { Column(Modifier.align(Alignment.Center).padding(24.dp), horizontalAlignment = Alignment.CenterHorizontally) { Text("GAME CENTER", color = LuxGold, fontSize = 10.sp, fontWeight = FontWeight.Black, letterSpacing = 1.5.sp) Spacer(Modifier.height(8.dp)) Text("No scheduled matchup is available yet", color = LuxText, fontSize = 20.sp, fontWeight = FontWeight.SemiBold) Text("Team and league channels remain available below.", color = LuxMuted, fontSize = 10.sp) } return@Box } Column(Modifier.fillMaxSize().padding(18.dp), verticalArrangement = Arrangement.SpaceBetween) { Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) { Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(9.dp)) { Text(event.league.label.uppercase(), color = LuxText, fontSize = 12.sp, fontWeight = FontWeight.Black) StatusBadgeV2(event, now) } Text( "${relativeDayV2(event.startEpoch)} • ${formatTimeV2(event.startEpoch)}", color = LuxMuted, fontSize = 9.sp, fontWeight = FontWeight.Medium, ) } if (event.awayTeam.isNotBlank() && event.homeTeam.isNotBlank()) { Row( Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Center, ) { FeatureTeamV2( team = event.awayTeam, logo = event.awayLogo, score = if (event.isLive(now) || event.completed) event.awayScore else "", rank = event.awayRank, modifier = Modifier.weight(1f), ) Column( Modifier.width(130.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(5.dp), ) { Text(if (event.isLive(now)) "LIVE" else "VS", color = if (event.isLive(now)) LuxGreen else LuxGold, fontSize = 9.sp, fontWeight = FontWeight.Black, letterSpacing = 1.2.sp) if (event.status.isNotBlank()) Text(event.status, color = LuxText, fontSize = 11.sp, fontWeight = FontWeight.Bold, maxLines = 2, overflow = TextOverflow.Ellipsis) if (event.network.isNotBlank()) Text("TV • ${event.network}", color = LuxMuted, fontSize = 8.sp, maxLines = 1, overflow = TextOverflow.Ellipsis) } FeatureTeamV2( team = event.homeTeam, logo = event.homeLogo, score = if (event.isLive(now) || event.completed) event.homeScore else "", rank = event.homeRank, modifier = Modifier.weight(1f), ) } } else { Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.fillMaxWidth()) { Text(event.title, color = LuxText, fontSize = 26.sp, fontWeight = FontWeight.Black, maxLines = 2, overflow = TextOverflow.Ellipsis) if (event.network.isNotBlank()) Text("TV • ${event.network}", color = LuxMuted, fontSize = 9.sp) } } Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) { Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically) { val ranked = remember(event) { rankFeedsV2(event) } if (ranked.isNotEmpty()) { Text("${ranked.size} MATCHED ${if (ranked.size == 1) "FEED" else "FEEDS"}", color = LuxGold, fontSize = 8.sp, fontWeight = FontWeight.Black, letterSpacing = .8.sp) Text("•", color = LuxMuted, fontSize = 8.sp) Text(ranked.first().reason, color = LuxGreen, fontSize = 8.sp, fontWeight = FontWeight.Bold) } else { Text("WAITING FOR A MATCHED PROVIDER FEED", color = LuxMuted, fontSize = 8.sp, fontWeight = FontWeight.Bold) } } Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { if (event.feeds.size > 1) LuxButton("AVAILABLE FEEDS", onOpenFeeds) LuxButton( if (event.isLive(now)) "WATCH BEST FEED" else "OPEN BEST FEED", onBestFeed, primary = true, enabled = event.feeds.isNotEmpty(), ) } } } } } @Composable private fun FeatureTeamV2(team: String, logo: String, score: String, rank: Int, modifier: Modifier) { Column(modifier, horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(6.dp)) { Box( Modifier.size(92.dp).background(Color.White.copy(alpha = .05f), RoundedCornerShape(50)) .border(1.dp, LuxLine, RoundedCornerShape(50)), contentAlignment = Alignment.Center, ) { var imageFailed by remember(logo) { mutableStateOf(false) } if (logo.isNotBlank() && !imageFailed) { AsyncImage(logo, contentDescription = team, modifier = Modifier.fillMaxSize().padding(9.dp), contentScale = ContentScale.Fit, onError = { imageFailed = true }) } else { Text(teamInitialsV2(team), color = LuxGold, fontSize = 24.sp, fontWeight = FontWeight.Black) } } Text(if (rank in 1..25) "#$rank $team" else team, color = LuxText, fontSize = 14.sp, fontWeight = FontWeight.Bold, maxLines = 2, overflow = TextOverflow.Ellipsis) if (score.isNotBlank()) Text(score, color = LuxText, fontSize = 27.sp, fontWeight = FontWeight.Black) } } @Composable private fun UpNextPanelV2( events: List, now: Long, modifier: Modifier, firstFocusRequester: FocusRequester, leftFocusRequester: FocusRequester, onFocusEvent: (SportsEvent) -> Unit, onOpenEvent: (SportsEvent) -> Unit, ) { Column( modifier.clip(RoundedCornerShape(20.dp)).background(Color(0xE9111820)).border(1.dp, LuxLine, RoundedCornerShape(20.dp)).padding(13.dp), verticalArrangement = Arrangement.spacedBy(8.dp), ) { Text("UP NEXT", color = LuxText, fontSize = 13.sp, fontWeight = FontWeight.Black) Text("Next scheduled games", color = LuxMuted, fontSize = 8.sp) if (events.isEmpty()) { Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { Text("No upcoming games", color = LuxMuted, fontSize = 9.sp) } } else { events.forEachIndexed { index, event -> UpNextRowV2( event = event, now = now, modifier = Modifier.weight(1f), focusRequester = if (index == 0) firstFocusRequester else null, leftFocusRequester = leftFocusRequester, onFocused = { onFocusEvent(event) }, onClick = { onOpenEvent(event) }, ) } } } } @Composable private fun UpNextRowV2( event: SportsEvent, now: Long, modifier: Modifier, focusRequester: FocusRequester?, leftFocusRequester: FocusRequester, onFocused: () -> Unit, onClick: () -> Unit, ) { var focused by remember { mutableStateOf(false) } LaunchedEffect(focused) { if (focused) { delay(110) if (focused) onFocused() } } Row( modifier.fillMaxWidth().clip(RoundedCornerShape(11.dp)) .background(if (focused) Color(0xFF252A31) else Color.Transparent) .border(1.dp, if (focused) LuxGold else Color.Transparent, RoundedCornerShape(11.dp)) .then(if (focusRequester != null) Modifier.focusRequester(focusRequester) else Modifier) .onFocusChanged { focused = it.isFocused } .onPreviewKeyEvent { keyEvent -> if (keyEvent.type == KeyEventType.KeyDown && keyEvent.key == Key.DirectionLeft) { runCatching { leftFocusRequester.requestFocus() } true } else false } .focusable().clickable(onClick = onClick).padding(horizontal = 9.dp, vertical = 7.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp), ) { TeamMiniBadgeV2(event.awayTeam.ifBlank { event.title }, event.awayLogo) Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(1.dp)) { Text( if (event.awayTeam.isNotBlank() && event.homeTeam.isNotBlank()) "${event.awayTeam} @ ${event.homeTeam}" else event.title, color = LuxText, fontSize = 8.sp, fontWeight = FontWeight.Bold, maxLines = 2, overflow = TextOverflow.Ellipsis, ) Text(if (event.isLive(now)) "LIVE" else "${relativeDayV2(event.startEpoch)} ${formatTimeV2(event.startEpoch)}", color = if (event.isLive(now)) LuxGreen else LuxMuted, fontSize = 7.sp, fontWeight = FontWeight.Bold) } Text(if (event.network.isNotBlank()) event.network.take(8) else "${event.feeds.size}F", color = LuxGold, fontSize = 7.sp, fontWeight = FontWeight.Black, maxLines = 1) } } @Composable private fun SportsEventCardV2( event: SportsEvent, now: Long, modifier: Modifier, focusRequester: FocusRequester? = null, upFocusRequester: FocusRequester? = null, onFocused: () -> Unit, onClick: () -> Unit, ) { var focused by remember { mutableStateOf(false) } LaunchedEffect(focused) { if (focused) { delay(110) if (focused) onFocused() } } Column( modifier.scale(if (focused) 1.012f else 1f).clip(RoundedCornerShape(17.dp)) .background( if (focused) Brush.verticalGradient(listOf(Color(0xFF2B241B), Color(0xFF151A21))) else Brush.verticalGradient(listOf(Color(0xFF171D25), Color(0xFF10151B))) ) .border(1.dp, if (focused) LuxGold else if (event.isLive(now)) LuxGreen.copy(alpha = .38f) else LuxLine, RoundedCornerShape(17.dp)) .then(if (focusRequester != null) Modifier.focusRequester(focusRequester) else Modifier) .onFocusChanged { focused = it.isFocused } .onPreviewKeyEvent { keyEvent -> if (upFocusRequester != null && keyEvent.type == KeyEventType.KeyDown && keyEvent.key == Key.DirectionUp) { runCatching { upFocusRequester.requestFocus() } true } else false } .focusable().clickable(onClick = onClick).padding(17.dp), verticalArrangement = Arrangement.SpaceBetween, ) { Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) { Text("${event.league.label.uppercase()} • ${relativeDayV2(event.startEpoch)}", color = LuxGold, fontSize = 10.sp, fontWeight = FontWeight.Black, letterSpacing = .6.sp) StatusBadgeV2(event, now) } if (event.awayTeam.isNotBlank() && event.homeTeam.isNotBlank()) { Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) { CompactTeamV2(event.awayTeam, event.awayLogo, event.awayScore, event.awayRank, Modifier.weight(1f), alignEnd = false, showScore = event.isLive(now) || event.completed) Text("VS", color = LuxMuted, fontSize = 24.sp, fontWeight = FontWeight.Black, modifier = Modifier.padding(horizontal = 10.dp)) CompactTeamV2(event.homeTeam, event.homeLogo, event.homeScore, event.homeRank, Modifier.weight(1f), alignEnd = true, showScore = event.isLive(now) || event.completed) } } else { Text(event.title, color = LuxText, fontSize = 18.sp, fontWeight = FontWeight.Bold, maxLines = 2, overflow = TextOverflow.Ellipsis) } Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) { Text(event.network.ifBlank { formatTimeV2(event.startEpoch) }, color = LuxMuted, fontSize = 11.sp, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f)) Text("${event.feeds.size} ${if (event.feeds.size == 1) "feed" else "feeds"}", color = if (focused) LuxGold else LuxMuted, fontSize = 11.sp, fontWeight = FontWeight.Bold) } } } @Composable private fun CompactTeamV2( name: String, logo: String, score: String, rank: Int, modifier: Modifier, alignEnd: Boolean, showScore: Boolean, ) { // Reserve a separate vertical slot for each element so long names cannot squeeze logos. Column(modifier, horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(5.dp)) { TeamMiniBadgeV2(name, logo) if (showScore && score.isNotBlank()) { Text(score, color = LuxText, fontSize = 25.sp, fontWeight = FontWeight.Black, maxLines = 1) } else { Spacer(Modifier.height(30.dp)) } Text( if (rank in 1..25) "#$rank $name" else name, color = LuxText, fontSize = 15.sp, fontWeight = FontWeight.Bold, textAlign = androidx.compose.ui.text.style.TextAlign.Center, maxLines = 2, overflow = TextOverflow.Ellipsis, lineHeight = 18.sp, ) } } @Composable private fun TeamMiniBadgeV2(name: String, logo: String) { Box( Modifier.size(58.dp).background(Color.White.copy(alpha = .05f), RoundedCornerShape(50)).border(1.dp, LuxLine, RoundedCornerShape(50)), contentAlignment = Alignment.Center, ) { var imageFailed by remember(logo) { mutableStateOf(false) } if (logo.isNotBlank() && !imageFailed) AsyncImage(logo, contentDescription = null, modifier = Modifier.fillMaxSize().padding(5.dp), contentScale = ContentScale.Fit, onError = { imageFailed = true }) else Text(teamInitialsV2(name), color = LuxGold, fontSize = 14.sp, fontWeight = FontWeight.Black) } } @Composable private fun MatchedFeedsBarV2(event: SportsEvent?, preparing: Boolean, onOpenFeeds: () -> Unit) { val ranked = remember(event) { event?.let(::rankFeedsV2).orEmpty() } Row( Modifier.fillMaxWidth().height(80.dp).clip(RoundedCornerShape(17.dp)) .background(Brush.horizontalGradient(listOf(Color(0xFF101720), Color(0xFF12253A), Color(0xFF101720)))) .border(1.dp, LuxLine, RoundedCornerShape(17.dp)).padding(horizontal = 18.dp, vertical = 12.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(18.dp), ) { Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(3.dp)) { Text("MATCHED PROVIDER FEEDS", color = LuxText, fontSize = 13.sp, fontWeight = FontWeight.Black) Text( when { ranked.isNotEmpty() -> "Best match first • original TiviLux provider feeds remain the playback source" preparing -> "Finding provider and dedicated team feeds…" else -> "No matched feed for the featured game yet — team/league channels remain available below" }, color = LuxMuted, fontSize = 8.sp, ) } if (event != null) { Column(horizontalAlignment = Alignment.End) { Text(ranked.size.toString(), color = LuxText, fontSize = 21.sp, fontWeight = FontWeight.Black) Text("MATCHED FEEDS", color = LuxMuted, fontSize = 7.sp, fontWeight = FontWeight.Bold) } Box(Modifier.width(1.dp).height(42.dp).background(LuxLine)) Column(horizontalAlignment = Alignment.End) { Text(event.network.ifBlank { "PROVIDER" }, color = LuxText, fontSize = 12.sp, fontWeight = FontWeight.Bold, maxLines = 1, overflow = TextOverflow.Ellipsis) Text("LISTED ON", color = LuxMuted, fontSize = 7.sp, fontWeight = FontWeight.Bold) } if (ranked.isNotEmpty()) LuxButton("OPEN FEEDS", onOpenFeeds) } } } @Composable private fun SportsChannelCardV2(channel: MediaEntry, modifier: Modifier, onClick: () -> Unit) { var focused by remember { mutableStateOf(false) } Row( modifier.clip(RoundedCornerShape(15.dp)).background(if (focused) Color(0xFF242B34) else LuxPanel) .border(1.dp, if (focused) LuxGold else LuxLine, RoundedCornerShape(15.dp)) .onFocusChanged { focused = it.isFocused }.focusable().clickable(onClick = onClick).padding(10.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp), ) { Box(Modifier.size(52.dp).clip(RoundedCornerShape(11.dp)).background(Color.White.copy(alpha = .05f)), contentAlignment = Alignment.Center) { if (channel.image.isNotBlank()) AsyncImage(channel.image, contentDescription = channel.name, modifier = Modifier.fillMaxSize().padding(5.dp), contentScale = ContentScale.Fit) else Text(channel.name.take(2).uppercase(), color = LuxMuted, fontSize = 13.sp, fontWeight = FontWeight.Black) } Column(Modifier.weight(1f)) { Text(channel.name, color = LuxText, fontSize = 10.sp, fontWeight = FontWeight.Bold, maxLines = 2, overflow = TextOverflow.Ellipsis) if (channel.number > 0) Text("CH ${channel.number}", color = LuxMuted, fontSize = 8.sp) } } } @Composable private fun SectionTitleV2(title: String, subtitle: String) { Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.Bottom) { Column(verticalArrangement = Arrangement.spacedBy(2.dp)) { Text(title, color = LuxText, fontSize = 16.sp, fontWeight = FontWeight.Black) Text(subtitle, color = LuxMuted, fontSize = 8.sp) } Box(Modifier.width(54.dp).height(2.dp).background(LuxGold.copy(alpha = .55f), RoundedCornerShape(50))) } } @Composable private fun EmptySportsStateV2(scanning: Boolean) { Box( Modifier.fillMaxWidth().height(96.dp).background(LuxPanel, RoundedCornerShape(15.dp)).border(1.dp, LuxLine, RoundedCornerShape(15.dp)), contentAlignment = Alignment.Center, ) { Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(9.dp)) { if (scanning) CircularProgressIndicator(Modifier.size(16.dp), strokeWidth = 2.dp, color = LuxGold) Text(if (scanning) "Scanning the active playlist for sports feeds…" else "No sports feeds matched this category.", color = LuxMuted, fontSize = 10.sp) } } } @Composable private fun SportsReadyBannerV2() { Row( Modifier.widthIn(min = 350.dp, max = 460.dp).background(Color(0xF2141D26), RoundedCornerShape(14.dp)) .border(1.dp, LuxGreen.copy(alpha = .82f), RoundedCornerShape(14.dp)).padding(horizontal = 15.dp, vertical = 12.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(11.dp), ) { Box(Modifier.size(29.dp).background(LuxGreen.copy(alpha = .15f), RoundedCornerShape(50)), contentAlignment = Alignment.Center) { Text("✓", color = LuxGreen, fontSize = 17.sp, fontWeight = FontWeight.Black) } Column { Text("Sports Zone Ready", color = LuxText, fontSize = 12.sp, fontWeight = FontWeight.Bold) Text("Scores, schedules and matched feeds are loaded.", color = LuxMuted, fontSize = 8.sp) } } } @Composable private fun StatusBadgeV2(event: SportsEvent, now: Long) { val live = event.isLive(now) val text = when { live && event.status.isNotBlank() -> event.status.uppercase().take(18) live -> "LIVE" event.completed -> event.status.ifBlank { "FINAL" }.uppercase().take(18) event.startEpoch > now -> "UPCOMING" else -> event.status.ifBlank { "ENDED" }.uppercase().take(18) } val accent = if (live) LuxGreen else if (event.startEpoch > now) LuxGold else LuxMuted Row( Modifier.background(accent.copy(alpha = .10f), RoundedCornerShape(8.dp)).border(1.dp, accent.copy(alpha = .48f), RoundedCornerShape(8.dp)) .padding(horizontal = 8.dp, vertical = 4.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(5.dp), ) { if (live) Box(Modifier.size(5.dp).background(LuxGreen, RoundedCornerShape(50))) Text(text, color = accent, fontSize = 7.sp, fontWeight = FontWeight.Black) } } private data class RankedFeedV2( val feed: MediaEntry, val score: Int, val reason: String, val quality: String, ) /** * Display-only ranking. It NEVER manufactures a stream or replaces the existing TiviLux matcher. * Every row returned here is already present in SportsEvent.feeds from the proven engine. */ private fun rankFeedsV2(event: SportsEvent): List { return event.feeds.distinctBy { it.id }.map { feed -> val haystack = normalizeV2(feed.name) val awayTerms = teamTermsV2(event.awayTeam, event.awayAliases) val homeTerms = teamTermsV2(event.homeTeam, event.homeAliases) val awayHit = awayTerms.any { it.length >= 3 && haystack.contains(it) } val homeHit = homeTerms.any { it.length >= 3 && haystack.contains(it) } val networkTerms = normalizeV2(event.network).split(' ').filter { it.length >= 3 && it !in setOf("network", "sports", "plus") } val networkHit = networkTerms.any { haystack.contains(it) } val quality = when { Regex("(^|[^a-z0-9])4k([^a-z0-9]|$)").containsMatchIn(haystack) -> "4K" haystack.contains("fhd") || haystack.contains("1080") -> "FHD" haystack.contains(" hd") || haystack.startsWith("hd ") || haystack.contains("720") -> "HD" else -> "AUTO" } val qualityBonus = when (quality) { "4K" -> 2 "FHD" -> 2 "HD" -> 1 else -> 0 } val base = when { awayHit && homeHit -> 97 awayHit || homeHit -> 92 networkHit -> 89 else -> 84 } val reason = when { awayHit && homeHit -> "BOTH TEAMS" awayHit || homeHit -> "TEAM MATCH" networkHit -> "NETWORK MATCH" else -> "MATCHED FEED" } RankedFeedV2(feed, (base + qualityBonus).coerceAtMost(99), reason, quality) }.sortedWith(compareByDescending { it.score }.thenBy { it.feed.name.lowercase(Locale.ROOT) }) } @Composable private fun FeedPickerV2( event: SportsEvent, now: Long, onDismiss: () -> Unit, onPlay: (MediaEntry) -> Unit, ) { val ranked = remember(event) { rankFeedsV2(event) } Dialog( onDismissRequest = onDismiss, properties = DialogProperties(usePlatformDefaultWidth = false), ) { Row( Modifier.fillMaxWidth(.88f).heightIn(min = 430.dp, max = 640.dp) .background(Color(0xFF0B1118), RoundedCornerShape(22.dp)) .border(1.dp, LuxGold.copy(alpha = .55f), RoundedCornerShape(22.dp)) .padding(18.dp), horizontalArrangement = Arrangement.spacedBy(16.dp), ) { Column( Modifier.width(300.dp).fillMaxHeight().background( Brush.verticalGradient(listOf(Color(0xFF142234), Color(0xFF0D131B))), RoundedCornerShape(17.dp), ).border(1.dp, LuxLine, RoundedCornerShape(17.dp)).padding(16.dp), verticalArrangement = Arrangement.spacedBy(12.dp), horizontalAlignment = Alignment.CenterHorizontally, ) { Text("GAME DETAILS", color = LuxGold, fontSize = 8.sp, fontWeight = FontWeight.Black, letterSpacing = 1.2.sp) if (event.awayTeam.isNotBlank() && event.homeTeam.isNotBlank()) { Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceEvenly) { DialogTeamV2(event.awayTeam, event.awayLogo, if (event.isLive(now) || event.completed) event.awayScore else "") Text("VS", color = LuxMuted, fontSize = 9.sp, fontWeight = FontWeight.Black) DialogTeamV2(event.homeTeam, event.homeLogo, if (event.isLive(now) || event.completed) event.homeScore else "") } } else { Text(event.title, color = LuxText, fontSize = 18.sp, fontWeight = FontWeight.Black, maxLines = 3, overflow = TextOverflow.Ellipsis) } StatusBadgeV2(event, now) Text("${relativeDayV2(event.startEpoch)} • ${formatTimeV2(event.startEpoch)}", color = LuxText, fontSize = 10.sp, fontWeight = FontWeight.Bold) if (event.network.isNotBlank()) Text("TV • ${event.network}", color = LuxMuted, fontSize = 9.sp, maxLines = 2, overflow = TextOverflow.Ellipsis) event.venue.takeIf { it.isNotBlank() }?.let { Text(it, color = LuxMuted, fontSize = 8.sp, maxLines = 2, overflow = TextOverflow.Ellipsis) } Spacer(Modifier.weight(1f)) Text("TiviLux ranks only feeds that the existing sports engine already matched. Playback remains unchanged.", color = LuxMuted, fontSize = 8.sp, lineHeight = 12.sp) LuxButton("CLOSE", onDismiss) } Column(Modifier.weight(1f).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(10.dp)) { Text("AVAILABLE FEEDS", color = LuxGold, fontSize = 9.sp, fontWeight = FontWeight.Black, letterSpacing = 1.2.sp) Text("Best match first", color = LuxText, fontSize = 23.sp, fontWeight = FontWeight.SemiBold) Text("Choose any matched provider feed. The original stream URL and player path are untouched.", color = LuxMuted, fontSize = 9.sp) LazyColumn(Modifier.fillMaxWidth().weight(1f), verticalArrangement = Arrangement.spacedBy(8.dp)) { itemsIndexed(ranked, key = { _, item -> "rank:${item.feed.id}" }) { index, rankedFeed -> RankedFeedRowV2( ranked = rankedFeed, requestFocus = index == 0, onClick = { onPlay(rankedFeed.feed) }, ) } } } } } } @Composable private fun DialogTeamV2(team: String, logo: String, score: String) { Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(5.dp), modifier = Modifier.width(104.dp)) { Box(Modifier.size(58.dp).background(Color.White.copy(alpha = .05f), RoundedCornerShape(50)).border(1.dp, LuxLine, RoundedCornerShape(50)), contentAlignment = Alignment.Center) { var imageFailed by remember(logo) { mutableStateOf(false) } if (logo.isNotBlank() && !imageFailed) AsyncImage(logo, contentDescription = team, modifier = Modifier.fillMaxSize().padding(6.dp), contentScale = ContentScale.Fit, onError = { imageFailed = true }) else Text(teamInitialsV2(team), color = LuxGold, fontSize = 15.sp, fontWeight = FontWeight.Black) } Text(team, color = LuxText, fontSize = 9.sp, fontWeight = FontWeight.Bold, maxLines = 2, overflow = TextOverflow.Ellipsis) if (score.isNotBlank()) Text(score, color = LuxText, fontSize = 18.sp, fontWeight = FontWeight.Black) } } @Composable private fun RankedFeedRowV2(ranked: RankedFeedV2, requestFocus: Boolean, onClick: () -> Unit) { var focused by remember { mutableStateOf(false) } val focusRequester = remember { FocusRequester() } LaunchedEffect(requestFocus) { if (requestFocus) { delay(90) runCatching { focusRequester.requestFocus() } } } Row( Modifier.fillMaxWidth().height(74.dp).focusRequester(focusRequester).clip(RoundedCornerShape(13.dp)) .background(if (focused) Color(0xFF2C261C) else LuxPanel) .border(1.dp, if (focused) LuxGold else LuxLine, RoundedCornerShape(13.dp)) .onFocusChanged { focused = it.isFocused }.focusable().clickable(onClick = onClick).padding(horizontal = 12.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(11.dp), ) { Box( Modifier.width(52.dp).height(34.dp).background(Color(0xFF07100B), RoundedCornerShape(8.dp)).border(1.dp, LuxGreen.copy(alpha = .35f), RoundedCornerShape(8.dp)), contentAlignment = Alignment.Center, ) { Text("${ranked.score}%", color = LuxGreen, fontSize = 10.sp, fontWeight = FontWeight.Black) } Box(Modifier.size(40.dp).background(Color.White.copy(alpha = .05f), RoundedCornerShape(9.dp)), contentAlignment = Alignment.Center) { if (ranked.feed.image.isNotBlank()) AsyncImage(ranked.feed.image, contentDescription = ranked.feed.name, modifier = Modifier.fillMaxSize().padding(5.dp), contentScale = ContentScale.Fit) else Text(ranked.feed.name.take(2).uppercase(), color = LuxMuted, fontSize = 9.sp, fontWeight = FontWeight.Black) } Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(3.dp)) { Text(ranked.feed.name, color = LuxText, fontSize = 11.sp, fontWeight = FontWeight.Bold, maxLines = 1, overflow = TextOverflow.Ellipsis) Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) { MiniTagV2(ranked.reason, LuxGold) MiniTagV2(ranked.quality, LuxMuted) } } Text("PLAY ▶", color = if (focused) LuxGold else LuxMuted, fontSize = 8.sp, fontWeight = FontWeight.Black) } } @Composable private fun MiniTagV2(text: String, accent: Color) { Text( text, color = accent, fontSize = 7.sp, fontWeight = FontWeight.Bold, modifier = Modifier.background(accent.copy(alpha = .08f), RoundedCornerShape(6.dp)) .border(1.dp, accent.copy(alpha = .24f), RoundedCornerShape(6.dp)).padding(horizontal = 6.dp, vertical = 3.dp), ) } private fun normalizeV2(raw: String): String = raw.lowercase(Locale.ROOT) .replace(Regex("[^a-z0-9]+"), " ") .replace(Regex("\\s+"), " ") .trim() private fun teamTermsV2(team: String, aliases: List): Set { val values = (listOf(team) + aliases).map(::normalizeV2).filter { it.isNotBlank() } val out = linkedSetOf() values.forEach { value -> out += value val words = value.split(' ').filter { it.length >= 3 } words.lastOrNull()?.let { out += it } if (words.size > 1) out += words.takeLast(2).joinToString(" ") } return out } private fun teamInitialsV2(name: String): String { val ignore = setOf("the", "fc", "cf") val words = name.split(Regex("[^A-Za-z0-9]+")) .filter { it.isNotBlank() && it.lowercase(Locale.ROOT) !in ignore } if (words.isEmpty()) return "TV" return words.takeLast(2).joinToString("") { it.take(1).uppercase(Locale.ROOT) }.take(3) } private fun relativeDayV2(epoch: Long): String = runCatching { val target = Calendar.getInstance().apply { timeInMillis = epoch * 1000L } val today = Calendar.getInstance() fun dayKey(c: Calendar) = c.get(Calendar.YEAR) * 1000 + c.get(Calendar.DAY_OF_YEAR) when (dayKey(target) - dayKey(today)) { 0 -> "TODAY" 1 -> "TOMORROW" else -> SimpleDateFormat("EEE M/d", Locale.getDefault()).format(target.time).uppercase(Locale.ROOT) } }.getOrDefault("") private fun formatTimeV2(epoch: Long): String = runCatching { SimpleDateFormat("h:mm a", Locale.getDefault()).format(Date(epoch * 1000L)) }.getOrDefault("") private fun collegeRankTierV2(event: SportsEvent): Int { val away = event.awayRank in 1..25 val home = event.homeRank in 1..25 return when { away && home -> 0 away || home -> 1 else -> 2 } } private fun bestCollegeRankV2(event: SportsEvent): Int = listOf(event.awayRank, event.homeRank) .filter { it in 1..25 }.minOrNull() ?: 99 private fun easternHourV2(epoch: Long): Int = Calendar.getInstance(TimeZone.getTimeZone("America/New_York")).run { timeInMillis = epoch * 1000L get(Calendar.HOUR_OF_DAY) } private fun sportsPriorityV2(): SportLeague? = when ( Calendar.getInstance(TimeZone.getTimeZone("America/New_York")).get(Calendar.DAY_OF_WEEK) ) { Calendar.SATURDAY -> SportLeague.COLLEGE_FOOTBALL Calendar.SUNDAY -> SportLeague.NFL else -> null }