Skip to content
Open
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
13 changes: 13 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
alias(libs.plugins.ksp)
alias(libs.plugins.hilt)
alias(libs.plugins.kover)
alias(libs.plugins.baselineprofile)
}

val keystorePropertiesFile = rootProject.file("keystore.properties")
Expand Down Expand Up @@ -151,6 +152,13 @@ kotlin {
}
}

composeCompiler {
// Marks cross-module immutable classes (domain models, java.time) as stable so
// composables taking them as parameters can skip recomposition. See
// compose-stability.conf at the repo root.
stabilityConfigurationFiles.add(rootProject.layout.projectDirectory.file("compose-stability.conf"))
}

kover {
currentProject {
createVariant("ci") {
Expand All @@ -161,6 +169,11 @@ kover {

dependencies {
coreLibraryDesugaring(libs.desugar.jdk.libs)
// Installs the baseline profile (app + androidx library rules) at install time so
// sideloaded builds (Fire TV) get AOT-compiled hot paths instead of cold JIT.
implementation(libs.profileinstaller)
// Profile generator module; run ./gradlew :app:generateBaselineProfile to refresh.
baselineProfile(project(":baselineprofile"))
implementation(project(":domain"))
implementation(project(":data"))
implementation(project(":player"))
Expand Down
27,293 changes: 27,293 additions & 0 deletions app/src/beta/generated/baselineProfiles/baseline-prof.txt

Large diffs are not rendered by default.

27,293 changes: 27,293 additions & 0 deletions app/src/beta/generated/baselineProfiles/startup-prof.txt

Large diffs are not rendered by default.

45 changes: 35 additions & 10 deletions app/src/main/java/com/streamvault/app/ui/screens/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,11 @@ fun HomeScreen(
LiveTvChannelMode.COMPACT -> 2.dp
LiveTvChannelMode.PRO -> 2.dp
}
val previewChannel = remember(uiState.filteredChannels, uiState.previewChannelId) {
uiState.filteredChannels.firstOrNull { it.id == uiState.previewChannelId }
}
// Preview state is collected as a State object (not delegated) so the screen
// body only subscribes to the derived "is a preview active" boolean; the
// full preview state is read inside HomeLivePreviewHost, keeping playback
// ticks from recomposing this whole scope.
val previewUiState = viewModel.previewUiState.collectAsStateWithLifecycle()
val snackbarHostState = remember { SnackbarHostState() }

// Split screen state
Expand Down Expand Up @@ -234,7 +236,7 @@ fun HomeScreen(
}
}

val hasActivePreview = uiState.previewPlayerEngine != null
val hasActivePreview by remember { derivedStateOf { previewUiState.value.playerEngine != null } }
DisposableEffect(hasActivePreview) {
val window = (context as? android.app.Activity)?.window
if (hasActivePreview) {
Expand Down Expand Up @@ -1279,7 +1281,7 @@ fun HomeScreen(
pendingUnlockChannel = channel
showPinDialog = true
} else if (isProMode) {
if (uiState.previewChannelId == channel.id) {
if (previewUiState.value.channelId == channel.id) {
val handedOff = viewModel.beginPreviewHandoff(channel)
if (!handedOff) {
viewModel.clearPreview()
Expand Down Expand Up @@ -1352,11 +1354,9 @@ fun HomeScreen(
}

if (isProMode) {
LivePreviewPane(
channel = previewChannel,
playerEngine = uiState.previewPlayerEngine,
isLoading = uiState.isPreviewLoading,
errorMessage = uiState.previewErrorMessage,
HomeLivePreviewHost(
previewUiState = previewUiState,
channels = uiState.filteredChannels,
modifier = Modifier
.weight(0.92f)
.fillMaxHeight()
Expand All @@ -1378,4 +1378,29 @@ fun HomeScreen(

}

/**
* Isolated recomposition scope for the live preview pane. Reads [previewUiState]
* here (not in the HomeScreen body) so preview playback ticks — loading and
* error transitions while a stream spins up or rebuffers — only recompose this
* host instead of the entire Home screen.
*/
@Composable
private fun HomeLivePreviewHost(
previewUiState: State<HomePreviewUiState>,
channels: List<Channel>,
modifier: Modifier = Modifier
) {
val preview = previewUiState.value
val channel = remember(channels, preview.channelId) {
channels.firstOrNull { it.id == preview.channelId }
}
LivePreviewPane(
channel = channel,
playerEngine = preview.playerEngine,
isLoading = preview.isLoading,
errorMessage = preview.errorMessage,
modifier = modifier
)
}

// SearchInput moved to its own component file
110 changes: 53 additions & 57 deletions app/src/main/java/com/streamvault/app/ui/screens/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ class HomeViewModel @Inject constructor(

private val _uiState = MutableStateFlow(HomeUiState())
val uiState: StateFlow<HomeUiState> = _uiState.asStateFlow()

// Preview playback state lives in its own flow so high-frequency playback
// ticks (loading/error transitions while a stream spins up or stalls) do not
// copy-and-republish the whole HomeUiState, which recomposes the entire
// Home screen scope. Collected only by the preview pane host.
private val _previewUiState = MutableStateFlow(HomePreviewUiState())
val previewUiState: StateFlow<HomePreviewUiState> = _previewUiState.asStateFlow()
val remoteShortcutPreferences = preferencesRepository.remoteShortcutPreferences
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000L), com.streamvault.domain.model.RemoteShortcutPreferences())

Expand Down Expand Up @@ -287,7 +294,7 @@ class HomeViewModel @Inject constructor(
state.copy(filteredChannels = markedChannels)
}
}
val previewChannelId = _uiState.value.previewChannelId
val previewChannelId = _previewUiState.value.channelId
if (previewChannelId != null && markedChannels.none { it.id == previewChannelId }) {
clearPreview()
}
Expand Down Expand Up @@ -992,33 +999,31 @@ class HomeViewModel @Inject constructor(

fun previewChannel(channel: Channel) {
if (_uiState.value.liveTvChannelMode != LiveTvChannelMode.PRO) return
if (_uiState.value.previewChannelId == channel.id && _uiState.value.previewPlayerEngine != null) return
if (_previewUiState.value.channelId == channel.id && _previewUiState.value.playerEngine != null) return

val previewVersion = ++previewSessionVersion
val engine = previewPlayerEngine ?: playerEngineProvider.get().also { previewPlayerEngine = it }
previewPlaybackJob?.cancel()
previewErrorJob?.cancel()

_uiState.update {
it.copy(
previewChannelId = channel.id,
previewPlayerEngine = engine,
isPreviewLoading = true,
previewErrorMessage = null
)
}
_previewUiState.value = HomePreviewUiState(
channelId = channel.id,
playerEngine = engine,
isLoading = true,
errorMessage = null
)

previewPlaybackJob = viewModelScope.launch {
engine.playbackState.collectLatest { playbackState ->
if (!isActivePreviewSession(previewVersion, channel.id)) return@collectLatest
_uiState.update { state ->
_previewUiState.update { state ->
state.copy(
isPreviewLoading = playbackState == PlaybackState.IDLE || playbackState == PlaybackState.BUFFERING,
previewErrorMessage = when {
playbackState == PlaybackState.ERROR && state.previewErrorMessage.isNullOrBlank() ->
isLoading = playbackState == PlaybackState.IDLE || playbackState == PlaybackState.BUFFERING,
errorMessage = when {
playbackState == PlaybackState.ERROR && state.errorMessage.isNullOrBlank() ->
appContext.getString(R.string.live_preview_failed)
playbackState != PlaybackState.ERROR -> null
else -> state.previewErrorMessage
else -> state.errorMessage
}
)
}
Expand All @@ -1029,10 +1034,10 @@ class HomeViewModel @Inject constructor(
engine.error.collectLatest { error ->
if (!isActivePreviewSession(previewVersion, channel.id)) return@collectLatest
if (error != null) {
_uiState.update {
_previewUiState.update {
it.copy(
isPreviewLoading = false,
previewErrorMessage = error.message.ifBlank { appContext.getString(R.string.live_preview_failed) }
isLoading = false,
errorMessage = error.message.ifBlank { appContext.getString(R.string.live_preview_failed) }
)
}
}
Expand All @@ -1047,10 +1052,10 @@ class HomeViewModel @Inject constructor(
is Result.Success -> pluginResult.data
is Result.Error -> {
if (!isActivePreviewSession(previewVersion, channel.id)) return@launch
_uiState.update {
_previewUiState.update {
it.copy(
isPreviewLoading = false,
previewErrorMessage = pluginResult.message.ifBlank { appContext.getString(R.string.live_preview_failed) }
isLoading = false,
errorMessage = pluginResult.message.ifBlank { appContext.getString(R.string.live_preview_failed) }
)
}
return@launch
Expand Down Expand Up @@ -1083,10 +1088,10 @@ class HomeViewModel @Inject constructor(
}
is Result.Error -> {
if (!isActivePreviewSession(previewVersion, channel.id)) return@launch
_uiState.update {
_previewUiState.update {
it.copy(
isPreviewLoading = false,
previewErrorMessage = result.message
isLoading = false,
errorMessage = result.message
)
}
}
Expand All @@ -1106,7 +1111,7 @@ class HomeViewModel @Inject constructor(
viewModelScope.launch {
delay(ADAPTIVE_PREVIEW_REPRIME_DELAY_MS)
if (!isActivePreviewSession(previewVersion, channel.id)) return@launch
if (_uiState.value.previewErrorMessage != null) return@launch
if (_previewUiState.value.errorMessage != null) return@launch
if (engine.playbackState.value != PlaybackState.READY) return@launch
if (!engine.isPlaying.value) return@launch
if (engine.playerStats.value.ttffMs > 0L) return@launch
Expand All @@ -1123,7 +1128,7 @@ class HomeViewModel @Inject constructor(

fun beginPreviewHandoff(channel: Channel): Boolean {
val engine = previewPlayerEngine ?: return false
if (_uiState.value.previewChannelId != channel.id) return false
if (_previewUiState.value.channelId != channel.id) return false
if (!livePreviewHandoffManager.beginFullscreenHandoff(channel.id, engine)) return false

previewSessionVersion++
Expand All @@ -1132,14 +1137,7 @@ class HomeViewModel @Inject constructor(
previewPlaybackJob = null
previewErrorJob = null
previewPlayerEngine = null
_uiState.update {
it.copy(
previewChannelId = null,
previewPlayerEngine = null,
isPreviewLoading = false,
previewErrorMessage = null
)
}
_previewUiState.value = HomePreviewUiState()
return true
}

Expand Down Expand Up @@ -1169,19 +1167,17 @@ class HomeViewModel @Inject constructor(
engine = engine,
source = PreviewHandoffSource.HOME
)
_uiState.update {
it.copy(
previewChannelId = session.channelId,
previewPlayerEngine = engine,
isPreviewLoading = false,
previewErrorMessage = null
)
}
_previewUiState.value = HomePreviewUiState(
channelId = session.channelId,
playerEngine = engine,
isLoading = false,
errorMessage = null
)
previewPlaybackJob = viewModelScope.launch {
engine.playbackState.collectLatest { state ->
if (!isActivePreviewSession(version, session.channelId)) return@collectLatest
if (state == PlaybackState.ERROR && _uiState.value.previewErrorMessage == null) {
_uiState.update { it.copy(previewErrorMessage = appContext.getString(R.string.live_preview_failed)) }
if (state == PlaybackState.ERROR && _previewUiState.value.errorMessage == null) {
_previewUiState.update { it.copy(errorMessage = appContext.getString(R.string.live_preview_failed)) }
}
}
}
Expand All @@ -1198,18 +1194,11 @@ class HomeViewModel @Inject constructor(
previewPlayerEngine?.stop()
previewPlayerEngine?.release()
previewPlayerEngine = null
_uiState.update {
it.copy(
previewChannelId = null,
previewPlayerEngine = null,
isPreviewLoading = false,
previewErrorMessage = null
)
}
_previewUiState.value = HomePreviewUiState()
}

private fun isActivePreviewSession(version: Long, channelId: Long): Boolean =
version == previewSessionVersion && _uiState.value.previewChannelId == channelId
version == previewSessionVersion && _previewUiState.value.channelId == channelId

private fun fetchEpgForChannels(channels: List<Channel>) {
epgJob?.cancel()
Expand Down Expand Up @@ -2013,15 +2002,22 @@ data class HomeUiState(
val isChannelReorderMode: Boolean = false,
val reorderCategory: Category? = null,
val liveTvChannelMode: LiveTvChannelMode = LiveTvChannelMode.PRO,
val previewChannelId: Long? = null,
val previewPlayerEngine: PlayerEngine? = null,
val isPreviewLoading: Boolean = false,
val previewErrorMessage: String? = null,
val errorMessage: String? = null,
val multiviewChannelCount: Int = 0,
val multiviewSlotCapacity: Int = MultiViewManager.MAX_SLOTS
)

/**
* Live-preview playback state, split out of [HomeUiState] so playback ticks only
* recompose the preview pane host instead of the whole Home screen.
*/
data class HomePreviewUiState(
val channelId: Long? = null,
val playerEngine: PlayerEngine? = null,
val isLoading: Boolean = false,
val errorMessage: String? = null
)

private data class CategorySelectionContext(
val categories: List<Category>,
val defaultCategoryId: Long?,
Expand Down
Loading