From 612a23c1dcd67ba6d8b40e57adc91866553d23a9 Mon Sep 17 00:00:00 2001 From: Krunal Patel Date: Sat, 26 Nov 2022 14:07:03 +0530 Subject: [PATCH] Fix pip mode brightness issue Check if activity is in pip mode then use system brightness. Don't force to store brightness while returning from pip mode. Since it contains system brightness. --- .../libretube/ui/views/CustomExoPlayerView.kt | 2 +- .../github/libretube/util/BrightnessHelper.kt | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt index 045ec9c66..ccb198f29 100644 --- a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt +++ b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt @@ -445,7 +445,7 @@ internal class CustomExoPlayerView( if (PlayerHelper.swipeGestureEnabled) { when (newConfig?.orientation) { Configuration.ORIENTATION_LANDSCAPE -> brightnessHelper.restoreSavedBrightness() - else -> brightnessHelper.resetToSystemBrightness(true) + else -> brightnessHelper.resetToSystemBrightness(false) } } } diff --git a/app/src/main/java/com/github/libretube/util/BrightnessHelper.kt b/app/src/main/java/com/github/libretube/util/BrightnessHelper.kt index 6c6d88951..02aec92a1 100644 --- a/app/src/main/java/com/github/libretube/util/BrightnessHelper.kt +++ b/app/src/main/java/com/github/libretube/util/BrightnessHelper.kt @@ -1,11 +1,12 @@ package com.github.libretube.util import android.app.Activity +import android.os.Build import android.view.WindowManager import com.github.libretube.constants.PreferenceKeys import com.github.libretube.extensions.normalize -class BrightnessHelper(activity: Activity) { +class BrightnessHelper(private val activity: Activity) { private val window = activity.window private val minBrightness = 0.0f @@ -31,15 +32,13 @@ class BrightnessHelper(activity: Activity) { /** * Restore screen brightness to device system brightness. - * [saveOldValue] determines whether the old value should be persisted or not. + * if [forced] is false then value will be stored only if it's not + * [WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE] value. */ - fun resetToSystemBrightness(saveOldValue: Boolean = false) { - savedBrightness = if (saveOldValue) { - brightness - } else { - WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE + fun resetToSystemBrightness(forced: Boolean = true) { + if (forced || brightness != WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE) { + savedBrightness = brightness } - brightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE } @@ -47,6 +46,9 @@ class BrightnessHelper(activity: Activity) { * Set current screen brightness to saved brightness value. */ fun restoreSavedBrightness() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && activity.isInPictureInPictureMode) { + return + } brightness = savedBrightness }