Skip to content

Commit

Permalink
feat(settings): add option to enable/disable PiP mode
Browse files Browse the repository at this point in the history
Fixes #118
  • Loading branch information
rhenwinch committed Aug 24, 2024
1 parent 16b30d4 commit 1000dad
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class MobileActivity : ComponentActivity() {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& viewModel.uiState.value.isOnPlayerScreen
&& packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)
&& viewModel.isPiPModeEnabled
) {
// Force pip mode for player
enterPictureInPictureMode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.flixclusive.core.datastore.AppSettingsManager
import com.flixclusive.core.ui.mobile.KeyEventHandler
import com.flixclusive.core.util.common.resource.Resource
import com.flixclusive.data.util.InternetMonitor
Expand Down Expand Up @@ -41,6 +42,7 @@ internal class MobileAppViewModel @Inject constructor(
private val getMediaLinksUseCase: GetMediaLinksUseCase,
private val watchHistoryRepository: WatchHistoryRepository,
private val watchlistRepository: WatchlistRepository,
private val appSettingsManager: AppSettingsManager,
internetMonitor: InternetMonitor,
) : ViewModel() {
private var onFilmLongClickJob: Job? = null
Expand All @@ -59,6 +61,9 @@ internal class MobileAppViewModel @Inject constructor(
initialValue = runBlocking { internetMonitor.isOnline.first() }
)

val isPiPModeEnabled: Boolean
get() = appSettingsManager.localAppSettings.isPiPModeEnabled

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ object PlayerUiUtil {
fun AudioFocusManager(
activity: Activity,
preferredSeekAmount: Long,
isPiPModeEnabled: Boolean = false,
isTv: Boolean = false,
) {
val playerManager by rememberLocalPlayerManager()
Expand Down Expand Up @@ -345,7 +346,7 @@ object PlayerUiUtil {

playerTimeUpdaterJob = scope.launch {
playerManager.run {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !isTv) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !isTv && isPiPModeEnabled) {
activity.updatePiPParams(
isPlaying = isPlaying,
hasEnded = playbackState == Player.STATE_ENDED,
Expand Down
2 changes: 2 additions & 0 deletions core/util/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
<string name="opt_out_prerelease">Hell nah 😭</string>
<string name="other_films_message">Other films you might like!</string>
<string name="pause">Pause</string>
<string name="pip_mode">PiP mode</string>
<string name="play">Play</string>
<string name="playback_speed">Playback speed</string>
<string name="popular">Popular</string>
Expand Down Expand Up @@ -353,6 +354,7 @@
<string name="overview_expand">Expand all of the film\'s description</string>
<string name="owner_avatar_content_desc">Avatar or picture of repository\'s owner</string>
<string name="pause_button">Pause button</string>
<string name="pip_mode_desc">Picture-in-picture (PiP) lets you watch videos while using other apps.</string>
<string name="play_button">Play button</string>
<string name="play_pause_button_content_description">Play or pause button</string>
<string name="playback_speed_snackbar_message">Playback speed set to %1$s</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ fun PlayerScreen(

AudioFocusManager(
activity = context,
preferredSeekAmount = appSettings.preferredSeekAmount
preferredSeekAmount = appSettings.preferredSeekAmount,
isPiPModeEnabled = appSettings.isPiPModeEnabled
)

Box(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import com.flixclusive.core.ui.common.R as UiCommonR
import com.flixclusive.core.ui.common.util.onMediumEmphasis
import com.flixclusive.feature.mobile.settings.KEY_AUDIO_LANGUAGE_DIALOG
import com.flixclusive.feature.mobile.settings.KEY_PLAYER_QUALITY_DIALOG
Expand All @@ -21,6 +20,7 @@ import com.flixclusive.feature.mobile.settings.util.rememberLocalAppSettings
import com.flixclusive.feature.mobile.settings.util.rememberSettingsChanger
import com.flixclusive.model.datastore.player.ResizeMode
import java.util.Locale
import com.flixclusive.core.ui.common.R as UiCommonR
import com.flixclusive.core.util.R as UtilR

@Composable
Expand Down Expand Up @@ -67,6 +67,22 @@ internal fun currentVideoPlayerSettings(
)
}
),
SettingsItem(
title = stringResource(UtilR.string.pip_mode),
description = stringResource(UtilR.string.pip_mode_desc),
onClick = {
onChangeSettings(appSettings.copy(isPiPModeEnabled = !appSettings.isPiPModeEnabled))
},
previewContent = {
Switch(
checked = appSettings.isPiPModeEnabled,
onCheckedChange = {
onChangeSettings(appSettings.copy(isPiPModeEnabled = !appSettings.isPiPModeEnabled))
},
modifier = Modifier.scale(0.7F)
)
}
),
SettingsItem(
title = stringResource(UtilR.string.volume_booster),
onClick = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ data class AppSettings(
// == player
val shouldReleasePlayer: Boolean = true,
val isPlayerTimeReversed: Boolean = true,
val isPiPModeEnabled: Boolean = true,
val isUsingVolumeBoost: Boolean = false,
val preferredAudioLanguage: String = "en",
/** Unset = -1 = Default */
Expand Down

0 comments on commit 1000dad

Please sign in to comment.