Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(YouTube - Swipe controls): Save and restore brightness and add auto-brightness toggle #610

Merged
merged 27 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a246972
feat(YouTube - Swipe controls): Remember current brightness at all times
MarcaDian Apr 5, 2024
5026c50
refactor
oSumAtrIX Apr 5, 2024
c3a9e6b
refactor
MarcaDian Apr 6, 2024
46ef6c7
comments and rename vars
MarcaDian Apr 7, 2024
00e396a
do not use var as global setting
MarcaDian Apr 8, 2024
f5ef01d
revert
MarcaDian Apr 8, 2024
cd7fe53
Merge branch 'dev' into feat/save_brightness
MarcaDian Apr 10, 2024
d317b3f
refactoring and optimization
MarcaDian Apr 10, 2024
ffd2acc
Merge remote-tracking branch 'origin/feat/save_brightness' into feat/…
MarcaDian Apr 10, 2024
cf60915
fix
MarcaDian Apr 11, 2024
7dd6a28
possibly fixed
MarcaDian Apr 11, 2024
2a1916b
I'm already sick of this shitty code 🙃
MarcaDian Apr 11, 2024
765ec07
some fix
MarcaDian Apr 12, 2024
48e734f
some fix
MarcaDian Apr 12, 2024
03802cc
Merge remote-tracking branch 'origin/feat/save_brightness' into feat/…
MarcaDian Apr 12, 2024
7aa3d1e
del unused import
MarcaDian Apr 12, 2024
48ae621
i think this is final
MarcaDian Apr 12, 2024
25d00af
lost a comment
MarcaDian Apr 12, 2024
80e0bbb
Merge remote-tracking branch 'upstream/dev' into feat/save_brightness
MarcaDian Apr 13, 2024
3a81731
Merge remote-tracking branch 'upstream/dev' into feat/save_brightness
MarcaDian Apr 16, 2024
44cd133
refactor
MarcaDian Apr 16, 2024
6ccdc70
Merge remote-tracking branch 'upstream/dev' into feat/save_brightness
MarcaDian Apr 17, 2024
84a39b6
Merge remote-tracking branch 'upstream/dev' into feat/save_brightness
MarcaDian Apr 18, 2024
7794c5c
Merge remote-tracking branch 'upstream/dev' into feat/save_brightness
MarcaDian Apr 18, 2024
1fbbfd9
Merge remote-tracking branch 'upstream/dev' into feat/save_brightness
MarcaDian Apr 20, 2024
7c0b506
refactor
MarcaDian Apr 20, 2024
cef6012
refactor
oSumAtrIX Apr 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ 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 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));
// Debugging
/**
* When enabled, share the debug logs with care.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,17 @@ 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 shouldEnableLowestValueAutoBrightness: Boolean
get() = Settings.SWIPE_ENABLE_LOWEST_VALUE_AUTO_BRIGHTNESS.get()

/**
* variable that stores the brightness gesture value
*/
var savedScreenBrightnessValue: Float
get() = Settings.SWIPE_BRIGHTNESS_VALUE.get()
set(value) = Settings.SWIPE_BRIGHTNESS_VALUE.save(value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, this can be simplified by adding get set operators and delegating getter setter properties, not a matter of this PR though.

//endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ class SwipeControlsHostActivity : Activity() {
screen?.restoreDefaultBrightness()
}
}
} else {
screen?.restoreDefaultBrightness() // here was lost the function of restore the default brightness
}
}

Expand All @@ -198,7 +200,7 @@ class SwipeControlsHostActivity : Activity() {
*/
private fun createScreenController() =
if (config.enableBrightnessControl) {
ScreenBrightnessController(this)
ScreenBrightnessController(this, config)
MarcaDian marked this conversation as resolved.
Show resolved Hide resolved
} else {
null
}
Expand All @@ -222,4 +224,4 @@ class SwipeControlsHostActivity : Activity() {
var currentHost: WeakReference<SwipeControlsHostActivity> = WeakReference(null)
private set
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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.misc.clamp

/**
Expand All @@ -11,11 +12,8 @@ import app.revanced.integrations.youtube.swipecontrols.misc.clamp
*/
class ScreenBrightnessController(
private val host: Activity,
val config: SwipeControlsConfigurationProvider,
) {
/**
* screen brightness saved by [save]
*/
private var savedScreenBrightness: Float? = null

/**
* the current screen brightness in percent, ranging from 0.0 to 100.0
Expand All @@ -40,22 +38,20 @@ 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() {
if (savedScreenBrightness == null) {
savedScreenBrightness = rawScreenBrightness
if (config.savedScreenBrightnessValue == -1f) {
config.savedScreenBrightnessValue = rawScreenBrightness
}
}

/**
* restore the screen brightness saved using [save]
* restore the screen brightness from settings saved using [save]
*/
fun restore() {
savedScreenBrightness?.let {
rawScreenBrightness = it
}
savedScreenBrightness = null
rawScreenBrightness = config.savedScreenBrightnessValue
config.savedScreenBrightnessValue = -1f
}

/**
Expand All @@ -68,4 +64,4 @@ class ScreenBrightnessController(
attr.screenBrightness = value
host.window.attributes = attr
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,17 @@ class VolumeAndBrightnessScrollerImpl(
),
) { _, _, direction ->
screenController?.run {
if (screenBrightness > 0 || direction > 0) {
val shouldAdjustBrightness = if (config.shouldEnableLowestValueAutoBrightness) {
screenBrightness > 0 || direction > 0
} else {
screenBrightness >= 0 || direction >= 0
}

if (shouldAdjustBrightness) {
screenBrightness += direction
} else {
restoreDefaultBrightness()
}

overlayController.onBrightnessChanged(screenBrightness)
}
}
Expand All @@ -94,4 +99,4 @@ class VolumeAndBrightnessScrollerImpl(
volumeScroller.reset()
brightnessScroller.reset()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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.swipecontrols.SwipeControlsConfigurationProvider
import app.revanced.integrations.youtube.swipecontrols.misc.SwipeControlsOverlay
Expand Down Expand Up @@ -122,10 +123,13 @@ class SwipeControlsOverlayLayout(
}

override fun onBrightnessChanged(brightness: Double) {
if (brightness > 0) {
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)
} else {
showFeedbackView("AUTO", autoBrightnessIcon)
}
}

Expand All @@ -138,4 +142,4 @@ class SwipeControlsOverlayLayout(
)
}
}
}
}
Loading