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 channel list host

David Nashash3064eaa46305
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreen.kt b/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreen.kt
index 65c732b2..a4855f11 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreen.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreen.kt
@@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
-import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.border
import androidx.compose.foundation.background
@@ -43,6 +42,7 @@ import com.streamvault.feature.live.home.HomePreviewHost
import com.streamvault.feature.live.home.LiveChannelResultsHeader
import com.streamvault.feature.live.home.LiveCategorySidebarHeader
import com.streamvault.feature.live.home.LiveChannelContentHost
+import com.streamvault.feature.live.home.LiveChannelListHost
import com.streamvault.feature.live.presentation.components.LiveChannelRowSurface
import com.streamvault.core.ui.components.TvEmptyState
import com.streamvault.app.ui.components.dialogs.CategoryOptionsDialog
@@ -65,8 +65,6 @@ import com.streamvault.domain.model.Category
import com.streamvault.domain.model.Channel
import com.streamvault.domain.model.LegacyProvider as Provider
import kotlinx.coroutines.launch
-import kotlinx.coroutines.flow.distinctUntilChanged
-import kotlinx.coroutines.flow.filter
import androidx.compose.ui.res.stringResource
import com.streamvault.app.R
import com.streamvault.domain.model.LiveTvChannelMode
@@ -838,6 +836,22 @@ fun HomeScreen(
label = "category_content_transition"
) { _ ->
val selectedCategory = uiState.selectedCategory
+ var ignoreNextClick by remember { mutableStateOf(false) }
+ var draggingChannel by remember { mutableStateOf<Channel?>(null) }
+
+ LaunchedEffect(ignoreNextClick) {
+ if (ignoreNextClick) {
+ kotlinx.coroutines.delay(1000)
+ ignoreNextClick = false
+ }
+ }
+
+ LaunchedEffect(isReorderMode) {
+ if (!isReorderMode) {
+ draggingChannel = null
+ }
+ }
+
LiveChannelContentHost(
isLoading = uiState.isLoading,
errorMessage = uiState.errorMessage,
@@ -855,109 +869,23 @@ fun HomeScreen(
else -> null
}
) {
- var ignoreNextClick by remember { mutableStateOf(false) }
- val channelListState = rememberLazyListState()
-
- LaunchedEffect(ignoreNextClick) {
- if (ignoreNextClick) {
- kotlinx.coroutines.delay(1000)
- ignoreNextClick = false
- }
- }
-
- var draggingChannel by remember { mutableStateOf<Channel?>(null) }
-
- LaunchedEffect(isReorderMode) {
- if (!isReorderMode) {
- draggingChannel = null
- }
- }
-
- LaunchedEffect(isReorderMode, draggingChannel?.id, uiState.filteredChannels) {
- if (!isReorderMode) return@LaunchedEffect
- val draggingChannelId = draggingChannel?.id ?: return@LaunchedEffect
- val draggedIndex = uiState.filteredChannels.indexOfFirst { it.id == draggingChannelId }
- if (draggedIndex < 0) return@LaunchedEffect
-
- val visibleItems = channelListState.layoutInfo.visibleItemsInfo
- val firstVisibleIndex = visibleItems.firstOrNull()?.index
- val lastVisibleIndex = visibleItems.lastOrNull()?.index
-
- if (
- firstVisibleIndex != null &&
- lastVisibleIndex != null &&
- (draggedIndex <= firstVisibleIndex || draggedIndex >= lastVisibleIndex)
- ) {
- channelListState.scrollToItem(draggedIndex)
- }
-
- runCatching { channelFocusRequesters[draggingChannelId]?.requestFocus() }
- }
-
- LaunchedEffect(channelListState, uiState.filteredChannels, lastFocusedChannelId) {
- snapshotFlow {
- channelListState.layoutInfo.visibleItemsInfo.mapNotNull { item ->
- uiState.filteredChannels.getOrNull(item.index)?.id
- } to lastFocusedChannelId
- }
- .distinctUntilChanged()
- .collect { (visibleIds, focusedId) ->
- viewModel.updateVisibleChannelWindow(visibleIds, focusedId)
- }
- }
-
- // Load more channels when the user scrolls near the end of the list
- LaunchedEffect(channelListState) {
- snapshotFlow {
- val info = channelListState.layoutInfo
- val lastVisible = info.visibleItemsInfo.lastOrNull()?.index ?: -1
- val total = info.totalItemsCount
- uiState.hasMoreChannels && total > 0 && lastVisible >= total - 5
- }
- .distinctUntilChanged()
- .filter { it }
- .collect { viewModel.loadMoreChannels() }
- }
-
- DisposableEffect(Unit) {
- onDispose {
- viewModel.updateVisibleChannelWindow(emptyList(), null)
- }
- }
-
- LazyColumn(
- state = channelListState,
- modifier = Modifier
- .fillMaxSize()
- .onPreviewKeyEvent { event ->
- if (uiState.isChannelReorderMode && event.nativeKeyEvent.action == android.view.KeyEvent.ACTION_DOWN) {
- if (event.nativeKeyEvent.keyCode == android.view.KeyEvent.KEYCODE_BACK) {
- if (draggingChannel != null) {
- draggingChannel = null
- true
- } else {
- viewModel.exitChannelReorderMode()
- true
- }
- } else false
- } else false
- },
- contentPadding = PaddingValues(
- start = 10.dp,
- end = 10.dp,
- bottom = if (isDenseMode) 8.dp else 12.dp
- ),
- verticalArrangement = Arrangement.spacedBy(channelListSpacing)
- ) {
- items(
- items = uiState.filteredChannels,
- key = { it.id },
- contentType = { "live_channel" }
- ) { channel ->
+ LiveChannelListHost(
+ channels = uiState.filteredChannels,
+ hasMoreChannels = uiState.hasMoreChannels,
+ isReorderMode = isReorderMode,
+ draggingChannel = draggingChannel,
+ focusedChannelId = lastFocusedChannelId,
+ channelFocusRequesters = channelFocusRequesters,
+ contentPaddingBottom = if (isDenseMode) 8.dp else 12.dp,
+ channelListSpacing = channelListSpacing,
+ onDraggingChannelChange = { draggingChannel = it },
+ onExitReorderMode = viewModel::exitChannelReorderMode,
+ onMoveChannelUp = viewModel::moveChannelUp,
+ onMoveChannelDown = viewModel::moveChannelDown,
+ onVisibleChannelWindowChanged = viewModel::updateVisibleChannelWindow,
+ onLoadMore = viewModel::loadMoreChannels,
+ itemContent = { channel, channelFocusRequester, isDraggingThis ->
val isLocked = isChannelLocked(channel)
- val isDraggingThis = draggingChannel == channel
- val channelFocusRequester = channelFocusRequesters.getOrPut(channel.id) { FocusRequester() }
-
LiveChannelRowSurface(
channel = channel,
nowMs = nowMs,
@@ -1052,28 +980,9 @@ fun HomeScreen(
focusedRemoteShortcutTarget = null
}
}
- .onPreviewKeyEvent { event ->
- if (uiState.isChannelReorderMode && isDraggingThis && event.nativeKeyEvent.action == android.view.KeyEvent.ACTION_DOWN) {
- when (event.nativeKeyEvent.keyCode) {
- android.view.KeyEvent.KEYCODE_DPAD_LEFT -> {
- viewModel.moveChannelUp(channel); true
- }
- android.view.KeyEvent.KEYCODE_DPAD_UP -> {
- viewModel.moveChannelUp(channel); true
- }
- android.view.KeyEvent.KEYCODE_DPAD_RIGHT -> {
- viewModel.moveChannelDown(channel); true
- }
- android.view.KeyEvent.KEYCODE_DPAD_DOWN -> {
- viewModel.moveChannelDown(channel); true
- }
- else -> false
- }
- } else false
- }
)
}
- }
+ )
}
} // Crossfade
}
diff --git a/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md b/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
index 66620dba..67c63eb7 100644
--- a/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
+++ b/docs/COMPOSE_REDUCTION_PHASE5_TRANSITIONAL_DEPENDENCIES.md
@@ -132,7 +132,8 @@ the loading/preview host supporting composables, the live source switcher, Home
quick-filter panel/chip row, the reusable EPG guide shortcut chip, the shared
EPG guide-now ticker/provider, EPG search field/row, Home reorder top bar, and
Home channel row surface, Home channel-results header, Home category sidebar
-header, and channel-content state host are now feature-owned while the Home and EPG
+header, channel-content state host, and channel-list host are now feature-owned
+while the Home and EPG
screen/dialog composition remains in `:app`.
The source switcher receives localized labels from the app at the current
composition boundary. Live-owned
diff --git a/docs/superpowers/plans/2026-08-28-live-feature-extraction.md b/docs/superpowers/plans/2026-08-28-live-feature-extraction.md
index 5b92cb38..497d422d 100644
--- a/docs/superpowers/plans/2026-08-28-live-feature-extraction.md
+++ b/docs/superpowers/plans/2026-08-28-live-feature-extraction.md
@@ -22,7 +22,7 @@ loading/preview host supporting composables, the live source switcher, Home
quick-filter panel/chip row, the reusable EPG guide shortcut chip, the shared
EPG guide-now ticker/provider, EPG search field/row, Home reorder top bar,
Home channel row surface, Home channel-results header, Home category sidebar
-header, and channel-content state host are now feature-owned
+header, channel-content state host, and channel-list host are now feature-owned
and their feature checks are green. Home screen/dialog composition, the
remaining live cards/rows, complete locale resource migration, and acceptance
gates remain open.
@@ -667,7 +667,9 @@ also calls `LiveCategorySidebarHeader`, which owns source-switcher/search/
quick-filter layout while receiving app callbacks and localized labels. The
channel content state now calls `LiveChannelContentHost` for loading, error,
locked-empty, and no-channel presentation while keeping the channel-list slot
-in the app. The
+in the app. The list mechanics now call `LiveChannelListHost` for lazy-list
+state, visible-window/load-more reporting, reorder key handling, and drag
+auto-scroll while the app retains row presentation and channel actions. The
quick-filter key/selection rules are covered by `LiveQuickFiltersTest`. The
remaining app-owned live cards and shell/dialog composition still require
compatibility seams before the full Home move.
diff --git a/feature/live/src/main/java/com/streamvault/feature/live/home/LiveChannelListHost.kt b/feature/live/src/main/java/com/streamvault/feature/live/home/LiveChannelListHost.kt
new file mode 100644
index 00000000..fd95c65f
--- /dev/null
+++ b/feature/live/src/main/java/com/streamvault/feature/live/home/LiveChannelListHost.kt
@@ -0,0 +1,132 @@
+package com.streamvault.feature.live.home
+
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.lazy.items
+import androidx.compose.foundation.lazy.rememberLazyListState
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.DisposableEffect
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.snapshotFlow
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.focus.FocusRequester
+import androidx.compose.ui.input.key.*
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.unit.dp
+import com.streamvault.domain.model.Channel
+import kotlinx.coroutines.flow.distinctUntilChanged
+import kotlinx.coroutines.flow.filter
+
+@Composable
+fun LiveChannelListHost(
+ channels: List<Channel>,
+ hasMoreChannels: Boolean,
+ isReorderMode: Boolean,
+ draggingChannel: Channel?,
+ focusedChannelId: Long?,
+ channelFocusRequesters: MutableMap<Long, FocusRequester>,
+ contentPaddingBottom: Dp,
+ channelListSpacing: Dp,
+ onDraggingChannelChange: (Channel?) -> Unit,
+ onExitReorderMode: () -> Unit,
+ onMoveChannelUp: (Channel) -> Unit,
+ onMoveChannelDown: (Channel) -> Unit,
+ onVisibleChannelWindowChanged: (List<Long>, Long?) -> Unit,
+ onLoadMore: () -> Unit,
+ itemContent: @Composable (channel: Channel, focusRequester: FocusRequester, isDragging: Boolean) -> Unit,
+ modifier: Modifier = Modifier
+) {
+ val channelListState = rememberLazyListState()
+
+ LaunchedEffect(isReorderMode, draggingChannel?.id, channels) {
+ if (!isReorderMode) return@LaunchedEffect
+ val draggingChannelId = draggingChannel?.id ?: return@LaunchedEffect
+ val draggedIndex = channels.indexOfFirst { it.id == draggingChannelId }
+ if (draggedIndex < 0) return@LaunchedEffect
+
+ val visibleItems = channelListState.layoutInfo.visibleItemsInfo
+ val firstVisibleIndex = visibleItems.firstOrNull()?.index
+ val lastVisibleIndex = visibleItems.lastOrNull()?.index
+ if (
+ firstVisibleIndex != null &&
+ lastVisibleIndex != null &&
+ (draggedIndex <= firstVisibleIndex || draggedIndex >= lastVisibleIndex)
+ ) {
+ channelListState.scrollToItem(draggedIndex)
+ }
+
+ runCatching { channelFocusRequesters[draggingChannelId]?.requestFocus() }
+ }
+
+ LaunchedEffect(channelListState, channels, focusedChannelId) {
+ snapshotFlow {
+ channelListState.layoutInfo.visibleItemsInfo.mapNotNull { item ->
+ channels.getOrNull(item.index)?.id
+ } to focusedChannelId
+ }
+ .distinctUntilChanged()
+ .collect { (visibleIds, focusedId) ->
+ onVisibleChannelWindowChanged(visibleIds, focusedId)
+ }
+ }
+
+ LaunchedEffect(channelListState) {
+ snapshotFlow {
+ val info = channelListState.layoutInfo
+ val lastVisible = info.visibleItemsInfo.lastOrNull()?.index ?: -1
+ val total = info.totalItemsCount
+ hasMoreChannels && total > 0 && lastVisible >= total - 5
+ }
+ .distinctUntilChanged()
+ .filter { it }
+ .collect { onLoadMore() }
+ }
+
+ DisposableEffect(Unit) {
+ onDispose { onVisibleChannelWindowChanged(emptyList(), null) }
+ }
+
+ LazyColumn(
+ state = channelListState,
+ modifier = modifier
+ .fillMaxSize()
+ .onPreviewKeyEvent { event ->
+ if (!isReorderMode || event.type != KeyEventType.KeyDown) return@onPreviewKeyEvent false
+ when (event.nativeKeyEvent.keyCode) {
+ android.view.KeyEvent.KEYCODE_BACK -> {
+ if (draggingChannel != null) {
+ onDraggingChannelChange(null)
+ } else {
+ onExitReorderMode()
+ }
+ true
+ }
+ android.view.KeyEvent.KEYCODE_DPAD_LEFT,
+ android.view.KeyEvent.KEYCODE_DPAD_UP -> {
+ draggingChannel?.let(onMoveChannelUp)
+ draggingChannel != null
+ }
+ android.view.KeyEvent.KEYCODE_DPAD_RIGHT,
+ android.view.KeyEvent.KEYCODE_DPAD_DOWN -> {
+ draggingChannel?.let(onMoveChannelDown)
+ draggingChannel != null
+ }
+ else -> false
+ }
+ },
+ contentPadding = PaddingValues(start = 10.dp, end = 10.dp, bottom = contentPaddingBottom),
+ verticalArrangement = Arrangement.spacedBy(channelListSpacing)
+ ) {
+ items(
+ items = channels,
+ key = { it.id },
+ contentType = { "live_channel" }
+ ) { channel ->
+ val isDragging = draggingChannel == channel
+ val focusRequester = channelFocusRequesters.getOrPut(channel.id) { FocusRequester() }
+ itemContent(channel, focusRequester, isDragging)
+ }
+ }
+}