Skip to content

Commit

Permalink
fix(player): Fix lag when toggling player ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Secozzi committed Jan 22, 2025
1 parent db018bb commit 4ebe949
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ class PlayerViewModel @JvmOverloads constructor(
private val _currentSource = MutableStateFlow<AnimeSource?>(null)
val currentSource = _currentSource.asStateFlow()

private val _isEpisodeOnline = MutableStateFlow(false)
val isEpisodeOnline = _isEpisodeOnline.asStateFlow()

private val _isLoadingEpisode = MutableStateFlow(false)
val isLoadingEpisode = _isLoadingEpisode.asStateFlow()

Expand Down Expand Up @@ -1126,6 +1129,7 @@ class PlayerViewModel @JvmOverloads constructor(

_currentEpisode.update { _ -> episode }
_currentSource.update { _ -> source }
_isEpisodeOnline.update { _ -> isEpisodeOnline() == true }

_hasPreviousEpisode.update { _ -> getCurrentEpisodeIndex() != 0 }
_hasNextEpisode.update { _ -> getCurrentEpisodeIndex() != currentPlaylist.value.size - 1 }
Expand Down Expand Up @@ -1206,6 +1210,7 @@ class PlayerViewModel @JvmOverloads constructor(
val chosenEpisode = currentPlaylist.value.firstOrNull { ep -> ep.id == episodeId } ?: return null

_currentEpisode.update { _ -> chosenEpisode }
_isEpisodeOnline.update { _ -> isEpisodeOnline() == true }

return withIOContext {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ fun PlayerControls(
// Top right controls
val autoPlayEnabled by playerPreferences.autoplayEnabled().collectAsState()
val videoList by viewModel.videoList.collectAsState()
val isEpisodeOnline by viewModel.isEpisodeOnline.collectAsState()
AnimatedVisibility(
controlsShown && !areControlsLocked,
enter = if (!reduceMotion) {
Expand Down Expand Up @@ -449,7 +450,7 @@ fun PlayerControls(
viewModel.showSheet(Sheets.QualityTracks)
}
},
isEpisodeOnline = viewModel.isEpisodeOnline(),
isEpisodeOnline = isEpisodeOnline,
onMoreClick = { viewModel.showSheet(Sheets.More) },
onMoreLongClick = { viewModel.showPanel(Panels.VideoFilters) },
)
Expand Down

0 comments on commit 4ebe949

Please sign in to comment.