|
|
|
@@ -61,6 +61,18 @@ internal fun guideDayPrefix(timeMs: Long, nowMs: Long): String {
|
|
|
|
|
internal fun guideDayJump(cursorMs: Long, nowMs: Long, forward: Boolean): Long =
|
|
|
|
|
(maxOf(cursorMs, nowMs) + if (forward) 24 * 60 * 60_000L else -24 * 60 * 60_000L).coerceIn(nowMs, nowMs + GUIDE_MAX_SLOTS_AHEAD * GUIDE_SLOT_MS - 1)
|
|
|
|
|
|
|
|
|
|
internal enum class GuideCellTime { Past, Now, Later }
|
|
|
|
|
|
|
|
|
|
/** Only the programme actually on air is lit, so neighbouring programmes can't read as one. */
|
|
|
|
|
internal fun guideCellTime(startMs: Long, endMs: Long, nowMs: Long) = when {
|
|
|
|
|
endMs <= nowMs -> GuideCellTime.Past
|
|
|
|
|
startMs <= nowMs -> GuideCellTime.Now
|
|
|
|
|
else -> GuideCellTime.Later
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private val GuideChannelColumn = Color(0xFF0A1B3C)
|
|
|
|
|
private val GuidePast = Color(0xFF0D2247)
|
|
|
|
|
|
|
|
|
|
/** The first row to draw, moving only as far as it takes to keep the chosen row on screen. */
|
|
|
|
|
internal fun guideFirstRow(row: Int, first: Int, visible: Int, count: Int): Int {
|
|
|
|
|
val last = (count - visible).coerceAtLeast(0)
|
|
|
|
@@ -90,7 +102,6 @@ internal fun GuideGrid(channels: List<SampleChannel>, selectedNumber: Int, modif
|
|
|
|
|
var slotsAhead by remember { mutableIntStateOf(0) }
|
|
|
|
|
var firstRow by remember { mutableIntStateOf(0) }
|
|
|
|
|
val gridFocus = remember { FocusRequester() }
|
|
|
|
|
val toolsFocus = remember { FocusRequester() }
|
|
|
|
|
var gridFocused by remember { mutableStateOf(true) }
|
|
|
|
|
LaunchedEffect(Unit) { gridFocus.requestFocus() }
|
|
|
|
|
BackHandler(onBack = onBack)
|
|
|
|
@@ -107,41 +118,36 @@ internal fun GuideGrid(channels: List<SampleChannel>, selectedNumber: Int, modif
|
|
|
|
|
slotsAhead = ahead
|
|
|
|
|
}
|
|
|
|
|
Column(modifier.fillMaxWidth().background(Navy).padding(horizontal = 14.dp, vertical = 8.dp), verticalArrangement = Arrangement.spacedBy(5.dp)) {
|
|
|
|
|
Row(Modifier.fillMaxWidth().height(96.dp), horizontalArrangement = Arrangement.spacedBy(12.dp)) {
|
|
|
|
|
Row(Modifier.fillMaxWidth().height(135.dp), horizontalArrangement = Arrangement.spacedBy(14.dp)) {
|
|
|
|
|
val branding = ChannelBrands.forNumber(channel.number)
|
|
|
|
|
// The picture stays on the tuned channel while the cursor browses, so moving rows never re-tunes.
|
|
|
|
|
Box(Modifier.width(170.dp).fillMaxHeight().background(Panel)) {
|
|
|
|
|
Box(Modifier.width(240.dp).fillMaxHeight().background(Panel)) {
|
|
|
|
|
picture()
|
|
|
|
|
}
|
|
|
|
|
// Four lines fill the panel's height. OK Watch is already in the legend below.
|
|
|
|
|
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
|
|
|
|
if (branding != null) Image(painterResource(branding.logo), branding.displayName, Modifier.width(90.dp).height(28.dp))
|
|
|
|
|
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
|
|
|
|
if (branding != null) Image(painterResource(branding.logo), branding.displayName, Modifier.width(115.dp).height(36.dp))
|
|
|
|
|
else Text(ChannelBrands.displayName(channel), color = Color.White, fontSize = 16.sp)
|
|
|
|
|
val (focusedName, focusedDetail) = guideTitleParts(focused.media.item.title)
|
|
|
|
|
Text(focusedName, color = Color.White, fontSize = 17.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
|
|
|
|
if (focusedDetail != null) Text(focusedDetail, color = Color.White, fontSize = 13.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
|
|
|
|
Text("${guideDayPrefix(focused.startMs, now)}${clock(focused.startMs)} to ${clock(focused.endMs)} • ${channel.number} ${ChannelBrands.displayName(channel)}", color = Muted, fontSize = 12.sp, maxLines = 1)
|
|
|
|
|
}
|
|
|
|
|
Column(verticalArrangement = Arrangement.Top) {
|
|
|
|
|
OrbitButton("Test transition", Modifier.focusRequester(toolsFocus).onPreviewKeyEvent { event ->
|
|
|
|
|
if (event.nativeKeyEvent.keyCode == KeyEvent.KEYCODE_DPAD_DOWN && event.nativeKeyEvent.action == KeyEvent.ACTION_DOWN) { gridFocus.requestFocus(); true } else false
|
|
|
|
|
}, onClick = { onWatch(channel.number, channel.transitionCheckOffset(System.currentTimeMillis())) })
|
|
|
|
|
Text(focusedName, color = Color.White, fontSize = 21.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
|
|
|
|
if (focusedDetail != null) Text(focusedDetail, color = Color.White, fontSize = 15.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
|
|
|
|
Text("${guideDayPrefix(focused.startMs, now)}${clock(focused.startMs)} to ${clock(focused.endMs)} • ${channel.number} ${ChannelBrands.displayName(channel)}", color = Muted, fontSize = 13.sp, maxLines = 1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Row(Modifier.fillMaxWidth().height(20.dp).background(Panel), verticalAlignment = Alignment.CenterVertically) {
|
|
|
|
|
Text(guideDayPrefix(windowStart, now).trim().ifEmpty { title }, Modifier.width(130.dp).padding(start = 8.dp), color = Color.White, fontSize = 12.sp, fontWeight = FontWeight.SemiBold)
|
|
|
|
|
Text(guideDayPrefix(windowStart, now).trim().ifEmpty { title }, Modifier.width(136.dp).padding(start = 8.dp), color = Color.White, fontSize = 12.sp, fontWeight = FontWeight.SemiBold)
|
|
|
|
|
Row(Modifier.weight(1f)) {
|
|
|
|
|
repeat(GUIDE_SLOTS) { Text(clock(windowStart + it * GUIDE_SLOT_MS), Modifier.weight(1f).padding(start = 4.dp), color = Color.White, fontSize = 12.sp, fontWeight = FontWeight.SemiBold) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BoxWithConstraints(Modifier.fillMaxWidth().weight(1f)) {
|
|
|
|
|
val visibleRows = ((maxHeight + 3.dp) / 43.dp).toInt().coerceAtLeast(1)
|
|
|
|
|
val visibleRows = ((maxHeight + 3.dp) / 41.dp).toInt().coerceAtLeast(1)
|
|
|
|
|
firstRow = guideFirstRow(row, firstRow, visibleRows, channels.size)
|
|
|
|
|
Column(Modifier.fillMaxWidth().focusRequester(gridFocus).onFocusChanged { gridFocused = it.isFocused }.focusable().onPreviewKeyEvent { event ->
|
|
|
|
|
val native = event.nativeKeyEvent
|
|
|
|
|
if (native.action != KeyEvent.ACTION_DOWN) return@onPreviewKeyEvent false
|
|
|
|
|
when (native.keyCode) {
|
|
|
|
|
KeyEvent.KEYCODE_DPAD_UP -> { if (row > 0) row-- else toolsFocus.requestFocus(); true }
|
|
|
|
|
// At the top row, up leaves the grid for the gear.
|
|
|
|
|
KeyEvent.KEYCODE_DPAD_UP -> if (row > 0) { row--; true } else false
|
|
|
|
|
KeyEvent.KEYCODE_DPAD_DOWN -> { if (row < channels.lastIndex) row++; true }
|
|
|
|
|
KeyEvent.KEYCODE_DPAD_RIGHT, KeyEvent.KEYCODE_DPAD_LEFT -> {
|
|
|
|
|
val forward = native.keyCode == KeyEvent.KEYCODE_DPAD_RIGHT
|
|
|
|
@@ -160,9 +166,9 @@ internal fun GuideGrid(channels: List<SampleChannel>, selectedNumber: Int, modif
|
|
|
|
|
}, verticalArrangement = Arrangement.spacedBy(3.dp)) {
|
|
|
|
|
channels.subList(firstRow, minOf(firstRow + visibleRows, channels.size)).forEachIndexed { offset, line ->
|
|
|
|
|
val index = firstRow + offset
|
|
|
|
|
Row(Modifier.fillMaxWidth().height(40.dp), horizontalArrangement = Arrangement.spacedBy(0.dp)) {
|
|
|
|
|
Row(Modifier.fillMaxWidth().height(38.dp), horizontalArrangement = Arrangement.spacedBy(6.dp)) {
|
|
|
|
|
val mark = ChannelBrands.forNumber(line.number)
|
|
|
|
|
Row(Modifier.width(130.dp).fillMaxHeight().background(Panel).padding(start = 6.dp), verticalAlignment = Alignment.CenterVertically) {
|
|
|
|
|
Row(Modifier.width(130.dp).fillMaxHeight().background(if (index == row) Blue else GuideChannelColumn).padding(start = 6.dp), verticalAlignment = Alignment.CenterVertically) {
|
|
|
|
|
Text(line.number.toString(), Modifier.width(30.dp), color = Muted, fontSize = 12.sp, fontWeight = FontWeight.SemiBold)
|
|
|
|
|
if (mark != null) Image(painterResource(mark.logo), mark.displayName, Modifier.width(88.dp).height(28.dp))
|
|
|
|
|
else Text(ChannelBrands.displayName(line), color = Color.White, fontSize = 13.sp, maxLines = 1)
|
|
|
|
@@ -170,17 +176,17 @@ internal fun GuideGrid(channels: List<SampleChannel>, selectedNumber: Int, modif
|
|
|
|
|
BoxWithConstraints(Modifier.weight(1f).fillMaxHeight()) {
|
|
|
|
|
guideCells(line, windowStart, windowEnd).forEach { cell ->
|
|
|
|
|
val isFocus = gridFocused && index == row && cell.show.startMs == focused.startMs
|
|
|
|
|
val onNow = cell.show.startMs <= now
|
|
|
|
|
Box(Modifier.offset(x = maxWidth * cell.startFraction).width((maxWidth * cell.widthFraction - 2.dp).coerceAtLeast(1.dp)).fillMaxHeight()
|
|
|
|
|
.background(if (isFocus) Yellow else if (onNow) Blue else Panel).padding(horizontal = 6.dp), contentAlignment = Alignment.CenterStart) {
|
|
|
|
|
val time = guideCellTime(cell.show.startMs, cell.show.endMs, now)
|
|
|
|
|
Box(Modifier.offset(x = maxWidth * cell.startFraction).width((maxWidth * cell.widthFraction - 3.dp).coerceAtLeast(1.dp)).fillMaxHeight()
|
|
|
|
|
.background(if (isFocus) Yellow else when (time) { GuideCellTime.Past -> GuidePast; GuideCellTime.Now -> Blue; GuideCellTime.Later -> Panel }).padding(horizontal = 6.dp), contentAlignment = Alignment.CenterStart) {
|
|
|
|
|
// Too narrow for a readable word, so the panel above carries the name.
|
|
|
|
|
if (cell.widthFraction >= .09f) {
|
|
|
|
|
Text(guideTitleParts(cell.show.media.item.title).first, color = if (isFocus) Navy else Color.White, fontSize = 13.sp, fontWeight = if (isFocus) FontWeight.SemiBold else FontWeight.Normal, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
|
|
|
|
Text(guideTitleParts(cell.show.media.item.title).first, color = if (isFocus) Navy else if (time == GuideCellTime.Past) Muted else Color.White, fontSize = 13.sp, fontWeight = if (isFocus || time == GuideCellTime.Now) FontWeight.SemiBold else FontWeight.Normal, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
guideNowFraction(now, windowStart, windowEnd)?.let { fraction ->
|
|
|
|
|
Box(Modifier.offset(x = maxWidth * fraction).width(2.dp).fillMaxHeight().background(Color.White.copy(alpha = .6f)))
|
|
|
|
|
Box(Modifier.offset(x = maxWidth * fraction).width(1.dp).fillMaxHeight().background(Color.White.copy(alpha = .4f)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|