refactoring and optimization

This commit is contained in:
MarcaDian 2024-04-10 23:50:25 +03:00
parent f5ef01d363
commit d317b3f3f3
No known key found for this signature in database
GPG Key ID: 904EF10755E7C016
6 changed files with 22 additions and 47 deletions

View File

@ -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.

View File

@ -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
}

View File

@ -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
}
}

View File

@ -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
}
}
/**

View File

@ -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)
}
}

View File

@ -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)
}
}