Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions app/src/main/java/tv/own/owntv/features/epg/EpgScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,21 @@ private fun cursorStep(progs: List<EpgProgrammeEntity>, cursor: Long, dir: Int,
return target.coerceIn(windowStart, windowEnd - 1)
}

/**
* Decides whether an OK press on a channel in the Guide / Live list should send D-pad focus to the
* mini-player instead of re-tuning the channel.
*
* When the mini-player is active and playing [channelId], a second OK press on that same channel
* (or pressing OK while focused on the channel currently playing in the mini-player) transfers
* D-pad focus to the mini-player controls so the user can easily expand or close it.
*/
internal fun shouldFocusMiniPlayerOnOk(
isMiniPlayer: Boolean,
onFocusMiniPlayer: (() -> Unit)?,
channelId: Long,
playingChannelId: Long?,
): Boolean = isMiniPlayer && onFocusMiniPlayer != null && playingChannelId != null && channelId == playingChannelId

/**
* The TV Guide in the Stage design: the focused channel's preview and the focused programme
* with its actions on top; one control line (Today · Now · Category · Order · Search · Auto-match EPG);
Expand Down Expand Up @@ -198,10 +213,12 @@ fun EpgScreen(
onPlayCatchup: (channel: ChannelEntity, programme: EpgProgrammeEntity) -> Unit,
/** False while the full-screen or mini player owns the video surface. */
previewEnabled: Boolean = true,
isMiniPlayer: Boolean = false,
liveMode: Boolean = false,
onListView: () -> Unit = {},
/** How ▶ from the rail enters the guide: at the grid row focus was on (the rail's entry hook, as Home's). */
onEntryHook: (((() -> Boolean)?) -> Unit)? = null,
onFocusMiniPlayer: (() -> Unit)? = null,
) {
val vm: EpgViewModel = koinViewModel()
// Live TV's view model: its preview player (no second decoder), its category list and playlist marks.
Expand Down Expand Up @@ -422,9 +439,14 @@ fun EpgScreen(
}
}
// OK on a programme: watch — the archive for one that has been on and can be replayed, else the channel.
// If the mini-player is active and playing this channel, a second OK transfers focus to the mini-player.
val onOk: (ChannelEntity, EpgProgrammeEntity?) -> Unit = { ch, p ->
val now = System.currentTimeMillis()
if (p != null && p.stopMs <= now && vm.canCatchup(ch, p, now)) playFromStart(ch, p) else watch(ch)
if (shouldFocusMiniPlayerOnOk(isMiniPlayer, onFocusMiniPlayer, ch.id, liveVm.playingChannel?.id)) {
onFocusMiniPlayer?.invoke()
} else {
val now = System.currentTimeMillis()
if (p != null && p.stopMs <= now && vm.canCatchup(ch, p, now)) playFromStart(ch, p) else watch(ch)
}
}

/** What [p] on [ch] can do right now — the programme menu, Record ▾ and the buttons on top share it. */
Expand Down
17 changes: 12 additions & 5 deletions app/src/main/java/tv/own/owntv/features/live/LiveScreen.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tv.own.owntv.features.live

import tv.own.owntv.features.epg.shouldFocusMiniPlayerOnOk
import tv.own.owntv.ui.components.onDpadLeft
import tv.own.owntv.core.epg.displayLogoUrl
import androidx.activity.compose.BackHandler
Expand Down Expand Up @@ -97,6 +98,7 @@ fun LiveScreen(
onFullscreen: () -> Unit,
onChildFocused: () -> Unit,
previewEnabled: Boolean = true,
isMiniPlayer: Boolean = false,
restoreFocus: Boolean = false,
onRestored: () -> Unit = {},
modifier: Modifier = Modifier,
Expand All @@ -107,6 +109,7 @@ fun LiveScreen(
lockedKey: LiveKey? = null,
/** Guide view (Live TV tool row): opens the TV Guide until an in-place guide exists. */
onOpenGuide: () -> Unit = {},
onFocusMiniPlayer: (() -> Unit)? = null,
) {
val vm: LiveViewModel = koinViewModel()
val lockVm: tv.own.owntv.features.categorylock.CategoryLockViewModel = koinViewModel()
Expand Down Expand Up @@ -848,11 +851,15 @@ fun LiveScreen(
if (rememberLive) perCategoryChannelIds[selectedKey] = channel.id
},
onClick = {
when (okAction(previewOnOk, effectivePreview && previewShown, paneChannel?.id, channel.id)) {
OkAction.PREVIEW -> vm.playPreview(channel)
OkAction.WATCH -> {
vm.watchFullscreen(channel, channels.itemSnapshotList.items.filterNotNull())
if (!externalPlayerOn) onFullscreen()
if (shouldFocusMiniPlayerOnOk(isMiniPlayer, onFocusMiniPlayer, channel.id, vm.playingChannel?.id)) {
onFocusMiniPlayer?.invoke()
} else {
when (okAction(previewOnOk, effectivePreview && previewShown, paneChannel?.id, channel.id)) {
OkAction.PREVIEW -> vm.playPreview(channel)
OkAction.WATCH -> {
vm.watchFullscreen(channel, channels.itemSnapshotList.items.filterNotNull())
if (!externalPlayerOn) onFullscreen()
}
}
}
},
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/java/tv/own/owntv/features/shell/OwnTVShell.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1366,11 +1366,13 @@ fun OwnTVShell(
onPlayCatchup = guidePlayCatchup,
onAddEpg = { openEpgAdd = true; onSelectSection(MainSection.SETTINGS) },
previewEnabled = playerMode == PlayerMode.NONE,
isMiniPlayer = playerMode == PlayerMode.MINI,
liveMode = true,
onEntryHook = { guideEntry = it },
onListView = { liveVm.setLiveView(tv.own.owntv.core.settings.SettingsRepository.LiveView.LIST) },
restoreFocus = restoreFocus,
onRestored = { restoreFocus = false },
onFocusMiniPlayer = { if (playerMode == PlayerMode.MINI) runCatching { miniEntryFocus.requestFocus() } },
modifier = Modifier
.fillMaxSize()
.onFocusChanged { if (it.hasFocus) focusedLayer = ShellLayer.CONTENT }
Expand All @@ -1382,8 +1384,10 @@ fun OwnTVShell(
onOpenGuide = { liveVm.setLiveView(tv.own.owntv.core.settings.SettingsRepository.LiveView.GUIDE) },
onChildFocused = { focusedLayer = ShellLayer.CONTENT },
previewEnabled = playerMode == PlayerMode.NONE,
isMiniPlayer = playerMode == PlayerMode.MINI,
restoreFocus = restoreFocus,
onRestored = { restoreFocus = false },
onFocusMiniPlayer = { if (playerMode == PlayerMode.MINI) runCatching { miniEntryFocus.requestFocus() } },
modifier = Modifier.fillMaxSize(),
)

Expand Down Expand Up @@ -1431,10 +1435,12 @@ fun OwnTVShell(
onPlayChannel = guidePlayChannel,
onPlayCatchup = guidePlayCatchup,
previewEnabled = playerMode == PlayerMode.NONE,
isMiniPlayer = playerMode == PlayerMode.MINI,
onEntryHook = { guideEntry = it },
onAddEpg = { openEpgAdd = true; onSelectSection(MainSection.SETTINGS) },
restoreFocus = restoreFocus,
onRestored = { restoreFocus = false },
onFocusMiniPlayer = { if (playerMode == PlayerMode.MINI) runCatching { miniEntryFocus.requestFocus() } },
modifier = Modifier
.fillMaxSize()
.onFocusChanged { if (it.hasFocus) focusedLayer = ShellLayer.CONTENT }
Expand Down Expand Up @@ -2007,7 +2013,12 @@ fun OwnTVShell(
onCyclePosition = { scope.launch { settingsRepo.setMiniPlayerPosition(miniPos.next().name) } },
onAudioMode = toAudioMode,
entryFocusRequester = miniEntryFocus,
onBack = { runCatching { shellContentFocus.requestFocus() } },
onBack = {
val restored = guideEntry?.invoke() == true
if (!restored) {
runCatching { contentAreaFocus.requestFocus() }
}
},
modifier = Modifier.fillMaxSize().onFocusChanged { miniHasFocus = it.hasFocus },
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package tv.own.owntv.features.epg

import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

class MiniPlayerOkFocusTest {

@Test
fun `focuses mini player when mini player active and playing channel matches focused channel`() {
var focused = false
val onFocus = { focused = true }

val result = shouldFocusMiniPlayerOnOk(
isMiniPlayer = true,
onFocusMiniPlayer = onFocus,
channelId = 101L,
playingChannelId = 101L,
)

assertTrue(result)
onFocus()
assertTrue(focused)
}

@Test
fun `does not focus mini player when mini player is not active`() {
val result = shouldFocusMiniPlayerOnOk(
isMiniPlayer = false,
onFocusMiniPlayer = {},
channelId = 101L,
playingChannelId = 101L,
)

assertFalse(result)
}

@Test
fun `does not focus mini player when playing channel is different`() {
val result = shouldFocusMiniPlayerOnOk(
isMiniPlayer = true,
onFocusMiniPlayer = {},
channelId = 102L,
playingChannelId = 101L,
)

assertFalse(result)
}

@Test
fun `does not focus mini player when handler is null`() {
val result = shouldFocusMiniPlayerOnOk(
isMiniPlayer = true,
onFocusMiniPlayer = null,
channelId = 101L,
playingChannelId = 101L,
)

assertFalse(result)
}

@Test
fun `does not focus mini player when playing channel id is null`() {
val result = shouldFocusMiniPlayerOnOk(
isMiniPlayer = true,
onFocusMiniPlayer = {},
channelId = 101L,
playingChannelId = null,
)

assertFalse(result)
}
}