Skip to content

Commit

Permalink
Fix pip changing
Browse files Browse the repository at this point in the history
  • Loading branch information
rozPierog committed Jul 14, 2022
1 parent 42ad42e commit 6315abc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
21 changes: 11 additions & 10 deletions app/src/main/java/com/omelan/cofi/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,19 @@ class MainActivity : MonetCompatActivity() {
if (isRunning) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} else {
blockPip()
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}

private fun blockPip() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
setPictureInPictureParams(
PictureInPictureParams.Builder().setAutoEnterEnabled(false).build()
)
}
}

@Composable
fun MainList(navController: NavController) {
RecipeList(
Expand Down Expand Up @@ -133,16 +142,8 @@ class MainActivity : MonetCompatActivity() {
ShortcutManagerCompat.pushDynamicShortcut(this@MainActivity, shortcut)
}
},
goBack = {
onTimerRunning(false)
goBack()
},
goToEdit = {
onTimerRunning(false)
navController.navigate(
route = "edit/$recipeId",
)
},
goBack = goBack,
goToEdit = { navController.navigate(route = "edit/$recipeId") },
onTimerRunning = onTimerRunning,
windowSizeClass = windowSizeClass,
)
Expand Down
20 changes: 13 additions & 7 deletions app/src/main/java/com/omelan/cofi/pages/RecipeDetails.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.app.PictureInPictureParams
import android.graphics.Rect
import android.media.MediaPlayer
import android.os.Build
import android.util.Log
import android.util.Rational
import androidx.annotation.RequiresApi
import androidx.compose.animation.*
Expand Down Expand Up @@ -45,10 +46,7 @@ import androidx.compose.ui.graphics.toAndroidRect
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.layout.boundsInWindow
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.platform.*
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
Expand Down Expand Up @@ -98,12 +96,15 @@ fun RecipeDetails(
}

@RequiresApi(Build.VERSION_CODES.O)
suspend fun setPiPSettings(activity: Activity, isTimerRunning: Boolean, sourceRectHint: Rect) {
suspend fun setPiPSettings(activity: Activity, isTimerRunning: Boolean, sourceRectHint: Rect?) {
if (activity !is MainActivity) {
return
}
val isPiPEnabled = DataStore(activity).getPiPSetting().first()
if ((!isTimerRunning || !isPiPEnabled) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (!isPiPEnabled) {
return
}
if (!isTimerRunning && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
activity.setPictureInPictureParams(
PictureInPictureParams.Builder().setAutoEnterEnabled(false).build()
)
Expand Down Expand Up @@ -272,6 +273,11 @@ fun RecipeDetails(
LaunchedEffect(isTimerRunning) {
onTimerRunning(isTimerRunning)
}
DisposableEffect(true) {
onDispose {
onTimerRunning(false)
}
}

suspend fun startRecipe() = coroutineScope.launch {
collapse()
Expand Down Expand Up @@ -555,7 +561,7 @@ fun StartFAB(isTimerRunning: Boolean, onClick: () -> Unit) {
val icon = AnimatedImageVector.animatedVectorResource(R.drawable.play_anim)
var atEnd by remember { mutableStateOf(false) }

LaunchedEffect(key1 = isTimerRunning) {
LaunchedEffect(isTimerRunning) {
launch {
atEnd = isTimerRunning
}
Expand Down

0 comments on commit 6315abc

Please sign in to comment.