1
1
package app.revanced.extension.youtube.swipecontrols
2
2
3
- import android.annotation.SuppressLint
4
3
import android.graphics.Color
5
4
import app.revanced.extension.shared.Logger
6
5
import app.revanced.extension.shared.StringRef.str
7
6
import app.revanced.extension.shared.Utils
7
+ import app.revanced.extension.shared.settings.StringSetting
8
8
import app.revanced.extension.youtube.settings.Settings
9
9
import app.revanced.extension.youtube.shared.PlayerType
10
10
@@ -51,105 +51,112 @@ class SwipeControlsConfigurationProvider {
51
51
/* *
52
52
* Indicates whether press-to-swipe mode is enabled, requiring a press before swiping to activate controls.
53
53
*/
54
- val shouldEnablePressToSwipe: Boolean
55
- get() = Settings .SWIPE_PRESS_TO_ENGAGE .get()
54
+ val shouldEnablePressToSwipe = Settings .SWIPE_PRESS_TO_ENGAGE .get()
56
55
57
56
/* *
58
57
* The threshold for detecting swipe gestures, in pixels.
59
58
* Loaded once to ensure consistent behavior during rapid scroll events.
60
59
*/
61
- val swipeMagnitudeThreshold: Int
62
- get() = Settings .SWIPE_MAGNITUDE_THRESHOLD .get()
60
+ val swipeMagnitudeThreshold = Settings .SWIPE_MAGNITUDE_THRESHOLD .get()
63
61
64
62
/* *
65
63
* The sensitivity of volume swipe gestures, determining how much volume changes per swipe.
66
64
* Resets to default if set to 0, as it would disable swiping.
67
65
*/
68
- val volumeSwipeSensitivity: Int
69
- get() {
70
- val sensitivity = Settings .SWIPE_VOLUME_SENSITIVITY .get()
66
+ val volumeSwipeSensitivity: Int by lazy {
67
+ val sensitivity = Settings .SWIPE_VOLUME_SENSITIVITY .get()
71
68
72
- if (sensitivity < 1 ) {
73
- return Settings .SWIPE_VOLUME_SENSITIVITY .resetToDefault()
74
- }
75
-
76
- return sensitivity
69
+ if (sensitivity < 1 ) {
70
+ return @lazy Settings .SWIPE_VOLUME_SENSITIVITY .resetToDefault()
77
71
}
72
+
73
+ sensitivity
74
+ }
78
75
// endregion
79
76
80
77
// region overlay adjustments
81
78
/* *
82
79
* Indicates whether haptic feedback should be enabled for swipe control interactions.
83
80
*/
84
- val shouldEnableHapticFeedback: Boolean
85
- get() = Settings .SWIPE_HAPTIC_FEEDBACK .get()
81
+ val shouldEnableHapticFeedback = Settings .SWIPE_HAPTIC_FEEDBACK .get()
86
82
87
83
/* *
88
84
* The duration in milliseconds that the overlay should remain visible after a change.
89
85
*/
90
- val overlayShowTimeoutMillis: Long
91
- get() = Settings .SWIPE_OVERLAY_TIMEOUT .get()
86
+ val overlayShowTimeoutMillis = Settings .SWIPE_OVERLAY_TIMEOUT .get()
92
87
93
88
/* *
94
89
* The background opacity of the overlay, converted from a percentage (0-100) to an alpha value (0-255).
95
90
* Resets to default and shows a toast if the value is out of range.
96
91
*/
97
- val overlayBackgroundOpacity: Int
98
- get() {
99
- var opacity = Settings .SWIPE_OVERLAY_OPACITY .get()
100
-
101
- if (opacity < 0 || opacity > 100 ) {
102
- Utils .showToastLong(str(" revanced_swipe_overlay_background_opacity_invalid_toast" ))
103
- opacity = Settings .SWIPE_OVERLAY_OPACITY .resetToDefault()
104
- }
92
+ val overlayBackgroundOpacity: Int by lazy {
93
+ var opacity = Settings .SWIPE_OVERLAY_OPACITY .get()
105
94
106
- opacity = opacity * 255 / 100
107
- return Color .argb(opacity, 0 , 0 , 0 )
95
+ if (opacity < 0 || opacity > 100 ) {
96
+ Utils .showToastLong(str(" revanced_swipe_overlay_background_opacity_invalid_toast" ))
97
+ opacity = Settings .SWIPE_OVERLAY_OPACITY .resetToDefault()
108
98
}
109
99
100
+ opacity = opacity * 255 / 100
101
+ Color .argb(opacity, 0 , 0 , 0 )
102
+ }
103
+
110
104
/* *
111
- * The color of the progress bar in the overlay.
105
+ * The color of the progress bar in the overlay for brightness .
112
106
* Resets to default and shows a toast if the color string is invalid or empty.
113
107
*/
114
- val overlayProgressColor: Int
115
- get() {
116
- try {
117
- @SuppressLint(" UseKtx" )
118
- val color = Color .parseColor(Settings .SWIPE_OVERLAY_PROGRESS_COLOR .get())
119
- return (0xBF000000 .toInt() or (color and 0xFFFFFF ))
120
- } catch (ex: IllegalArgumentException ) {
121
- Logger .printDebug({ " Could not parse color" }, ex)
122
- Utils .showToastLong(str(" revanced_swipe_overlay_progress_color_invalid_toast" ))
123
- Settings .SWIPE_OVERLAY_PROGRESS_COLOR .resetToDefault()
124
- return overlayProgressColor // Recursively return.
125
- }
108
+ val overlayBrightnessProgressColor: Int by lazy {
109
+ // Use lazy to avoid repeat parsing. Changing color requires app restart.
110
+ getSettingColor(Settings .SWIPE_OVERLAY_BRIGHTNESS_COLOR )
111
+ }
112
+
113
+ /* *
114
+ * The color of the progress bar in the overlay for volume.
115
+ * Resets to default and shows a toast if the color string is invalid or empty.
116
+ */
117
+ val overlayVolumeProgressColor: Int by lazy {
118
+ getSettingColor(Settings .SWIPE_OVERLAY_VOLUME_COLOR )
119
+ }
120
+
121
+ private fun getSettingColor (setting : StringSetting ): Int {
122
+ try {
123
+ // noinspection UseKtx
124
+ val color = Color .parseColor(setting.get())
125
+ return (0xBF000000 .toInt() or (color and 0x00FFFFFF ))
126
+ } catch (ex: IllegalArgumentException ) {
127
+ // This code should never be reached.
128
+ // Color picker rejects and will not save bad colors to a setting.
129
+ // If a user imports bad data, the color picker preference resets the
130
+ // bad color before this method can be called.
131
+ Logger .printDebug({ " Could not parse color: $setting " }, ex)
132
+ Utils .showToastLong(str(" revanced_settings_color_invalid" ))
133
+ setting.resetToDefault()
134
+ return getSettingColor(setting) // Recursively return.
126
135
}
136
+ }
127
137
128
138
/* *
129
139
* The background color used for the filled portion of the progress bar in the overlay.
130
140
*/
131
- val overlayFillBackgroundPaint: Int
132
- get() = 0x80D3D3D3 .toInt()
141
+ val overlayFillBackgroundPaint = 0x80D3D3D3 .toInt()
133
142
134
143
/* *
135
144
* The color used for text and icons in the overlay.
136
145
*/
137
- val overlayTextColor: Int
138
- get() = Color .WHITE
146
+ val overlayTextColor = Color .WHITE
139
147
140
148
/* *
141
149
* The text size in the overlay, in density-independent pixels (dp).
142
150
* Must be between 1 and 30 dp; resets to default and shows a toast if invalid.
143
151
*/
144
- val overlayTextSize: Int
145
- get() {
146
- val size = Settings .SWIPE_OVERLAY_TEXT_SIZE .get()
147
- if (size < 1 || size > 30 ) {
148
- Utils .showToastLong(str(" revanced_swipe_text_overlay_size_invalid_toast" ))
149
- return Settings .SWIPE_OVERLAY_TEXT_SIZE .resetToDefault()
150
- }
151
- return size
152
+ val overlayTextSize: Int by lazy {
153
+ val size = Settings .SWIPE_OVERLAY_TEXT_SIZE .get()
154
+ if (size < 1 || size > 30 ) {
155
+ Utils .showToastLong(str(" revanced_swipe_text_overlay_size_invalid_toast" ))
156
+ return @lazy Settings .SWIPE_OVERLAY_TEXT_SIZE .resetToDefault()
152
157
}
158
+ size
159
+ }
153
160
154
161
/* *
155
162
* Defines the style of the swipe controls overlay, determining its layout and appearance.
@@ -199,28 +206,25 @@ class SwipeControlsConfigurationProvider {
199
206
/* *
200
207
* A minimal vertical progress bar.
201
208
*/
202
- VERTICAL_MINIMAL (isMinimal = true , isVertical = true )
209
+ VERTICAL_MINIMAL (isMinimal = true , isVertical = true )
203
210
}
204
211
205
212
/* *
206
213
* The current style of the overlay, determining its layout and appearance.
207
214
*/
208
- val overlayStyle: SwipeOverlayStyle
209
- get() = Settings .SWIPE_OVERLAY_STYLE .get()
215
+ val overlayStyle = Settings .SWIPE_OVERLAY_STYLE .get()
210
216
// endregion
211
217
212
218
// region behaviour
213
219
/* *
214
220
* Indicates whether the brightness level should be saved and restored when entering or exiting fullscreen mode.
215
221
*/
216
- val shouldSaveAndRestoreBrightness: Boolean
217
- get() = Settings .SWIPE_SAVE_AND_RESTORE_BRIGHTNESS .get()
222
+ val shouldSaveAndRestoreBrightness = Settings .SWIPE_SAVE_AND_RESTORE_BRIGHTNESS .get()
218
223
219
224
/* *
220
225
* Indicates whether auto-brightness should be enabled when the brightness gesture reaches its lowest value.
221
226
*/
222
- val shouldLowestValueEnableAutoBrightness: Boolean
223
- get() = Settings .SWIPE_LOWEST_VALUE_ENABLE_AUTO_BRIGHTNESS .get()
227
+ val shouldLowestValueEnableAutoBrightness = Settings .SWIPE_LOWEST_VALUE_ENABLE_AUTO_BRIGHTNESS .get()
224
228
225
229
/* *
226
230
* The saved brightness value for the swipe gesture, used to restore brightness in fullscreen mode.
@@ -229,4 +233,4 @@ class SwipeControlsConfigurationProvider {
229
233
get() = Settings .SWIPE_BRIGHTNESS_VALUE .get()
230
234
set(value) = Settings .SWIPE_BRIGHTNESS_VALUE .save(value)
231
235
// endregion
232
- }
236
+ }
0 commit comments