feat(YouTube - Swipe controls): Remember current brightness at all times

This commit is contained in:
MarcaDian 2024-04-06 00:57:11 +03:00
parent bddcc97392
commit a24697256d
No known key found for this signature in database
GPG Key ID: 904EF10755E7C016
6 changed files with 57 additions and 25 deletions

View File

@ -242,9 +242,10 @@ public class Settings extends BaseSettings {
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
public static final LongSetting SWIPE_OVERLAY_TIMEOUT = new LongSetting("revanced_swipe_overlay_timeout", 500L, true,
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
public static final BooleanSetting SWIPE_SAVE_AND_RESTORE_BRIGHTNESS = new BooleanSetting("revanced_swipe_save_and_restore_brightness", TRUE, true,
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
public static final BooleanSetting SWIPE_SAVE_AND_RESTORE_BRIGHTNESS = new BooleanSetting("revanced_swipe_save_and_restore_brightness", TRUE, true, parent(SWIPE_BRIGHTNESS));
public static final BooleanSetting SWIPE_ENABLE_AUTO_BRIGHTNESS = new BooleanSetting("revanced_swipe_enable_auto_brightness", TRUE, true, parent(SWIPE_BRIGHTNESS));
public static final FloatSetting SWIPE_BRIGHTNESS_VALUE = new FloatSetting("revanced_swipe_brightness_value", 0.5f);
public static final BooleanSetting SWIPE_BRIGHTNESS_AUTO_STATE = new BooleanSetting("revanced_swipe_brightness_auto_state", TRUE);
// Debugging
/**
* When enabled, share the debug logs with care.

View File

@ -104,5 +104,10 @@ class SwipeControlsConfigurationProvider(
val shouldSaveAndRestoreBrightness: Boolean
get() = Settings.SWIPE_SAVE_AND_RESTORE_BRIGHTNESS.get()
/**
* should the auto-brightness be enabled at the lowest value of the brightness gesture
*/
val shouldEnableAutoBrightness: Boolean
get() = Settings.SWIPE_ENABLE_AUTO_BRIGHTNESS.get()
//endregion
}
}

View File

@ -173,6 +173,15 @@ class SwipeControlsHostActivity : Activity() {
*/
private fun onPlayerTypeChanged(type: PlayerType) {
if (config.shouldSaveAndRestoreBrightness) {
when (type) {
PlayerType.WATCH_WHILE_FULLSCREEN -> screen?.restore()
else -> {
screen?.restore()
screen?.save()
screen?.restoreDefaultBrightness()
}
}
} else {
when (type) {
PlayerType.WATCH_WHILE_FULLSCREEN -> screen?.restore()
else -> {
@ -222,4 +231,4 @@ class SwipeControlsHostActivity : Activity() {
var currentHost: WeakReference<SwipeControlsHostActivity> = WeakReference(null)
private set
}
}
}

View File

@ -2,6 +2,7 @@ package app.revanced.integrations.youtube.swipecontrols.controller
import android.app.Activity
import android.view.WindowManager
import app.revanced.integrations.youtube.settings.Settings
import app.revanced.integrations.youtube.swipecontrols.misc.clamp
/**
@ -12,10 +13,6 @@ import app.revanced.integrations.youtube.swipecontrols.misc.clamp
class ScreenBrightnessController(
private val host: Activity,
) {
/**
* screen brightness saved by [save]
*/
private var savedScreenBrightness: Float? = null
/**
* the current screen brightness in percent, ranging from 0.0 to 100.0
@ -43,19 +40,15 @@ class ScreenBrightnessController(
* save the current screen brightness, to be brought back using [restore]
*/
fun save() {
if (savedScreenBrightness == null) {
savedScreenBrightness = rawScreenBrightness
}
Settings.SWIPE_BRIGHTNESS_VALUE.save(rawScreenBrightness)
}
/**
* restore the screen brightness saved using [save]
*/
fun restore() {
savedScreenBrightness?.let {
rawScreenBrightness = it
}
savedScreenBrightness = null
if (!Settings.SWIPE_BRIGHTNESS_AUTO_STATE.get())
rawScreenBrightness = Settings.SWIPE_BRIGHTNESS_VALUE.get()
}
/**
@ -68,4 +61,4 @@ class ScreenBrightnessController(
attr.screenBrightness = value
host.window.attributes = attr
}
}
}

View File

@ -2,6 +2,8 @@ package app.revanced.integrations.youtube.swipecontrols.controller.gesture.core
import android.content.Context
import android.util.TypedValue
import app.revanced.integrations.youtube.settings.Settings
import app.revanced.integrations.youtube.swipecontrols.SwipeControlsConfigurationProvider
import app.revanced.integrations.youtube.swipecontrols.controller.AudioVolumeController
import app.revanced.integrations.youtube.swipecontrols.controller.ScreenBrightnessController
import app.revanced.integrations.youtube.swipecontrols.misc.ScrollDistanceHelper
@ -77,10 +79,22 @@ class VolumeAndBrightnessScrollerImpl(
),
) { _, _, direction ->
screenController?.run {
if (screenBrightness > 0 || direction > 0) {
screenBrightness += direction
if (!Settings.SWIPE_ENABLE_AUTO_BRIGHTNESS.get()){
if (screenBrightness >= 0 || direction > 0) {
restore()
screenBrightness += direction
save()
} else {
restoreDefaultBrightness()
}
} else {
restoreDefaultBrightness()
if (screenBrightness > 0 || direction > 0) {
restore()
screenBrightness += direction
save()
} else {
restoreDefaultBrightness()
}
}
overlayController.onBrightnessChanged(screenBrightness)
@ -94,4 +108,4 @@ class VolumeAndBrightnessScrollerImpl(
volumeScroller.reset()
brightnessScroller.reset()
}
}
}

View File

@ -11,7 +11,9 @@ import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import android.widget.TextView
import app.revanced.integrations.shared.StringRef.str
import app.revanced.integrations.shared.Utils
import app.revanced.integrations.youtube.settings.Settings
import app.revanced.integrations.youtube.swipecontrols.SwipeControlsConfigurationProvider
import app.revanced.integrations.youtube.swipecontrols.misc.SwipeControlsOverlay
import app.revanced.integrations.youtube.swipecontrols.misc.applyDimension
@ -122,10 +124,18 @@ class SwipeControlsOverlayLayout(
}
override fun onBrightnessChanged(brightness: Double) {
if (brightness > 0) {
showFeedbackView("${round(brightness).toInt()}%", manualBrightnessIcon)
Settings.SWIPE_BRIGHTNESS_AUTO_STATE.save(false)
if (config.shouldEnableAutoBrightness) {
if (brightness > 0) {
showFeedbackView("${round(brightness).toInt()}%", manualBrightnessIcon)
} else {
showFeedbackView(str("revanced_swipe_enable_auto_brightness_overlay_text"), autoBrightnessIcon)
Settings.SWIPE_BRIGHTNESS_AUTO_STATE.save(true)
}
} else {
showFeedbackView("AUTO", autoBrightnessIcon)
if (brightness >= 0) {
showFeedbackView("${round(brightness).toInt()}%", manualBrightnessIcon)
}
}
}
@ -138,4 +148,4 @@ class SwipeControlsOverlayLayout(
)
}
}
}
}