fix: add cancelLoading method to StreamsRepository

This commit is contained in:
tapframe 2026-04-30 21:54:58 +05:30
parent 8a58fabfdd
commit 5e65881716
2 changed files with 26 additions and 0 deletions

View file

@ -1327,6 +1327,7 @@ private fun MainAppContent(
)
)
StreamsRepository.consumeAutoPlay()
StreamsRepository.cancelLoading()
navController.navigate(PlayerRoute(launchId = launchId)) {
popUpTo<StreamRoute> { inclusive = true }
}
@ -1405,6 +1406,7 @@ private fun MainAppContent(
initialProgressFraction = resolvedResumeProgressFraction,
)
)
StreamsRepository.cancelLoading()
navController.navigate(
PlayerRoute(launchId = launchId)
)

View file

@ -424,8 +424,32 @@ object StreamsRepository {
}
}
fun cancelLoading() {
activeJob?.cancel()
activeJob = null
_uiState.update { current ->
if (!current.isAnyLoading && current.groups.none { it.isLoading }) {
current
} else {
val updatedGroups = current.groups.map { group ->
if (group.isLoading) group.copy(isLoading = false) else group
}
current.copy(
groups = updatedGroups,
isAnyLoading = false,
emptyStateReason = if (updatedGroups.isEmpty()) {
current.emptyStateReason
} else {
updatedGroups.toEmptyStateReason(anyLoading = false)
},
)
}
}
}
fun clear() {
activeJob?.cancel()
activeJob = null
activeRequestKey = null
_uiState.value = StreamsUiState()
}