From cef6012d8ad5f8dcb8820c133598b9ed311db147 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sun, 21 Apr 2024 01:47:16 +0200 Subject: [PATCH] refactor --- .../integrations/youtube/settings/Settings.java | 2 +- .../SwipeControlsConfigurationProvider.kt | 8 ++++---- .../controller/ScreenBrightnessController.kt | 14 ++++++-------- .../gesture/core/VolumeAndBrightnessScroller.kt | 4 ++-- .../views/SwipeControlsOverlayLayout.kt | 8 ++++---- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java b/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java index eb933b12..b74098c7 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java +++ b/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java @@ -251,7 +251,7 @@ public class Settings extends BaseSettings { 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 FloatSetting SWIPE_BRIGHTNESS_VALUE = new FloatSetting("revanced_swipe_brightness_value", -1f); - public static final BooleanSetting SWIPE_ENABLE_LOWEST_VALUE_AUTO_BRIGHTNESS = new BooleanSetting("revanced_swipe_enable_lowest_value_auto_brightness", TRUE, true, parent(SWIPE_BRIGHTNESS)); + 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 /** * When enabled, share the debug logs with care. diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/SwipeControlsConfigurationProvider.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/SwipeControlsConfigurationProvider.kt index 3e956125..893ccd57 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/SwipeControlsConfigurationProvider.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/SwipeControlsConfigurationProvider.kt @@ -105,10 +105,10 @@ class SwipeControlsConfigurationProvider( get() = Settings.SWIPE_SAVE_AND_RESTORE_BRIGHTNESS.get() /** - * should the auto-brightness be enabled at the lowest value of the brightness gesture + * should auto-brightness be enabled at the lowest value of the brightness gesture */ - val shouldEnableLowestValueAutoBrightness: Boolean - get() = Settings.SWIPE_ENABLE_LOWEST_VALUE_AUTO_BRIGHTNESS.get() + val shouldLowestValueEnableAutoBrightness: Boolean + get() = Settings.SWIPE_LOWEST_VALUE_ENABLE_AUTO_BRIGHTNESS.get() /** * variable that stores the brightness gesture value in the settings @@ -117,4 +117,4 @@ class SwipeControlsConfigurationProvider( get() = Settings.SWIPE_BRIGHTNESS_VALUE.get() set(value) = Settings.SWIPE_BRIGHTNESS_VALUE.save(value) //endregion -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/ScreenBrightnessController.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/ScreenBrightnessController.kt index e1b4fcc6..08e27004 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/ScreenBrightnessController.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/ScreenBrightnessController.kt @@ -1,18 +1,16 @@ package app.revanced.integrations.youtube.swipecontrols.controller -import android.app.Activity import android.view.WindowManager -import app.revanced.integrations.youtube.swipecontrols.SwipeControlsConfigurationProvider +import app.revanced.integrations.youtube.swipecontrols.SwipeControlsHostActivity import app.revanced.integrations.youtube.swipecontrols.misc.clamp /** * 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( - private val host: Activity, - val config: SwipeControlsConfigurationProvider = SwipeControlsConfigurationProvider(host), + val host: SwipeControlsHostActivity, ) { /** @@ -46,7 +44,7 @@ class ScreenBrightnessController( fun save() { if (isBrightnessRestored) { // Saves the current screen brightness value into settings - config.savedScreenBrightnessValue = rawScreenBrightness + host.config.savedScreenBrightnessValue = rawScreenBrightness // Reset the flag isBrightnessRestored = false } @@ -57,7 +55,7 @@ class ScreenBrightnessController( */ fun restore() { // Restores the screen brightness value from the saved settings - rawScreenBrightness = config.savedScreenBrightnessValue + rawScreenBrightness = host.config.savedScreenBrightnessValue // Mark that brightness has been restored isBrightnessRestored = true } @@ -72,4 +70,4 @@ class ScreenBrightnessController( attr.screenBrightness = value host.window.attributes = attr } -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/core/VolumeAndBrightnessScroller.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/core/VolumeAndBrightnessScroller.kt index c648e831..f15478ec 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/core/VolumeAndBrightnessScroller.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/controller/gesture/core/VolumeAndBrightnessScroller.kt @@ -77,7 +77,7 @@ class VolumeAndBrightnessScrollerImpl( ), ) { _, _, direction -> screenController?.run { - val shouldAdjustBrightness = if (config.shouldEnableLowestValueAutoBrightness) { + val shouldAdjustBrightness = if (host.config.shouldLowestValueEnableAutoBrightness) { screenBrightness > 0 || direction > 0 } else { screenBrightness >= 0 || direction >= 0 @@ -99,4 +99,4 @@ class VolumeAndBrightnessScrollerImpl( volumeScroller.reset() brightnessScroller.reset() } -} \ No newline at end of file +} diff --git a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/views/SwipeControlsOverlayLayout.kt b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/views/SwipeControlsOverlayLayout.kt index 6df61c1e..f68fcda1 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/views/SwipeControlsOverlayLayout.kt +++ b/app/src/main/java/app/revanced/integrations/youtube/swipecontrols/views/SwipeControlsOverlayLayout.kt @@ -123,10 +123,10 @@ class SwipeControlsOverlayLayout( } override fun onBrightnessChanged(brightness: Double) { - if (config.shouldEnableLowestValueAutoBrightness && brightness <= 0) { + if (config.shouldLowestValueEnableAutoBrightness && brightness <= 0) { showFeedbackView( - str("revanced_swipe_enable_lowest_value_auto_brightness_overlay_text"), - autoBrightnessIcon + str("revanced_swipe_lowest_value_enable_auto_brightness_overlay_text"), + autoBrightnessIcon, ) } else if (brightness >= 0) { showFeedbackView("${round(brightness).toInt()}%", manualBrightnessIcon) @@ -142,4 +142,4 @@ class SwipeControlsOverlayLayout( ) } } -} \ No newline at end of file +}