Skip to content

Commit

Permalink
disable pip until video screen reached
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Jul 7, 2024
1 parent 3c04dff commit 2ea10bd
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import dev.datlag.burningseries.model.BSUtil
import dev.datlag.burningseries.other.Constants
import dev.datlag.burningseries.other.DomainVerifier
import dev.datlag.burningseries.other.DownloadManager
import dev.datlag.burningseries.other.PictureInPicture
import dev.datlag.burningseries.settings.Settings
import dev.datlag.burningseries.ui.custom.video.pip.enterPIPMode
import dev.datlag.burningseries.ui.custom.video.pip.isActivityStatePipMode
Expand Down Expand Up @@ -76,7 +77,7 @@ class MainActivity : ComponentActivity() {
Kast.setup(this)
DownloadManager.setClient(httpClient).setFile(appContext ?: this)
DomainVerifier.verify(this)
PictureInPicture.update { this.isActivityStatePipMode() }
PictureInPicture.setActive(this.isActivityStatePipMode())

setContent {
val appSettings by di.instance<Settings.PlatformAppSettings>()
Expand Down Expand Up @@ -113,7 +114,10 @@ class MainActivity : ComponentActivity() {

override fun onUserLeaveHint() {
super.onUserLeaveHint()
enterPIPMode(this)

if (PictureInPicture.isEnabled) {
enterPIPMode(this)
}
}

@RequiresApi(Build.VERSION_CODES.O)
Expand All @@ -123,7 +127,7 @@ class MainActivity : ComponentActivity() {
) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)

PictureInPicture.update { isInPictureInPictureMode }
PictureInPicture.setActive(isInPictureInPictureMode)
}

override fun onDestroy() {
Expand All @@ -133,35 +137,35 @@ class MainActivity : ComponentActivity() {
Kast.dispose()
DomainVerifier.verify(this)

PictureInPicture.update { this.isActivityStatePipMode() }
PictureInPicture.setActive(this.isActivityStatePipMode())
}

override fun onStart() {
super.onStart()

DomainVerifier.verify(this)
PictureInPicture.update { this.isActivityStatePipMode() }
PictureInPicture.setActive(this.isActivityStatePipMode())
}

override fun onResume() {
super.onResume()

DomainVerifier.verify(this)
PictureInPicture.update { this.isActivityStatePipMode() }
PictureInPicture.setActive(this.isActivityStatePipMode())
}

override fun onPause() {
super.onPause()

DomainVerifier.verify(this)
PictureInPicture.update { this.isActivityStatePipMode() }
PictureInPicture.setActive(this.isActivityStatePipMode())
}

override fun onRestart() {
super.onRestart()

DomainVerifier.verify(this)
PictureInPicture.update { this.isActivityStatePipMode() }
PictureInPicture.setActive(this.isActivityStatePipMode())
}

private fun Uri.findSyncId(): String? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import org.kodein.di.DI

val LocalDarkMode = compositionLocalOf<Boolean> { error("No dark mode state provided") }
val LocalEdgeToEdge = staticCompositionLocalOf<Boolean> { false }
val PictureInPicture = MutableStateFlow(false)
val LocalDI = compositionLocalOf<DI> { error("No dependency injection provided") }
val LocalHaze = compositionLocalOf<HazeState> { error("No Haze state provided") }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dev.datlag.burningseries.other

import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update

data object PictureInPicture {
val enabled = MutableStateFlow(false)
val active = MutableStateFlow(false)

val isEnabled: Boolean
get() = enabled.value

fun setEnabled(value: Boolean) = enabled.update { value }
fun setActive(value: Boolean) = active.update { value }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
Expand All @@ -22,9 +24,9 @@ import com.arkivanov.decompose.ComponentContext
import com.arkivanov.essenty.lifecycle.Lifecycle
import com.arkivanov.essenty.lifecycle.LifecycleOwner
import dev.datlag.burningseries.LocalDI
import dev.datlag.burningseries.PictureInPicture
import dev.datlag.burningseries.common.nullableFirebaseInstance
import dev.datlag.burningseries.common.screen
import dev.datlag.burningseries.other.PictureInPicture
import dev.datlag.burningseries.ui.custom.PIPContent
import dev.datlag.burningseries.ui.theme.SchemeTheme
import dev.datlag.tooling.compose.launchDefault
Expand All @@ -43,6 +45,9 @@ interface Component : DIAware, ComponentContext {
val handlesPIP: Boolean
get() = false

val enablePIP: Boolean
get() = false

@Composable
fun render()

Expand All @@ -52,14 +57,18 @@ interface Component : DIAware, ComponentContext {

@Composable
fun onRender(content: @Composable (Boolean) -> Unit) {
LaunchedEffect(Unit) {
PictureInPicture.setEnabled(enablePIP)
}

CompositionLocalProvider(
LocalDI provides di,
LocalLifecycleOwner provides object : LifecycleOwner {
override val lifecycle: Lifecycle = this@Component.lifecycle
}
) {
Box {
val pip by PictureInPicture.collectAsStateWithLifecycle()
val pip by PictureInPicture.active.collectAsStateWithLifecycle()

content(pip)
if (pip && !handlesPIP) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package dev.datlag.burningseries.ui.navigation

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import dev.datlag.burningseries.PictureInPicture
import dev.datlag.burningseries.other.PictureInPicture
import dev.datlag.tooling.decompose.lifecycle.collectAsStateWithLifecycle

interface DialogComponent : Component {
fun dismiss()

@Composable
override fun onRender(content: @Composable (Boolean) -> Unit) {
val isPip by PictureInPicture.collectAsStateWithLifecycle()
val isPip by PictureInPicture.active.collectAsStateWithLifecycle()

if (!isPip || handlesPIP) {
super.onRender(content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import dev.datlag.burningseries.composeapp.generated.resources.Res
Expand Down Expand Up @@ -57,10 +58,15 @@ fun ErrorDialog(component: ErrorComponent) {
},
text = {
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(text = stringResource(Res.string.activate_error_text))
Text(
modifier = Modifier.fillMaxWidth(),
text = stringResource(Res.string.activate_error_text),
textAlign = TextAlign.Center
)
component.stream.ifEmpty { null }?.let { stream ->
Button(
modifier = Modifier.fillMaxWidth(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import dev.datlag.burningseries.composeapp.generated.resources.Res
Expand Down Expand Up @@ -49,10 +50,15 @@ fun SuccessDialog(component: SuccessComponent) {
},
text = {
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(text = stringResource(Res.string.activate_success_text))
Text(
modifier = Modifier.fillMaxWidth(),
text = stringResource(Res.string.activate_success_text),
textAlign = TextAlign.Center
)
component.stream.ifEmpty { null }?.let { stream ->
Button(
modifier = Modifier.fillMaxWidth(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class VideoScreenComponent(
}

override val handlesPIP: Boolean = true
override val enablePIP: Boolean = true

@Composable
override fun render() {
Expand Down

0 comments on commit 2ea10bd

Please sign in to comment.