mirror of
https://github.com/revanced/revanced-integrations.git
synced 2025-01-19 08:17:33 +01:00
feat(YouTube - Swipe controls): Save and restore brightness and add auto-brightness toggle (#610)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
efd03012d0
commit
1c8e2b2941
@ -249,9 +249,9 @@ public class Settings extends BaseSettings {
|
|||||||
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
|
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
|
||||||
public static final LongSetting SWIPE_OVERLAY_TIMEOUT = new LongSetting("revanced_swipe_overlay_timeout", 500L, true,
|
public static final LongSetting SWIPE_OVERLAY_TIMEOUT = new LongSetting("revanced_swipe_overlay_timeout", 500L, true,
|
||||||
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
|
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
|
||||||
public static final BooleanSetting SWIPE_SAVE_AND_RESTORE_BRIGHTNESS = new BooleanSetting("revanced_swipe_save_and_restore_brightness", TRUE, true,
|
public static final BooleanSetting SWIPE_SAVE_AND_RESTORE_BRIGHTNESS = new BooleanSetting("revanced_swipe_save_and_restore_brightness", TRUE, true, parent(SWIPE_BRIGHTNESS));
|
||||||
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
|
public static final FloatSetting SWIPE_BRIGHTNESS_VALUE = new FloatSetting("revanced_swipe_brightness_value", -1f);
|
||||||
|
public static final BooleanSetting SWIPE_LOWEST_VALUE_ENABLE_AUTO_BRIGHTNESS = new BooleanSetting("revanced_swipe_lowest_value_enable_auto_brightness", FALSE, true, parent(SWIPE_BRIGHTNESS));
|
||||||
// Debugging
|
// Debugging
|
||||||
/**
|
/**
|
||||||
* When enabled, share the debug logs with care.
|
* When enabled, share the debug logs with care.
|
||||||
|
@ -104,5 +104,17 @@ class SwipeControlsConfigurationProvider(
|
|||||||
val shouldSaveAndRestoreBrightness: Boolean
|
val shouldSaveAndRestoreBrightness: Boolean
|
||||||
get() = Settings.SWIPE_SAVE_AND_RESTORE_BRIGHTNESS.get()
|
get() = Settings.SWIPE_SAVE_AND_RESTORE_BRIGHTNESS.get()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* should auto-brightness be enabled at the lowest value of the brightness gesture
|
||||||
|
*/
|
||||||
|
val shouldLowestValueEnableAutoBrightness: Boolean
|
||||||
|
get() = Settings.SWIPE_LOWEST_VALUE_ENABLE_AUTO_BRIGHTNESS.get()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* variable that stores the brightness gesture value in the settings
|
||||||
|
*/
|
||||||
|
var savedScreenBrightnessValue: Float
|
||||||
|
get() = Settings.SWIPE_BRIGHTNESS_VALUE.get()
|
||||||
|
set(value) = Settings.SWIPE_BRIGHTNESS_VALUE.save(value)
|
||||||
//endregion
|
//endregion
|
||||||
}
|
}
|
||||||
|
@ -166,20 +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?.restore()
|
||||||
|
isBrightnessSaved = false
|
||||||
|
}
|
||||||
|
// If saving and restoring brightness is enabled, and brightness has not been saved,
|
||||||
|
// then save the current screen state, restore default brightness, and mark brightness as saved
|
||||||
|
config.shouldSaveAndRestoreBrightness && !isBrightnessSaved -> {
|
||||||
screen?.save()
|
screen?.save()
|
||||||
screen?.restoreDefaultBrightness()
|
screen?.restoreDefaultBrightness()
|
||||||
|
isBrightnessSaved = true
|
||||||
}
|
}
|
||||||
}
|
// If saving and restoring brightness is disabled, simply keep the default brightness
|
||||||
|
else -> screen?.restoreDefaultBrightness()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,21 +1,17 @@
|
|||||||
package app.revanced.integrations.youtube.swipecontrols.controller
|
package app.revanced.integrations.youtube.swipecontrols.controller
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
|
import app.revanced.integrations.youtube.swipecontrols.SwipeControlsHostActivity
|
||||||
import app.revanced.integrations.youtube.swipecontrols.misc.clamp
|
import app.revanced.integrations.youtube.swipecontrols.misc.clamp
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* controller to adjust the screen brightness level
|
* controller to adjust the screen brightness level
|
||||||
*
|
*
|
||||||
* @param host the host activity of which the brightness is adjusted
|
* @param host the host activity of which the brightness is adjusted, the main controller instance
|
||||||
*/
|
*/
|
||||||
class ScreenBrightnessController(
|
class ScreenBrightnessController(
|
||||||
private val host: Activity,
|
val host: SwipeControlsHostActivity,
|
||||||
) {
|
) {
|
||||||
/**
|
|
||||||
* screen brightness saved by [save]
|
|
||||||
*/
|
|
||||||
private var savedScreenBrightness: Float? = null
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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,13 +22,6 @@ 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?
|
||||||
*/
|
*/
|
||||||
@ -40,22 +29,35 @@ class ScreenBrightnessController(
|
|||||||
get() = (rawScreenBrightness == WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE)
|
get() = (rawScreenBrightness == WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* save the current screen brightness, to be brought back using [restore]
|
* 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]
|
||||||
*/
|
*/
|
||||||
fun save() {
|
fun save() {
|
||||||
if (savedScreenBrightness == null) {
|
if (isBrightnessRestored) {
|
||||||
savedScreenBrightness = rawScreenBrightness
|
// Saves the current screen brightness value into settings
|
||||||
|
host.config.savedScreenBrightnessValue = rawScreenBrightness
|
||||||
|
// Reset the flag
|
||||||
|
isBrightnessRestored = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* restore the screen brightness saved using [save]
|
* restore the screen brightness from settings saved using [save]
|
||||||
*/
|
*/
|
||||||
fun restore() {
|
fun restore() {
|
||||||
savedScreenBrightness?.let {
|
// Restores the screen brightness value from the saved settings
|
||||||
rawScreenBrightness = it
|
rawScreenBrightness = host.config.savedScreenBrightnessValue
|
||||||
}
|
// Mark that brightness has been restored
|
||||||
savedScreenBrightness = null
|
isBrightnessRestored = true
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,12 +77,17 @@ class VolumeAndBrightnessScrollerImpl(
|
|||||||
),
|
),
|
||||||
) { _, _, direction ->
|
) { _, _, direction ->
|
||||||
screenController?.run {
|
screenController?.run {
|
||||||
if (screenBrightness > 0 || direction > 0) {
|
val shouldAdjustBrightness = if (host.config.shouldLowestValueEnableAutoBrightness) {
|
||||||
|
screenBrightness > 0 || direction > 0
|
||||||
|
} else {
|
||||||
|
screenBrightness >= 0 || direction >= 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldAdjustBrightness) {
|
||||||
screenBrightness += direction
|
screenBrightness += direction
|
||||||
} else {
|
} else {
|
||||||
restoreDefaultBrightness()
|
restoreDefaultBrightness()
|
||||||
}
|
}
|
||||||
|
|
||||||
overlayController.onBrightnessChanged(screenBrightness)
|
overlayController.onBrightnessChanged(screenBrightness)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import app.revanced.integrations.shared.StringRef.str
|
||||||
import app.revanced.integrations.shared.Utils
|
import app.revanced.integrations.shared.Utils
|
||||||
import app.revanced.integrations.youtube.swipecontrols.SwipeControlsConfigurationProvider
|
import app.revanced.integrations.youtube.swipecontrols.SwipeControlsConfigurationProvider
|
||||||
import app.revanced.integrations.youtube.swipecontrols.misc.SwipeControlsOverlay
|
import app.revanced.integrations.youtube.swipecontrols.misc.SwipeControlsOverlay
|
||||||
@ -122,10 +123,13 @@ class SwipeControlsOverlayLayout(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onBrightnessChanged(brightness: Double) {
|
override fun onBrightnessChanged(brightness: Double) {
|
||||||
if (brightness > 0) {
|
if (config.shouldLowestValueEnableAutoBrightness && brightness <= 0) {
|
||||||
|
showFeedbackView(
|
||||||
|
str("revanced_swipe_lowest_value_enable_auto_brightness_overlay_text"),
|
||||||
|
autoBrightnessIcon,
|
||||||
|
)
|
||||||
|
} else if (brightness >= 0) {
|
||||||
showFeedbackView("${round(brightness).toInt()}%", manualBrightnessIcon)
|
showFeedbackView("${round(brightness).toInt()}%", manualBrightnessIcon)
|
||||||
} else {
|
|
||||||
showFeedbackView("AUTO", autoBrightnessIcon)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user