Skip to content

Commit

Permalink
feat(player-ui): update provider link loading state dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
rhenwinch committed Oct 6, 2024
1 parent 7abbbdb commit 67efc26
Show file tree
Hide file tree
Showing 6 changed files with 321 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ abstract class BasePlayerViewModel(
}
}

loadSourceData(episode)
loadMediaLinks(episode)
}
}

Expand All @@ -439,7 +439,7 @@ abstract class BasePlayerViewModel(
*
* @param episodeToWatch an optional parameter for the episode to watch if film to be watched is a [TvShow]
*/
fun loadSourceData(
fun loadMediaLinks(
episodeToWatch: Episode? = null
) {
if (loadLinksFromNewProviderJob?.isActive == true || loadLinksJob?.isActive == true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import android.os.Build.VERSION.SDK_INT
import android.view.KeyEvent
import androidx.activity.ComponentActivity
import androidx.annotation.OptIn
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
Expand Down Expand Up @@ -37,7 +40,6 @@ import androidx.media3.common.util.UnstableApi
import com.flixclusive.core.ui.common.navigation.navigator.PlayerScreenNavigator
import com.flixclusive.core.ui.common.util.noIndicationClickable
import com.flixclusive.core.ui.mobile.ListenKeyEvents
import com.flixclusive.core.ui.mobile.component.provider.ProviderResourceStateDialog
import com.flixclusive.core.ui.mobile.rememberPipMode
import com.flixclusive.core.ui.mobile.util.toggleSystemBars
import com.flixclusive.core.ui.player.PLAYER_CONTROL_VISIBILITY_TIMEOUT
Expand All @@ -55,6 +57,7 @@ import com.flixclusive.core.ui.player.util.updatePiPParams
import com.flixclusive.core.util.android.getActivity
import com.flixclusive.domain.provider.CachedLinks
import com.flixclusive.feature.mobile.player.controls.PlayerControls
import com.flixclusive.feature.mobile.player.controls.dialogs.provider.ProviderResourceStateScreen
import com.flixclusive.feature.mobile.player.util.BrightnessManager
import com.flixclusive.feature.mobile.player.util.LocalBrightnessManager
import com.flixclusive.feature.mobile.player.util.PlayerPipReceiver
Expand Down Expand Up @@ -82,12 +85,12 @@ internal fun PlayerScreen(
val brightnessManager = remember { BrightnessManager(context) }

val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val dialogState by viewModel.dialogState.collectAsStateWithLifecycle()
val providerState by viewModel.dialogState.collectAsStateWithLifecycle()

val appSettings by viewModel.appSettings.collectAsStateWithLifecycle()
val watchHistoryItem by viewModel.watchHistoryItem.collectAsStateWithLifecycle()

val sourceData = viewModel.cachedLinks
val mediaData = viewModel.cachedLinks
val providers by viewModel.providers.collectAsStateWithLifecycle(initialValue = emptyList())
val seasonData by viewModel.season.collectAsStateWithLifecycle()
val currentSelectedEpisode by viewModel.currentSelectedEpisode.collectAsStateWithLifecycle()
Expand Down Expand Up @@ -158,10 +161,10 @@ internal fun PlayerScreen(
*
* */
LaunchedEffect(Unit) {
if (sourceData.watchId.isEmpty() || sourceData.providerName.isEmpty()) {
if (mediaData.watchId.isEmpty() || mediaData.providerName.isEmpty()) {
when(args.film) {
is TvShow -> onEpisodeClick(args.episodeToPlay)
is Movie -> viewModel.loadSourceData()
is Movie -> viewModel.loadMediaLinks()
else -> throw IllegalStateException("Invalid film instance [${args.film.filmType}]: ${args.film}")
}
}
Expand Down Expand Up @@ -283,8 +286,8 @@ internal fun PlayerScreen(
ObserveNewLinksAndSubtitles(
selectedSourceLink = uiState.selectedSourceLink,
currentPlayerTitle = currentPlayerTitle,
newLinks = sourceData.streams,
newSubtitles = sourceData.subtitles,
newLinks = mediaData.streams,
newSubtitles = mediaData.subtitles,
getSavedTimeForCurrentSourceData = {
viewModel.getSavedTimeForSourceData(currentSelectedEpisode).first
}
Expand Down Expand Up @@ -346,7 +349,7 @@ internal fun PlayerScreen(
= getSavedTimeForSourceData(currentSelectedEpisode)

player.initialize()
sourceData.run {
mediaData.run {
val getPossibleSourceLink = streams
.getOrNull(uiState.selectedSourceLink)
?: streams.getOrNull(0)
Expand Down Expand Up @@ -389,7 +392,7 @@ internal fun PlayerScreen(
isDoubleTapping = isDoubleTapping,
isEpisodesSheetOpened = isEpisodesSheetOpened,
isAudiosAndSubtitlesDialogOpened = isAudiosAndSubtitlesDialogOpened,
servers = sourceData.streams,
servers = mediaData.streams,
isPlayerSettingsDialogOpened = isPlayerSettingsDialogOpened,
isServersDialogOpened = isServersDialogOpened,
watchHistoryItem = watchHistoryItem,
Expand All @@ -413,7 +416,7 @@ internal fun PlayerScreen(
toggleVideoTimeReverse = viewModel::toggleVideoTimeReverse,
showControls = { showControls(it) },
lockControls = { viewModel.areControlsLocked = it },
addSubtitle = { sourceData.subtitles.add(index = 0, element = it) },
addSubtitle = { mediaData.subtitles.add(index = 0, element = it) },
onEpisodeClick = {
viewModel.run {
updateWatchHistory(
Expand Down Expand Up @@ -457,30 +460,46 @@ internal fun PlayerScreen(
}
}

if (!dialogState.isIdle) {
LaunchedEffect(Unit) {
viewModel.player.run {
if (isPlaying) {
pause()
playWhenReady = true

AnimatedVisibility(
visible = !providerState.isIdle,
enter = fadeIn(),
exit = fadeOut(),
) {
with(viewModel) {
DisposableEffect(Unit) {
if (player.isPlaying) {
player.pause()
player.playWhenReady = true
}

onDispose {
scrapingJob?.cancel()
scrapingJob = null
}
}
}

ProviderResourceStateDialog(
state = dialogState,
onConsumeDialog = {
scrapingJob?.cancel()
scrapingJob = null
viewModel.onConsumePlayerDialog()
ProviderResourceStateScreen(
state = providerState,
servers = mediaData.streams,
onSkipLoading = {
updateWatchHistory(
currentTime = player.currentPosition,
duration = player.duration
)

if (viewModel.player.playWhenReady) {
viewModel.player.play()
onEpisodeClick()
},
onClose = {
scrapingJob?.cancel()
scrapingJob = null
onConsumePlayerDialog()

if (player.playWhenReady) {
player.play()
}
}
}
)
} else {
scrapingJob?.cancel()
scrapingJob = null
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.flixclusive.feature.mobile.player.controls.common

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.flixclusive.core.ui.common.util.noIndicationClickable

@Composable
internal fun BasePopupScreen(
modifier: Modifier = Modifier,
onDismiss: () -> Unit,
content: @Composable ColumnScope.() -> Unit
) {
BackHandler {
onDismiss()
}

Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Black.copy(0.9F))
.then(modifier)
) {
// Block touches
Box(
modifier = Modifier
.fillMaxSize()
.noIndicationClickable { }
)

Column(
modifier = Modifier
.fillMaxSize()
.align(Alignment.TopStart),
verticalArrangement = Arrangement.spacedBy(15.dp),
) {
content()
}
}
}
Loading

0 comments on commit 67efc26

Please sign in to comment.