StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.
Kotlin iptv-player
perf: consolidate channel progress and audit lazy lists
David Nashash354ed0b20598
diff --git a/app/src/main/java/com/streamvault/app/ui/components/Cards.kt b/app/src/main/java/com/streamvault/app/ui/components/Cards.ktindex 2f65a145..0df80ab5 100644--- a/app/src/main/java/com/streamvault/app/ui/components/Cards.kt+++ b/app/src/main/java/com/streamvault/app/ui/components/Cards.kt@@ -26,7 +26,6 @@ import androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.rememberimport androidx.compose.runtime.setValue-import androidx.lifecycle.compose.collectAsStateWithLifecycleimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.draw.clip@@ -167,6 +166,7 @@ fun FocusableCard(@Composablefun ChannelCard(channel: Channel,+ nowMs: Long,onClick: () -> Unit,modifier: Modifier = Modifier,onLongClick: (() -> Unit)? = null,@@ -176,7 +176,6 @@ fun ChannelCard(isRecording: Boolean = false,isScheduledRecording: Boolean = false) {- val nowMs by ChannelProgressTicker.nowMs.collectAsStateWithLifecycle()val channelCardShape = LocalAppShapes.current.smallval hasUsableArchive = channel.archivePlaybackCapability().canBuildReplayCandidateval channelDescription = buildString {@@ -259,12 +258,14 @@ fun ChannelCard(overflow = TextOverflow.Ellipsis)- val totalDuration = program.endTime - program.startTime- val elapsed = nowMs - program.startTime- val progress = if (totalDuration > 0) elapsed.toFloat() / totalDuration else 0f-LinearProgressIndicator(- progress = { progress.coerceIn(0f, 1f) },+ progress = {+ channelProgressFraction(+ nowMs = nowMs,+ startTimeMs = program.startTime,+ endTimeMs = program.endTime+ )+ },modifier = Modifier.fillMaxWidth().height(2.dp)diff --git a/app/src/main/java/com/streamvault/app/ui/components/dialogs/AddToGroupDialog.kt b/app/src/main/java/com/streamvault/app/ui/components/dialogs/AddToGroupDialog.ktindex 4fdca945..eaebb0c3 100644--- a/app/src/main/java/com/streamvault/app/ui/components/dialogs/AddToGroupDialog.kt+++ b/app/src/main/java/com/streamvault/app/ui/components/dialogs/AddToGroupDialog.kt@@ -364,7 +364,11 @@ fun AddToGroupDialog()}- items(groups) { group ->+ items(+ items = groups,+ key = { it.id },+ contentType = { "category" }+ ) { group ->val isMember = memberOfGroups.contains(group.id)var isFocused by remember { mutableStateOf(false) }val groupAction = { if (isMember) safeRemoveFromGroup(group) else safeAddToGroup(group) }diff --git a/app/src/main/java/com/streamvault/app/ui/components/dialogs/M3uCategorySeriesAssignmentDialog.kt b/app/src/main/java/com/streamvault/app/ui/components/dialogs/M3uCategorySeriesAssignmentDialog.ktindex 86e5be19..67bf7ebf 100644--- a/app/src/main/java/com/streamvault/app/ui/components/dialogs/M3uCategorySeriesAssignmentDialog.kt+++ b/app/src/main/java/com/streamvault/app/ui/components/dialogs/M3uCategorySeriesAssignmentDialog.kt@@ -79,7 +79,11 @@ fun M3uCategorySeriesAssignmentDialog(modifier = Modifier.weight(1f),verticalArrangement = Arrangement.spacedBy(14.dp)) {- items(items, key = { it.channelId }) { item ->+ items(+ items = items,+ key = { it.channelId },+ contentType = { "series_assignment" }+ ) { item ->val draft = drafts[item.channelId] ?: return@itemsColumn(verticalArrangement = Arrangement.spacedBy(6.dp)) {Text(item.title, color = OnSurface)diff --git a/app/src/main/java/com/streamvault/app/ui/components/dialogs/ProgramHistoryDialog.kt b/app/src/main/java/com/streamvault/app/ui/components/dialogs/ProgramHistoryDialog.ktindex 4d989999..c75b4406 100644--- a/app/src/main/java/com/streamvault/app/ui/components/dialogs/ProgramHistoryDialog.kt+++ b/app/src/main/java/com/streamvault/app/ui/components/dialogs/ProgramHistoryDialog.kt@@ -123,7 +123,11 @@ fun ProgramHistoryDialog(modifier = Modifier.weight(1f),verticalArrangement = Arrangement.spacedBy(8.dp)) {- items(programs) { program ->+ items(+ items = programs,+ key = { "${it.channelId}:${it.startTime}:${it.endTime}:${it.id}" },+ contentType = { "program" }+ ) { program ->var isFocused by remember { mutableStateOf(false) }TvClickableSurface(diff --git a/app/src/main/java/com/streamvault/app/ui/components/shell/AppMediaCards.kt b/app/src/main/java/com/streamvault/app/ui/components/shell/AppMediaCards.ktindex a81d79fe..186071fd 100644--- a/app/src/main/java/com/streamvault/app/ui/components/shell/AppMediaCards.kt+++ b/app/src/main/java/com/streamvault/app/ui/components/shell/AppMediaCards.kt@@ -27,14 +27,6 @@ import androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.rememberimport androidx.compose.runtime.setValue-import androidx.lifecycle.compose.collectAsStateWithLifecycle-import kotlinx.coroutines.CoroutineScope-import kotlinx.coroutines.Dispatchers-import kotlinx.coroutines.SupervisorJob-import kotlinx.coroutines.delay-import kotlinx.coroutines.flow.SharingStarted-import kotlinx.coroutines.flow.flow-import kotlinx.coroutines.flow.stateInimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.draw.clip@@ -61,6 +53,7 @@ import androidx.tv.material3.Textimport coil3.compose.AsyncImageimport com.streamvault.app.Rimport com.streamvault.app.ui.components.ChannelLogoBadge+import com.streamvault.app.ui.components.channelProgressFractionimport com.streamvault.app.ui.components.rememberCrossfadeImageModelimport com.streamvault.app.ui.design.AppColorsimport com.streamvault.app.ui.design.AppMotion@@ -73,24 +66,10 @@ import com.streamvault.domain.model.Episodeimport com.streamvault.domain.model.Movieimport com.streamvault.domain.model.Series-private object LiveChannelRowTicker {- private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default)-- val nowMs = flow {- while (true) {- emit(System.currentTimeMillis())- delay(30_000L)- }- }.stateIn(- scope = scope,- started = SharingStarted.WhileSubscribed(stopTimeoutMillis = 30_000L),- initialValue = System.currentTimeMillis()- )-}-@Composablefun LiveChannelRowCard(channel: Channel,+ nowMs: Long,sourceBadgeLabel: String? = null,modifier: Modifier = Modifier,rowHeight: Dp = 68.dp@@ -103,7 +82,6 @@ fun LiveChannelRowCard(val logoPadding = if (isDense) 5.dp else if (isUltraCompact) 6.dp else 8.dpval contentSpacing = if (isUltraCompact) 8.dp else 10.dpval badgeSpacing = if (isUltraCompact) 3.dp else 4.dp- val nowMs by LiveChannelRowTicker.nowMs.collectAsStateWithLifecycle()val hasUsableArchive = channel.archivePlaybackCapability().canBuildReplayCandidateBox(@@ -186,11 +164,15 @@ fun LiveChannelRowCard(maxLines = 1,overflow = TextOverflow.Ellipsis)- val totalDuration = (program.endTime - program.startTime).coerceAtLeast(1L)- val elapsed = (nowMs - program.startTime).coerceAtLeast(0L)if (!isDense) {LinearProgressIndicator(- progress = { (elapsed.toFloat() / totalDuration.toFloat()).coerceIn(0f, 1f) },+ progress = {+ channelProgressFraction(+ nowMs = nowMs,+ startTimeMs = program.startTime,+ endTimeMs = program.endTime+ )+ },modifier = Modifier.fillMaxWidth().height(2.dp)@@ -214,6 +196,7 @@ fun LiveChannelRowCard(@Composablefun LiveChannelRowSurface(channel: Channel,+ nowMs: Long,onClick: () -> Unit,sourceBadgeLabel: String? = null,modifier: Modifier = Modifier,@@ -307,6 +290,7 @@ fun LiveChannelRowSurface(Box {LiveChannelRowCard(channel = channel,+ nowMs = nowMs,sourceBadgeLabel = sourceBadgeLabel,modifier = Modifier.fillMaxWidth(),rowHeight = rowHeightdiff --git a/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardScreen.kt b/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardScreen.ktindex 4595f514..a9e50614 100644--- a/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardScreen.kt+++ b/app/src/main/java/com/streamvault/app/ui/screens/dashboard/DashboardScreen.kt@@ -53,6 +53,7 @@ import coil3.compose.AsyncImageimport com.streamvault.app.Rimport com.streamvault.app.device.rememberIsTelevisionDeviceimport com.streamvault.app.ui.components.ChannelLogoBadge+import com.streamvault.app.ui.components.ChannelProgressTickerimport com.streamvault.app.navigation.Routesimport com.streamvault.app.ui.components.CategoryRowimport com.streamvault.app.ui.components.ChannelCard@@ -105,6 +106,7 @@ fun DashboardScreen(val uiState by viewModel.uiState.collectAsStateWithLifecycle()val recordingChannelIds by viewModel.recordingChannelIds.collectAsStateWithLifecycle()val scheduledChannelIds by viewModel.scheduledChannelIds.collectAsStateWithLifecycle()+ val nowMs by ChannelProgressTicker.nowMs.collectAsStateWithLifecycle()val provider = uiState.providerval snackbarHostState = remember { SnackbarHostState() }var showHomeCustomizationDialog by remember { mutableStateOf(false) }@@ -186,7 +188,11 @@ fun DashboardScreen()}}- items(orderedSections, key = { it.storageValue }) { section ->+ items(+ items = orderedSections,+ key = { it.storageValue },+ contentType = { it.storageValue }+ ) { section ->when (section) {AppHomeDashboardShelf.LIVE_SHORTCUTS -> DashboardShortcutRow(title = stringResource(R.string.dashboard_live_shortcuts),@@ -216,6 +222,7 @@ fun DashboardScreen() { channel ->ChannelCard(channel = channel,+ nowMs = nowMs,isRecording = channel.id in recordingChannelIds,isScheduledRecording = channel.id in scheduledChannelIds,onClick = { onRecentChannelClick(channel, uiState.currentCombinedProfileId) }diff --git a/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgGridComponents.kt b/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgGridComponents.ktindex 122c5618..ad3534a7 100644--- a/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgGridComponents.kt+++ b/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgGridComponents.kt@@ -191,7 +191,8 @@ internal fun EpgGrid() {itemsIndexed(items = channels,- key = { index, channel -> epgChannelKey(channel, index) }+ key = { index, channel -> epgChannelKey(channel, index) },+ contentType = { _, _ -> "epg_channel" }) { index, channel ->if (index >= channels.size - 15) {LaunchedEffect(channels.size) { onRequestMoreChannels() }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.ktindex 0a19c487..0d28c56d 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@@ -49,6 +49,7 @@ import androidx.lifecycle.Lifecycleimport androidx.lifecycle.compose.LifecycleEventEffectimport com.streamvault.app.ui.components.CategoryRowimport com.streamvault.app.ui.components.ChannelCard+import com.streamvault.app.ui.components.ChannelProgressTickerimport com.streamvault.app.ui.components.LiveSourceSwitcherimport com.streamvault.app.ui.components.shell.ContentMetadataStripimport com.streamvault.app.ui.components.shell.LiveChannelRowSurface@@ -185,6 +186,7 @@ fun HomeScreen() {val uiState by viewModel.uiState.collectAsStateWithLifecycle()val remoteShortcutPreferences by viewModel.remoteShortcutPreferences.collectAsStateWithLifecycle()+ val nowMs by ChannelProgressTicker.nowMs.collectAsStateWithLifecycle()val providerNameById = remember(uiState.allProviders) {uiState.allProviders.associateBy({ it.id }, { it.name })}@@ -951,7 +953,8 @@ fun HomeScreen(items(items = visibleCategories,- key = { it.id }+ key = { it.id },+ contentType = { "live_category" }) { category ->val isLocked = isCategoryLocked(category)val categoryFocusRequester = categoryFocusRequesters.getOrPut(category.id) { FocusRequester() }@@ -1291,7 +1294,8 @@ fun HomeScreen() {items(items = uiState.filteredChannels,- key = { it.id }+ key = { it.id },+ contentType = { "live_channel" }) { channel ->val isLocked = isChannelLocked(channel)val isDraggingThis = draggingChannel == channel@@ -1299,6 +1303,7 @@ fun HomeScreen(LiveChannelRowSurface(channel = channel,+ nowMs = nowMs,sourceBadgeLabel = uiState.currentCombinedProfileMembers.firstOrNull { it.providerId == channel.providerId }?.providerNamediff --git a/app/src/main/java/com/streamvault/app/ui/screens/player/overlay/PlayerChannelInfoOverlay.kt b/app/src/main/java/com/streamvault/app/ui/screens/player/overlay/PlayerChannelInfoOverlay.ktindex 819690db..b48adb32 100644--- a/app/src/main/java/com/streamvault/app/ui/screens/player/overlay/PlayerChannelInfoOverlay.kt+++ b/app/src/main/java/com/streamvault/app/ui/screens/player/overlay/PlayerChannelInfoOverlay.kt@@ -997,7 +997,11 @@ private fun ChannelInfoActionMenuTray(horizontalArrangement = Arrangement.spacedBy(8.dp),verticalAlignment = Alignment.CenterVertically) {- itemsIndexed(actions) { index, action ->+ itemsIndexed(+ items = actions,+ key = { index, action -> "${action.label}:$index" },+ contentType = { _, _ -> "channel_info_action" }+ ) { index, action ->CompactMenuActionButton(text = action.label,onClick = action.onClick,diff --git a/app/src/main/java/com/streamvault/app/ui/screens/player/overlay/PlayerControlsChrome.kt b/app/src/main/java/com/streamvault/app/ui/screens/player/overlay/PlayerControlsChrome.ktindex a793e3ed..ddcc85dd 100644--- a/app/src/main/java/com/streamvault/app/ui/screens/player/overlay/PlayerControlsChrome.kt+++ b/app/src/main/java/com/streamvault/app/ui/screens/player/overlay/PlayerControlsChrome.kt@@ -1596,7 +1596,11 @@ private fun PlayerQuickActionRows(horizontalArrangement = Arrangement.spacedBy(8.dp),contentPadding = PaddingValues(end = 4.dp)) {- itemsIndexed(actions) { actionIndex, action ->+ itemsIndexed(+ items = actions,+ key = { _, action -> action.label },+ contentType = { _, _ -> "player_quick_action" }+ ) { actionIndex, action ->PlayerQuickSettingsButton(text = action.label,onClick = action.onClick,diff --git a/app/src/main/java/com/streamvault/app/ui/screens/search/SearchScreen.kt b/app/src/main/java/com/streamvault/app/ui/screens/search/SearchScreen.ktindex 22bd427b..bbce05e7 100644--- a/app/src/main/java/com/streamvault/app/ui/screens/search/SearchScreen.kt+++ b/app/src/main/java/com/streamvault/app/ui/screens/search/SearchScreen.kt@@ -46,6 +46,7 @@ import com.streamvault.app.Rimport com.streamvault.app.ui.components.CategoryRowimport com.streamvault.app.ui.components.SearchInputimport com.streamvault.app.ui.components.ChannelCard+import com.streamvault.app.ui.components.ChannelProgressTickerimport com.streamvault.app.ui.components.MovieCardimport com.streamvault.app.ui.components.SeriesCardimport com.streamvault.app.ui.components.TvEmptyState@@ -377,6 +378,7 @@ fun SearchScreen(val uiState by viewModel.uiState.collectAsStateWithLifecycle()val recordingChannelIds by viewModel.recordingChannelIds.collectAsStateWithLifecycle()val scheduledChannelIds by viewModel.scheduledChannelIds.collectAsStateWithLifecycle()+ val nowMs by ChannelProgressTicker.nowMs.collectAsStateWithLifecycle()val focusManager = LocalFocusManager.currentval searchFocusRequester = remember { FocusRequester() }val context = androidx.compose.ui.platform.LocalContext.current@@ -639,6 +641,7 @@ fun SearchScreen()ChannelCard(channel = channel,+ nowMs = nowMs,isLocked = channelLocked,isRecording = channel.id in recordingChannelIds,isScheduledRecording = channel.id in scheduledChannelIds,@@ -727,11 +730,14 @@ fun SearchScreen(when (selectedTab) {SearchTab.ALL -> Unit- SearchTab.LIVE -> items(channelRows, key = { row ->- row.joinToString("-") { it.id.toString() }- }) { row ->+ SearchTab.LIVE -> items(+ items = channelRows,+ key = { row -> row.joinToString("-") { it.id.toString() } },+ contentType = { "search_live_row" }+ ) { row ->SearchChannelGridRow(channels = row,+ nowMs = nowMs,recordingChannelIds = recordingChannelIds,scheduledChannelIds = scheduledChannelIds,isLocked = { channel ->@@ -753,9 +759,11 @@ fun SearchScreen()}- SearchTab.MOVIES -> items(movieRows, key = { row ->- row.joinToString("-") { it.id.toString() }- }) { row ->+ SearchTab.MOVIES -> items(+ items = movieRows,+ key = { row -> row.joinToString("-") { it.id.toString() } },+ contentType = { "search_movie_row" }+ ) { row ->SearchMovieGridRow(movies = row,isLocked = { movie ->@@ -777,9 +785,11 @@ fun SearchScreen()}- SearchTab.SERIES -> items(seriesRows, key = { row ->- row.joinToString("-") { it.id.toString() }- }) { row ->+ SearchTab.SERIES -> items(+ items = seriesRows,+ key = { row -> row.joinToString("-") { it.id.toString() } },+ contentType = { "search_series_row" }+ ) { row ->SearchSeriesGridRow(seriesItems = row,isLocked = { seriesItem ->@@ -1040,6 +1050,7 @@ private fun <T : Any> SearchResultRail(@Composableprivate fun SearchChannelGridRow(channels: List<Channel>,+ nowMs: Long,recordingChannelIds: Set<Long> = emptySet(),scheduledChannelIds: Set<Long> = emptySet(),isLocked: (Channel) -> Boolean,@@ -1054,6 +1065,7 @@ private fun SearchChannelGridRow(val locked = isLocked(channel)ChannelCard(channel = channel,+ nowMs = nowMs,isLocked = locked,isRecording = channel.id in recordingChannelIds,isScheduledRecording = channel.id in scheduledChannelIds,diff --git a/docs/COMPOSE_REDUCTION_PHASE2_LIST_AUDIT.md b/docs/COMPOSE_REDUCTION_PHASE2_LIST_AUDIT.mdnew file mode 100644index 00000000..72bdc97c--- /dev/null+++ b/docs/COMPOSE_REDUCTION_PHASE2_LIST_AUDIT.md@@ -0,0 +1,32 @@+# Phase 2 lazy-list audit++This audit covers the Phase 2 hot paths: Home and Dashboard shelves, Search+results, the EPG channel rail, reusable media rows, and player/dialog lists.+The rule is to keep a stable domain identifier as the key and add+`contentType` when a list mixes item layouts or when a dynamic dialog list is+otherwise difficult for Compose to classify.++| Area / list | Key | `contentType` | Result |+| --- | --- | --- | --- |+| Dashboard sections | `AppHomeDashboardShelf.storageValue` | shelf storage value | Fixed; sections render materially different shelf layouts. |+| Dashboard recent/favorite/media `CategoryRow` shelves | Existing item IDs | CategoryRow supports an optional selector; omitted for homogeneous item renderers | Reviewed; stable keys are supplied by each caller and no mixed item layouts are present inside a shelf. |+| Dashboard shortcuts, stats, favorite-logo row | Existing shortcut/stat label or channel ID | Not required | Reviewed; each list is homogeneous and already keyed. |+| Home visible categories | Category ID | `live_category` | Fixed. |+| Home filtered channel list | Channel ID | `live_channel` | Fixed; this is also the owner of the shared channel clock. |+| Search result rails | Item ID through `CategoryRow` | Not required | Reviewed; each rail is homogeneous and uses the existing ID selector. |+| Search LIVE/MOVIES/SERIES result rows | Joined stable item IDs | `search_live_row`, `search_movie_row`, `search_series_row` | Fixed; the selected tab chooses a different row renderer. |+| Search tabs and recent queries | Tab name / query text | Not required | Reviewed; both lists are homogeneous and keyed. |+| EPG channel rows | `epgChannelKey(channel, index)` | `epg_channel` | Fixed; the index remains part of the existing collision-safe key policy. |+| `CategoryRow` reusable media shelf | Caller key selector | Caller selector, when needed | Reviewed; the reusable primitive already forwards keys and content types; homogeneous shelves only need the stable caller key. |+| `ContinueWatchingRow` | Playback-history ID | History content type | Already compliant. |+| Player channel/category/EPG overlay lists | Existing player item-key helpers | Existing channel/category/program types | Already compliant from the overlay audit. |+| Player track/variant/format/speed/timer/episode lists | Track/variant/format/speed/minutes/season/episode IDs | Homogeneous list types | Reviewed; stable keys are present and each list has one renderer. |+| Program history dialog | Channel/start/end/ID composite | `program` | Fixed; prevents index-key fallback when EPG data refreshes. |+| Add-to-group dialog | Category ID | `category` | Fixed. |+| M3U series-assignment dialog | Channel ID | `series_assignment` | Fixed. |+| Player short action rows | Positional action list | Not required | Reviewed; these are short, homogeneous action strips rather than data-backed scrolling lists. |++No display-text key was introduced where a stable domain ID was available.+The channel progress clock is collected once by Dashboard, Home, and Search;+`ChannelCard` and `LiveChannelRowCard` now receive the timestamp as a value and+do not collect a flow from inside a lazy-list item.