mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-06-02 11:26:18 +02:00
refactoring and optimization
This commit is contained in:
parent
f5ef01d363
commit
d317b3f3f3
|
@ -245,7 +245,6 @@ public class Settings extends BaseSettings {
|
|||
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", 0.5f);
|
||||
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_AUTO_BRIGHTNESS_STATE = new BooleanSetting("revanced_swipe_auto_brightness_state", TRUE);
|
||||
// Debugging
|
||||
/**
|
||||
* When enabled, share the debug logs with care.
|
||||
|
|
|
@ -116,14 +116,5 @@ class SwipeControlsConfigurationProvider(
|
|||
var savedScreenBrightnessValue: 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 restored if auto-brightness is enabled
|
||||
* if used as "non-setting" var brightness don`t restored after closing app
|
||||
*/
|
||||
var isEnabledAutoBrightness: Boolean
|
||||
get() = Settings.SWIPE_AUTO_BRIGHTNESS_STATE.get()
|
||||
set(value) = Settings.SWIPE_AUTO_BRIGHTNESS_STATE.save(value)
|
||||
//endregion
|
||||
}
|
|
@ -176,19 +176,12 @@ class SwipeControlsHostActivity : Activity() {
|
|||
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 -> {
|
||||
screen?.save()
|
||||
screen?.restoreDefaultBrightness()
|
||||
}
|
||||
}
|
||||
screen?.restoreDefaultBrightness() // here was lost the function of restore the default brightness
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,15 +41,19 @@ class ScreenBrightnessController(
|
|||
* save the current screen brightness into settings, to be brought back using [restore]
|
||||
*/
|
||||
fun save() {
|
||||
config.savedScreenBrightnessValue = rawScreenBrightness
|
||||
if (config.savedScreenBrightnessValue == -1f) {
|
||||
config.savedScreenBrightnessValue = rawScreenBrightness
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* restore the screen brightness from settings saved using [save]
|
||||
*/
|
||||
fun restore() {
|
||||
if (!config.isEnabledAutoBrightness) // do not restore brightness when auto-brightness is enabled
|
||||
if (config.savedScreenBrightnessValue != -1f) {
|
||||
rawScreenBrightness = config.savedScreenBrightnessValue
|
||||
config.savedScreenBrightnessValue = -1f // Reset the saved brightness value
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -77,24 +77,17 @@ class VolumeAndBrightnessScrollerImpl(
|
|||
),
|
||||
) { _, _, direction ->
|
||||
screenController?.run {
|
||||
if (config.shouldEnableLowestValueAutoBrightness){
|
||||
if (screenBrightness > 0 || direction > 0) {
|
||||
restore()
|
||||
screenBrightness += direction
|
||||
save()
|
||||
} else {
|
||||
restoreDefaultBrightness()
|
||||
}
|
||||
val condition = if (config.shouldEnableLowestValueAutoBrightness) {
|
||||
screenBrightness > 0
|
||||
} else {
|
||||
if (screenBrightness >= 0 || direction > 0) {
|
||||
restore()
|
||||
screenBrightness += direction
|
||||
save()
|
||||
} else {
|
||||
restoreDefaultBrightness()
|
||||
}
|
||||
screenBrightness >= 0
|
||||
}
|
||||
|
||||
if (condition || direction > 0) {
|
||||
screenBrightness += direction
|
||||
} else {
|
||||
restoreDefaultBrightness()
|
||||
}
|
||||
overlayController.onBrightnessChanged(screenBrightness)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,18 +123,13 @@ class SwipeControlsOverlayLayout(
|
|||
}
|
||||
|
||||
override fun onBrightnessChanged(brightness: Double) {
|
||||
config.isEnabledAutoBrightness = 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.isEnabledAutoBrightness = true // needed because saved before brightness restored when auto-brightness is enabled
|
||||
}
|
||||
} else {
|
||||
if (brightness >= 0) {
|
||||
showFeedbackView("${round(brightness).toInt()}%", manualBrightnessIcon)
|
||||
}
|
||||
if (config.shouldEnableLowestValueAutoBrightness && brightness <= 0) {
|
||||
showFeedbackView(
|
||||
str("revanced_swipe_enable_lowest_value_auto_brightness_overlay_text"),
|
||||
autoBrightnessIcon
|
||||
)
|
||||
} else if (brightness >= 0) {
|
||||
showFeedbackView("${round(brightness).toInt()}%", manualBrightnessIcon)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user