Skip to content

StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.

refactor(live): extract epg options overlay

David Nashash218d6b4ab5b3
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgScreen.kt b/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgScreen.kt
index 147d6fbb..8f0e0bdb 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgScreen.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgScreen.kt
@@ -25,6 +25,9 @@ import com.streamvault.feature.live.presentation.epg.LiveGuidePreviewPane
import com.streamvault.feature.live.presentation.epg.LiveGuideToolbarLabels
import com.streamvault.feature.live.presentation.epg.LiveGuideToolbarRow
import com.streamvault.feature.live.presentation.epg.LiveGuideMessageState
+import com.streamvault.feature.live.presentation.epg.LiveGuideOptionsLabels
+import com.streamvault.feature.live.presentation.epg.LiveGuideOptionsOverlay
+import com.streamvault.feature.live.presentation.epg.liveGuideOptionsDayStart
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
@@ -615,9 +618,13 @@ fun FullEpgScreen(
}
if (showGuideOptions) {
- GuideOptionsOverlay(
- uiState = uiState,
- labels = LiveGuideControlLabels(
+ LiveGuideOptionsOverlay(
+ selectedDayStart = liveGuideOptionsDayStart(uiState.guideWindowStart, EpgViewModel.LOOKBACK_MS),
+ selectedMode = uiState.selectedChannelMode,
+ selectedDensity = uiState.selectedDensity,
+ showScheduledOnly = uiState.showScheduledOnly,
+ showFavoritesOnly = uiState.showFavoritesOnly,
+ controlLabels = LiveGuideControlLabels(
time = LiveGuideTimeControlLabels(
section = stringResource(R.string.epg_time_controls),
previousDay = stringResource(R.string.epg_previous_day),
@@ -673,6 +680,13 @@ fun FullEpgScreen(
favoritesHint = stringResource(R.string.epg_favorites_filter_favorites_hint)
)
),
+ labels = LiveGuideOptionsLabels(
+ title = stringResource(R.string.epg_options_short),
+ showAppNavigation = stringResource(R.string.epg_show_app_navigation),
+ cancel = stringResource(R.string.settings_cancel),
+ manageEpgMatch = stringResource(R.string.epg_override_manage),
+ refreshGuide = stringResource(R.string.epg_refresh_guide)
+ ),
onDismiss = { showGuideOptions = false },
onShowAppNavigation = {
topNavVisible = true
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgScreenDialogs.kt b/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgScreenDialogs.kt
index 6bde67bb..21df309f 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgScreenDialogs.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgScreenDialogs.kt
@@ -1,8 +1,6 @@
package com.streamvault.app.ui.screens.epg
-import com.streamvault.feature.live.presentation.epg.LiveGuideProgramSearchRow
import com.streamvault.feature.live.presentation.epg.LiveGuideSearchField
-import com.streamvault.feature.live.presentation.epg.LiveGuideShortcutChip
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
@@ -11,9 +9,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
-import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
@@ -22,12 +18,8 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
-import androidx.compose.foundation.lazy.itemsIndexed
-import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
-import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.LinearProgressIndicator
-import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
@@ -51,16 +43,6 @@ import androidx.tv.material3.Surface
import androidx.tv.material3.SurfaceDefaults
import androidx.tv.material3.Text
import com.streamvault.app.R
-import com.streamvault.feature.live.presentation.epg.GuideChannelMode
-import com.streamvault.feature.live.presentation.epg.GuideDensity
-import com.streamvault.feature.live.presentation.epg.LiveGuideControlLabels
-import com.streamvault.feature.live.presentation.epg.LiveGuideDensityRow
-import com.streamvault.feature.live.presentation.epg.LiveGuideDayRow
-import com.streamvault.feature.live.presentation.epg.LiveGuideFavoritesRow
-import com.streamvault.feature.live.presentation.epg.LiveGuideModeRow
-import com.streamvault.feature.live.presentation.epg.LiveGuideTimeControlsRow
-import com.streamvault.feature.live.presentation.epg.LiveGuideViewOptionsRow
-import com.streamvault.feature.live.presentation.epg.startOfGuideDay
import com.streamvault.core.ui.interaction.TvClickableSurface
import com.streamvault.core.ui.interaction.TvButton
import com.streamvault.core.ui.theme.FocusBorder
@@ -106,136 +88,6 @@ private fun GuideModalDialog(
}
}
-@Composable
-internal fun GuideOptionsOverlay(
- uiState: EpgUiState,
- labels: LiveGuideControlLabels,
- onDismiss: () -> Unit,
- onShowAppNavigation: () -> Unit,
- onJumpToPreviousDay: () -> Unit,
- onPageBackward: () -> Unit,
- onJumpBackwardHalfHour: () -> Unit,
- onJumpBackward: () -> Unit,
- onJumpToNow: () -> Unit,
- onJumpForwardHalfHour: () -> Unit,
- onJumpForward: () -> Unit,
- onPageForward: () -> Unit,
- onJumpToPrimeTime: () -> Unit,
- onJumpToTomorrow: () -> Unit,
- onJumpToNextDay: () -> Unit,
- onDaySelected: (Long) -> Unit,
- onModeSelected: (GuideChannelMode) -> Unit,
- onDensitySelected: (GuideDensity) -> Unit,
- onToggleScheduledOnly: () -> Unit,
- onToggleFavoritesOnly: () -> Unit,
- onRefresh: () -> Unit,
- onManageEpgMatch: (() -> Unit)? = null
-) {
- val optionsFocusRequester = remember { FocusRequester() }
- LaunchedEffect(Unit) {
- optionsFocusRequester.requestFocus()
- }
- GuideModalDialog(onDismiss = onDismiss) {
- Surface(
- modifier = Modifier
- .fillMaxWidth(0.68f)
- .fillMaxHeight(0.78f)
- .focusGroup(),
- colors = SurfaceDefaults.colors(containerColor = SurfaceElevated),
- shape = RoundedCornerShape(20.dp)
- ) {
- Column(
- modifier = Modifier
- .fillMaxSize()
- .verticalScroll(rememberScrollState())
- .padding(vertical = 18.dp),
- verticalArrangement = Arrangement.spacedBy(12.dp)
- ) {
- Row(
- modifier = Modifier
- .fillMaxWidth()
- .padding(horizontal = 18.dp),
- horizontalArrangement = Arrangement.SpaceBetween,
- verticalAlignment = Alignment.CenterVertically
- ) {
- Text(
- text = stringResource(R.string.epg_options_short),
- style = MaterialTheme.typography.headlineSmall,
- color = OnSurface
- )
- Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
- LiveGuideShortcutChip(
- label = stringResource(R.string.epg_show_app_navigation),
- onClick = onShowAppNavigation
- )
- LiveGuideShortcutChip(
- label = stringResource(R.string.settings_cancel),
- onClick = onDismiss
- )
- }
- }
- LiveGuideTimeControlsRow(
- labels = labels.time,
- onJumpToPreviousDay = onJumpToPreviousDay,
- onPageBackward = onPageBackward,
- onJumpBackwardHalfHour = onJumpBackwardHalfHour,
- onJumpBackward = onJumpBackward,
- onJumpToNow = onJumpToNow,
- onJumpForwardHalfHour = onJumpForwardHalfHour,
- onJumpForward = onJumpForward,
- onPageForward = onPageForward,
- onJumpToPrimeTime = onJumpToPrimeTime,
- onJumpToTomorrow = onJumpToTomorrow,
- onJumpToNextDay = onJumpToNextDay,
- firstChipFocusRequester = optionsFocusRequester
- )
- LiveGuideDayRow(
- selectedDayStart = startOfGuideDay(uiState.guideWindowStart + EpgViewModel.LOOKBACK_MS),
- labels = labels.day,
- onDaySelected = onDaySelected
- )
- LiveGuideModeRow(
- selectedMode = uiState.selectedChannelMode,
- labels = labels.mode,
- onModeSelected = onModeSelected
- )
- LiveGuideDensityRow(
- selectedDensity = uiState.selectedDensity,
- labels = labels.density,
- onDensitySelected = onDensitySelected
- )
- LiveGuideViewOptionsRow(
- showScheduledOnly = uiState.showScheduledOnly,
- labels = labels.viewOptions,
- onToggleScheduledOnly = onToggleScheduledOnly
- )
- LiveGuideFavoritesRow(
- showFavoritesOnly = uiState.showFavoritesOnly,
- labels = labels.favorites,
- onToggleFavoritesOnly = onToggleFavoritesOnly
- )
- Row(
- modifier = Modifier
- .fillMaxWidth()
- .padding(horizontal = 24.dp),
- horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End)
- ) {
- if (onManageEpgMatch != null) {
- LiveGuideShortcutChip(
- label = stringResource(R.string.epg_override_manage),
- onClick = onManageEpgMatch
- )
- }
- LiveGuideShortcutChip(
- label = stringResource(R.string.epg_refresh_guide),
- onClick = onRefresh
- )
- }
- }
- }
- }
-}
-
@Composable
internal fun EpgOverrideDialog(
state: EpgOverrideUiState,
diff --git a/feature/live/src/main/java/com/streamvault/feature/live/presentation/epg/LiveGuideOptionsOverlay.kt b/feature/live/src/main/java/com/streamvault/feature/live/presentation/epg/LiveGuideOptionsOverlay.kt
new file mode 100644
index 00000000..1d11d8b5
--- /dev/null
+++ b/feature/live/src/main/java/com/streamvault/feature/live/presentation/epg/LiveGuideOptionsOverlay.kt
@@ -0,0 +1,213 @@
+package com.streamvault.feature.live.presentation.epg
+
+import androidx.compose.foundation.background
+import androidx.compose.foundation.clickable
+import androidx.compose.foundation.focusGroup
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.BoxScope
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.fillMaxHeight
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.remember
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.focus.FocusRequester
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.window.Dialog
+import androidx.compose.ui.window.DialogProperties
+import androidx.tv.material3.MaterialTheme
+import androidx.tv.material3.Surface
+import androidx.tv.material3.SurfaceDefaults
+import androidx.tv.material3.Text
+
+data class LiveGuideOptionsLabels(
+ val title: String,
+ val showAppNavigation: String,
+ val cancel: String,
+ val manageEpgMatch: String,
+ val refreshGuide: String
+)
+
+fun liveGuideOptionsDayStart(
+ guideWindowStart: Long,
+ lookbackMs: Long,
+ zoneId: java.time.ZoneId = java.time.ZoneId.systemDefault()
+): Long = startOfGuideDay(guideWindowStart + lookbackMs, zoneId)
+
+@Composable
+fun LiveGuideModalDialog(
+ onDismiss: () -> Unit,
+ contentAlignment: Alignment = Alignment.Center,
+ content: @Composable BoxScope.() -> Unit
+) {
+ Dialog(
+ onDismissRequest = onDismiss,
+ properties = DialogProperties(
+ usePlatformDefaultWidth = false,
+ dismissOnBackPress = true,
+ dismissOnClickOutside = false
+ )
+ ) {
+ Box(
+ modifier = Modifier.fillMaxSize(),
+ contentAlignment = contentAlignment
+ ) {
+ Box(
+ modifier = Modifier
+ .matchParentSize()
+ .background(Color.Black.copy(alpha = 0.68f))
+ .clickable(
+ onClick = onDismiss,
+ indication = null,
+ interactionSource = remember { androidx.compose.foundation.interaction.MutableInteractionSource() }
+ )
+ )
+ content()
+ }
+ }
+}
+
+@Composable
+fun LiveGuideOptionsOverlay(
+ selectedDayStart: Long,
+ selectedMode: GuideChannelMode,
+ selectedDensity: GuideDensity,
+ showScheduledOnly: Boolean,
+ showFavoritesOnly: Boolean,
+ controlLabels: LiveGuideControlLabels,
+ labels: LiveGuideOptionsLabels,
+ onDismiss: () -> Unit,
+ onShowAppNavigation: () -> Unit,
+ onJumpToPreviousDay: () -> Unit,
+ onPageBackward: () -> Unit,
+ onJumpBackwardHalfHour: () -> Unit,
+ onJumpBackward: () -> Unit,
+ onJumpToNow: () -> Unit,
+ onJumpForwardHalfHour: () -> Unit,
+ onJumpForward: () -> Unit,
+ onPageForward: () -> Unit,
+ onJumpToPrimeTime: () -> Unit,
+ onJumpToTomorrow: () -> Unit,
+ onJumpToNextDay: () -> Unit,
+ onDaySelected: (Long) -> Unit,
+ onModeSelected: (GuideChannelMode) -> Unit,
+ onDensitySelected: (GuideDensity) -> Unit,
+ onToggleScheduledOnly: () -> Unit,
+ onToggleFavoritesOnly: () -> Unit,
+ onRefresh: () -> Unit,
+ onManageEpgMatch: (() -> Unit)? = null
+) {
+ val optionsFocusRequester = remember { FocusRequester() }
+ LaunchedEffect(Unit) {
+ optionsFocusRequester.requestFocus()
+ }
+ LiveGuideModalDialog(onDismiss = onDismiss) {
+ Surface(
+ modifier = Modifier
+ .fillMaxWidth(0.68f)
+ .fillMaxHeight(0.78f)
+ .focusGroup(),
+ colors = SurfaceDefaults.colors(containerColor = com.streamvault.core.ui.theme.SurfaceElevated),
+ shape = RoundedCornerShape(20.dp)
+ ) {
+ Column(
+ modifier = Modifier
+ .fillMaxSize()
+ .verticalScroll(rememberScrollState())
+ .padding(vertical = 18.dp),
+ verticalArrangement = Arrangement.spacedBy(12.dp)
+ ) {
+ Row(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(horizontal = 18.dp),
+ horizontalArrangement = Arrangement.SpaceBetween,
+ verticalAlignment = Alignment.CenterVertically
+ ) {
+ Text(
+ text = labels.title,
+ style = MaterialTheme.typography.headlineSmall,
+ color = com.streamvault.core.ui.theme.OnSurface
+ )
+ Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
+ LiveGuideShortcutChip(
+ label = labels.showAppNavigation,
+ onClick = onShowAppNavigation
+ )
+ LiveGuideShortcutChip(
+ label = labels.cancel,
+ onClick = onDismiss
+ )
+ }
+ }
+ LiveGuideTimeControlsRow(
+ labels = controlLabels.time,
+ onJumpToPreviousDay = onJumpToPreviousDay,
+ onPageBackward = onPageBackward,
+ onJumpBackwardHalfHour = onJumpBackwardHalfHour,
+ onJumpBackward = onJumpBackward,
+ onJumpToNow = onJumpToNow,
+ onJumpForwardHalfHour = onJumpForwardHalfHour,
+ onJumpForward = onJumpForward,
+ onPageForward = onPageForward,
+ onJumpToPrimeTime = onJumpToPrimeTime,
+ onJumpToTomorrow = onJumpToTomorrow,
+ onJumpToNextDay = onJumpToNextDay,
+ firstChipFocusRequester = optionsFocusRequester
+ )
+ LiveGuideDayRow(
+ selectedDayStart = selectedDayStart,
+ labels = controlLabels.day,
+ onDaySelected = onDaySelected
+ )
+ LiveGuideModeRow(
+ selectedMode = selectedMode,
+ labels = controlLabels.mode,
+ onModeSelected = onModeSelected
+ )
+ LiveGuideDensityRow(
+ selectedDensity = selectedDensity,
+ labels = controlLabels.density,
+ onDensitySelected = onDensitySelected
+ )
+ LiveGuideViewOptionsRow(
+ showScheduledOnly = showScheduledOnly,
+ labels = controlLabels.viewOptions,
+ onToggleScheduledOnly = onToggleScheduledOnly
+ )
+ LiveGuideFavoritesRow(
+ showFavoritesOnly = showFavoritesOnly,
+ labels = controlLabels.favorites,
+ onToggleFavoritesOnly = onToggleFavoritesOnly
+ )
+ Row(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(horizontal = 24.dp),
+ horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End)
+ ) {
+ if (onManageEpgMatch != null) {
+ LiveGuideShortcutChip(
+ label = labels.manageEpgMatch,
+ onClick = onManageEpgMatch
+ )
+ }
+ LiveGuideShortcutChip(
+ label = labels.refreshGuide,
+ onClick = onRefresh
+ )
+ }
+ }
+ }
+ }
+}
diff --git a/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideOptionsTest.kt b/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideOptionsTest.kt
new file mode 100644
index 00000000..5d5e5437
--- /dev/null
+++ b/feature/live/src/test/java/com/streamvault/feature/live/presentation/epg/LiveGuideOptionsTest.kt
@@ -0,0 +1,15 @@
+package com.streamvault.feature.live.presentation.epg
+
+import com.google.common.truth.Truth.assertThat
+import java.time.ZoneId
+import org.junit.Test
+
+class LiveGuideOptionsTest {
+ @Test
+ fun `selected guide day is derived from the lookback-adjusted window`() {
+ val windowStart = 2 * 24 * 60 * 60 * 1000L + 5 * 60 * 60 * 1000L
+
+ assertThat(liveGuideOptionsDayStart(windowStart, 60 * 60 * 1000L, ZoneId.of("UTC")))
+ .isEqualTo(2 * 24 * 60 * 60 * 1000L)
+ }
+}