mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-06-02 11:26:18 +02:00
refactor
moved vars to SwipeControlsConfigurationProvider
This commit is contained in:
parent
5026c50a67
commit
c3a9e6b84f
|
@ -243,7 +243,7 @@ public class Settings extends BaseSettings {
|
|||
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, 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 BooleanSetting SWIPE_ENABLE_LOWEST_VALUE_AUTO_BRIGHTNESS = new BooleanSetting("revanced_swipe_enable_lowest_value_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
|
||||
|
|
|
@ -107,7 +107,22 @@ class SwipeControlsConfigurationProvider(
|
|||
/**
|
||||
* should the auto-brightness be enabled at the lowest value of the brightness gesture
|
||||
*/
|
||||
val shouldEnableAutoBrightness: Boolean
|
||||
get() = Settings.SWIPE_ENABLE_AUTO_BRIGHTNESS.get()
|
||||
val shouldEnableLowestValueAutoBrightness: Boolean
|
||||
get() = Settings.SWIPE_ENABLE_LOWEST_VALUE_AUTO_BRIGHTNESS.get()
|
||||
|
||||
/**
|
||||
* variable that stores the brightness gesture value
|
||||
*/
|
||||
var brightnessValue: Float
|
||||
get() = Settings.SWIPE_BRIGHTNESS_VALUE.get()
|
||||
set(value) = Settings.SWIPE_BRIGHTNESS_VALUE.save(value)
|
||||
|
||||
/**
|
||||
* variable that stores the auto-brightness state, which used in restore brightness function
|
||||
* it needed for that the brightness is not saved if auto-brightness is enabled
|
||||
*/
|
||||
var isEnableAutoBrightness: Boolean
|
||||
get() = Settings.SWIPE_BRIGHTNESS_AUTO_STATE.get()
|
||||
set(value) = Settings.SWIPE_BRIGHTNESS_AUTO_STATE.save(value)
|
||||
//endregion
|
||||
}
|
|
@ -207,7 +207,7 @@ class SwipeControlsHostActivity : Activity() {
|
|||
*/
|
||||
private fun createScreenController() =
|
||||
if (config.enableBrightnessControl) {
|
||||
ScreenBrightnessController(this)
|
||||
ScreenBrightnessController(this, config)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
|
|
@ -2,7 +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.SwipeControlsConfigurationProvider
|
||||
import app.revanced.integrations.youtube.swipecontrols.misc.clamp
|
||||
|
||||
/**
|
||||
|
@ -12,6 +12,7 @@ import app.revanced.integrations.youtube.swipecontrols.misc.clamp
|
|||
*/
|
||||
class ScreenBrightnessController(
|
||||
private val host: Activity,
|
||||
val config: SwipeControlsConfigurationProvider,
|
||||
) {
|
||||
|
||||
/**
|
||||
|
@ -37,18 +38,18 @@ class ScreenBrightnessController(
|
|||
get() = (rawScreenBrightness == WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE)
|
||||
|
||||
/**
|
||||
* save the current screen brightness, to be brought back using [restore]
|
||||
* save the current screen brightness into settings, to be brought back using [restore]
|
||||
*/
|
||||
fun save() {
|
||||
Settings.SWIPE_BRIGHTNESS_VALUE.save(rawScreenBrightness)
|
||||
config.brightnessValue = rawScreenBrightness
|
||||
}
|
||||
|
||||
/**
|
||||
* restore the screen brightness saved using [save]
|
||||
* restore the screen brightness from settings saved using [save]
|
||||
*/
|
||||
fun restore() {
|
||||
if (!Settings.SWIPE_BRIGHTNESS_AUTO_STATE.get())
|
||||
rawScreenBrightness = Settings.SWIPE_BRIGHTNESS_VALUE.get()
|
||||
if (!config.isEnableAutoBrightness)
|
||||
rawScreenBrightness = config.brightnessValue
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,8 +2,6 @@ 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
|
||||
|
@ -79,7 +77,7 @@ class VolumeAndBrightnessScrollerImpl(
|
|||
),
|
||||
) { _, _, direction ->
|
||||
screenController?.run {
|
||||
if (!Settings.SWIPE_ENABLE_AUTO_BRIGHTNESS.get()){
|
||||
if (!config.shouldEnableLowestValueAutoBrightness){
|
||||
if (screenBrightness >= 0 || direction > 0) {
|
||||
restore()
|
||||
screenBrightness += direction
|
||||
|
|
|
@ -13,7 +13,6 @@ 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
|
||||
|
@ -124,14 +123,18 @@ class SwipeControlsOverlayLayout(
|
|||
}
|
||||
|
||||
override fun onBrightnessChanged(brightness: Double) {
|
||||
val useAutoBrightness = config.shouldEnableAutoBrightness && brightness == 0.0
|
||||
|
||||
Settings.SWIPE_BRIGHTNESS_AUTO_STATE.save(useAutoBrightness)
|
||||
|
||||
if (useAutoBrightness) {
|
||||
showFeedbackView(str("revanced_swipe_enable_auto_brightness_overlay_text"), autoBrightnessIcon)
|
||||
config.isEnableAutoBrightness = false
|
||||
if (config.shouldEnableLowestValueAutoBrightness) {
|
||||
if (brightness > 0) {
|
||||
showFeedbackView("${round(brightness).toInt()}%", manualBrightnessIcon)
|
||||
} else {
|
||||
showFeedbackView(str("revanced_swipe_enable_lowest_value_auto_brightness_overlay_text"), autoBrightnessIcon)
|
||||
config.isEnableAutoBrightness = true
|
||||
}
|
||||
} else {
|
||||
showFeedbackView("${round(brightness).toInt()}%", manualBrightnessIcon)
|
||||
if (brightness >= 0) {
|
||||
showFeedbackView("${round(brightness).toInt()}%", manualBrightnessIcon)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,4 +147,4 @@ class SwipeControlsOverlayLayout(
|
|||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user