mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-06-11 07:37:59 +02:00
refactor
fixed brightness reset after soft close comments
This commit is contained in:
parent
1fbbfd90f3
commit
7c0b506b90
|
@ -111,7 +111,7 @@ class SwipeControlsConfigurationProvider(
|
||||||
get() = Settings.SWIPE_ENABLE_LOWEST_VALUE_AUTO_BRIGHTNESS.get()
|
get() = Settings.SWIPE_ENABLE_LOWEST_VALUE_AUTO_BRIGHTNESS.get()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* variable that stores the brightness gesture value
|
* variable that stores the brightness gesture value in the settings
|
||||||
*/
|
*/
|
||||||
var savedScreenBrightnessValue: Float
|
var savedScreenBrightnessValue: Float
|
||||||
get() = Settings.SWIPE_BRIGHTNESS_VALUE.get()
|
get() = Settings.SWIPE_BRIGHTNESS_VALUE.get()
|
||||||
|
|
|
@ -166,22 +166,31 @@ class SwipeControlsHostActivity : Activity() {
|
||||||
contentRoot.addView(overlay)
|
contentRoot.addView(overlay)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flag that indicates whether the brightness has been saved and restored default brightness
|
||||||
|
private var isBrightnessSaved = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* called when the player type changes
|
* called when the player type changes
|
||||||
*
|
*
|
||||||
* @param type the new player type
|
* @param type the new player type
|
||||||
*/
|
*/
|
||||||
private fun onPlayerTypeChanged(type: PlayerType) {
|
private fun onPlayerTypeChanged(type: PlayerType) {
|
||||||
if (config.shouldSaveAndRestoreBrightness) {
|
when {
|
||||||
when (type) {
|
// If saving and restoring brightness is enabled, and the player type is WATCH_WHILE_FULLSCREEN,
|
||||||
PlayerType.WATCH_WHILE_FULLSCREEN -> screen?.restore()
|
// and brightness has already been saved, then restore the screen brightness
|
||||||
else -> {
|
config.shouldSaveAndRestoreBrightness && type == PlayerType.WATCH_WHILE_FULLSCREEN && isBrightnessSaved -> {
|
||||||
screen?.save()
|
screen?.restore()
|
||||||
screen?.restoreDefaultBrightness()
|
isBrightnessSaved = false
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
// If saving and restoring brightness is enabled, and brightness has not been saved,
|
||||||
screen?.restoreDefaultBrightness() // here was lost the function of restore the default brightness
|
// then save the current screen state, restore default brightness, and mark brightness as saved
|
||||||
|
config.shouldSaveAndRestoreBrightness && !isBrightnessSaved -> {
|
||||||
|
screen?.save()
|
||||||
|
screen?.restoreDefaultBrightness()
|
||||||
|
isBrightnessSaved = true
|
||||||
|
}
|
||||||
|
// If saving and restoring brightness is disabled, simply keep the default brightness
|
||||||
|
else -> screen?.restoreDefaultBrightness()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,9 @@ import app.revanced.integrations.youtube.swipecontrols.misc.clamp
|
||||||
*/
|
*/
|
||||||
class ScreenBrightnessController(
|
class ScreenBrightnessController(
|
||||||
private val host: Activity,
|
private val host: Activity,
|
||||||
val config: SwipeControlsConfigurationProvider,
|
val config: SwipeControlsConfigurationProvider = SwipeControlsConfigurationProvider(host),
|
||||||
) {
|
) {
|
||||||
|
|
||||||
constructor(context: Activity) : this(context, SwipeControlsConfigurationProvider(context))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the current screen brightness in percent, ranging from 0.0 to 100.0
|
* the current screen brightness in percent, ranging from 0.0 to 100.0
|
||||||
*/
|
*/
|
||||||
|
@ -26,25 +24,31 @@ class ScreenBrightnessController(
|
||||||
rawScreenBrightness = (value.toFloat() / 100f).clamp(0f, 1f)
|
rawScreenBrightness = (value.toFloat() / 100f).clamp(0f, 1f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* restore the screen brightness to the default device brightness
|
|
||||||
*/
|
|
||||||
fun restoreDefaultBrightness() {
|
|
||||||
rawScreenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* is the screen brightness set to device- default?
|
* is the screen brightness set to device- default?
|
||||||
*/
|
*/
|
||||||
val isDefaultBrightness
|
val isDefaultBrightness
|
||||||
get() = (rawScreenBrightness == WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE)
|
get() = (rawScreenBrightness == WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* restore the screen brightness to the default device brightness
|
||||||
|
*/
|
||||||
|
fun restoreDefaultBrightness() {
|
||||||
|
rawScreenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flag that indicates whether the brightness has been restored
|
||||||
|
private var isBrightnessRestored = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* save the current screen brightness into settings, to be brought back using [restore]
|
* save the current screen brightness into settings, to be brought back using [restore]
|
||||||
*/
|
*/
|
||||||
fun save() {
|
fun save() {
|
||||||
if (config.savedScreenBrightnessValue == -1f) {
|
if (isBrightnessRestored) {
|
||||||
|
// Saves the current screen brightness value into settings
|
||||||
config.savedScreenBrightnessValue = rawScreenBrightness
|
config.savedScreenBrightnessValue = rawScreenBrightness
|
||||||
|
// Reset the flag
|
||||||
|
isBrightnessRestored = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,8 +56,10 @@ class ScreenBrightnessController(
|
||||||
* restore the screen brightness from settings saved using [save]
|
* restore the screen brightness from settings saved using [save]
|
||||||
*/
|
*/
|
||||||
fun restore() {
|
fun restore() {
|
||||||
|
// Restores the screen brightness value from the saved settings
|
||||||
rawScreenBrightness = config.savedScreenBrightnessValue
|
rawScreenBrightness = config.savedScreenBrightnessValue
|
||||||
config.savedScreenBrightnessValue = -1f
|
// Mark that brightness has been restored
|
||||||
|
isBrightnessRestored = true
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user