1
1
package app.revanced.extension.youtube.swipecontrols
2
2
3
+ import android.annotation.SuppressLint
3
4
import android.graphics.Color
5
+ import app.revanced.extension.shared.Logger
4
6
import app.revanced.extension.shared.StringRef.str
5
7
import app.revanced.extension.shared.Utils
6
8
import app.revanced.extension.youtube.settings.Settings
7
9
import app.revanced.extension.youtube.shared.PlayerType
8
10
9
11
/* *
10
- * provider for configuration for volume and brightness swipe controls
12
+ * Provides configuration settings for volume and brightness swipe controls in the YouTube player.
13
+ * Manages enabling/disabling gestures, overlay appearance, and behavior preferences.
11
14
*/
12
15
class SwipeControlsConfigurationProvider {
13
- // region swipe enable
16
+ // region swipe enable
14
17
/* *
15
- * should swipe controls be enabled? (global setting)
18
+ * Indicates whether swipe controls are enabled globally.
19
+ * Returns true if either volume or brightness controls are enabled and the video is in fullscreen mode.
16
20
*/
17
21
val enableSwipeControls: Boolean
18
22
get() = (enableVolumeControls || enableBrightnessControl) && isFullscreenVideo
19
23
20
24
/* *
21
- * should swipe controls for volume be enabled?
25
+ * Indicates whether swipe controls for adjusting volume are enabled.
22
26
*/
23
27
val enableVolumeControls = Settings .SWIPE_VOLUME .get()
24
28
25
29
/* *
26
- * should swipe controls for volume be enabled?
30
+ * Indicates whether swipe controls for adjusting brightness are enabled.
27
31
*/
28
32
val enableBrightnessControl = Settings .SWIPE_BRIGHTNESS .get()
29
33
30
34
/* *
31
- * is the video player currently in fullscreen mode?
35
+ * Checks if the video player is currently in fullscreen mode.
32
36
*/
33
37
private val isFullscreenVideo: Boolean
34
38
get() = PlayerType .current == PlayerType .WATCH_WHILE_FULLSCREEN
35
- // endregion
39
+ // endregion
36
40
37
- // region keys enable
41
+ // region keys enable
38
42
/* *
39
- * should volume key controls be overwritten? (global setting)
43
+ * Indicates whether volume key controls should be overridden by swipe controls.
44
+ * Returns true if volume controls are enabled and the video is in fullscreen mode.
40
45
*/
41
46
val overwriteVolumeKeyControls: Boolean
42
47
get() = enableVolumeControls && isFullscreenVideo
43
- // endregion
48
+ // endregion
44
49
45
- // region gesture adjustments
50
+ // region gesture adjustments
46
51
/* *
47
- * should press-to-swipe be enabled?
52
+ * Indicates whether press-to-swipe mode is enabled, requiring a press before swiping to activate controls.
48
53
*/
49
54
val shouldEnablePressToSwipe: Boolean
50
55
get() = Settings .SWIPE_PRESS_TO_ENGAGE .get()
51
56
52
57
/* *
53
- * threshold for swipe detection
54
- * this may be called rapidly in onScroll, so we have to load it once and then leave it constant
58
+ * The threshold for detecting swipe gestures, in pixels.
59
+ * Loaded once to ensure consistent behavior during rapid scroll events.
55
60
*/
56
61
val swipeMagnitudeThreshold: Int
57
62
get() = Settings .SWIPE_MAGNITUDE_THRESHOLD .get()
58
63
59
64
/* *
60
- * How much volume will change by single swipe.
61
- * If it is set to 0, it will reset to the default value because 0 would disable swiping.
62
- * * /
65
+ * The sensitivity of volume swipe gestures, determining how much volume changes per swipe.
66
+ * Resets to default if set to 0, as it would disable swiping.
67
+ */
63
68
val volumeSwipeSensitivity: Int
64
69
get() {
65
70
val sensitivity = Settings .SWIPE_VOLUME_SENSITIVITY .get()
66
71
67
72
if (sensitivity < 1 ) {
68
- Settings .SWIPE_VOLUME_SENSITIVITY .resetToDefault()
69
-
70
- return Settings .SWIPE_VOLUME_SENSITIVITY .get()
73
+ return Settings .SWIPE_VOLUME_SENSITIVITY .resetToDefault()
71
74
}
72
75
73
76
return sensitivity
74
77
}
75
- // endregion
78
+ // endregion
76
79
77
- // region overlay adjustments
80
+ // region overlay adjustments
78
81
/* *
79
- * should the overlay enable haptic feedback?
82
+ * Indicates whether haptic feedback should be enabled for swipe control interactions.
80
83
*/
81
84
val shouldEnableHapticFeedback: Boolean
82
85
get() = Settings .SWIPE_HAPTIC_FEEDBACK .get()
83
86
84
87
/* *
85
- * how long the overlay should be shown on changes
88
+ * The duration in milliseconds that the overlay should remain visible after a change.
86
89
*/
87
90
val overlayShowTimeoutMillis: Long
88
91
get() = Settings .SWIPE_OVERLAY_TIMEOUT .get()
89
92
90
93
/* *
91
- * Gets the opacity value (0-100%) is converted to an alpha value (0-255) for transparency .
92
- * If the opacity value is out of range, it resets to the default and displays a warning message .
94
+ * The background opacity of the overlay, converted from a percentage (0-100) to an alpha value (0-255).
95
+ * Resets to default and shows a toast if the value is out of range .
93
96
*/
94
97
val overlayBackgroundOpacity: Int
95
98
get() {
96
99
var opacity = Settings .SWIPE_OVERLAY_OPACITY .get()
97
100
98
101
if (opacity < 0 || opacity > 100 ) {
99
102
Utils .showToastLong(str(" revanced_swipe_overlay_background_opacity_invalid_toast" ))
100
- Settings .SWIPE_OVERLAY_OPACITY .resetToDefault()
101
- opacity = Settings .SWIPE_OVERLAY_OPACITY .get()
103
+ opacity = Settings .SWIPE_OVERLAY_OPACITY .resetToDefault()
102
104
}
103
105
104
106
opacity = opacity * 255 / 100
105
107
return Color .argb(opacity, 0 , 0 , 0 )
106
108
}
107
109
108
110
/* *
109
- * The color of the progress overlay.
111
+ * The color of the progress bar in the overlay.
112
+ * Resets to default and shows a toast if the color string is invalid or empty.
110
113
*/
111
114
val overlayProgressColor: Int
112
- get() = 0xBFFFFFFF .toInt()
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
+ }
126
+ }
113
127
114
128
/* *
115
- * The color used for the background of the progress overlay fill .
129
+ * The background color used for the filled portion of the progress bar in the overlay .
116
130
*/
117
131
val overlayFillBackgroundPaint: Int
118
132
get() = 0x80D3D3D3 .toInt()
119
133
120
134
/* *
121
- * The color used for the text and icons in the overlay.
135
+ * The color used for text and icons in the overlay.
122
136
*/
123
137
val overlayTextColor: Int
124
138
get() = Color .WHITE
125
139
126
140
/* *
127
- * A flag that determines if the overlay should only show the icon.
141
+ * The text size in the overlay, in density-independent pixels (dp).
142
+ * Must be between 1 and 30 dp; resets to default and shows a toast if invalid.
128
143
*/
129
- val overlayShowOverlayMinimalStyle: Boolean
130
- get() = Settings .SWIPE_OVERLAY_MINIMAL_STYLE .get()
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
+ }
131
153
132
154
/* *
133
- * A flag that determines if the progress bar should be circular.
155
+ * Defines the style of the swipe controls overlay, determining its layout and appearance.
156
+ *
157
+ * @property isMinimal Indicates whether the style is minimalistic, omitting detailed progress indicators.
158
+ * @property isHorizontalMinimalCenter Indicates whether the style is a minimal horizontal bar centered vertically.
159
+ * @property isCircular Indicates whether the style uses a circular progress bar.
160
+ * @property isVertical Indicates whether the style uses a vertical progress bar.
134
161
*/
135
- val isCircularProgressBar: Boolean
136
- get() = Settings .SWIPE_SHOW_CIRCULAR_OVERLAY .get()
137
- // endregion
162
+ @Suppress(" unused" )
163
+ enum class SwipeOverlayStyle (
164
+ val isMinimal : Boolean = false ,
165
+ val isHorizontalMinimalCenter : Boolean = false ,
166
+ val isCircular : Boolean = false ,
167
+ val isVertical : Boolean = false
168
+ ) {
169
+ /* *
170
+ * A full horizontal progress bar with detailed indicators.
171
+ */
172
+ HORIZONTAL ,
138
173
139
- // region behaviour
174
+ /* *
175
+ * A minimal horizontal progress bar positioned at the top.
176
+ */
177
+ HORIZONTAL_MINIMAL_TOP (isMinimal = true ),
178
+
179
+ /* *
180
+ * A minimal horizontal progress bar centered vertically.
181
+ */
182
+ HORIZONTAL_MINIMAL_CENTER (isMinimal = true , isHorizontalMinimalCenter = true ),
183
+
184
+ /* *
185
+ * A full circular progress bar with detailed indicators.
186
+ */
187
+ CIRCULAR (isCircular = true ),
188
+
189
+ /* *
190
+ * A minimal circular progress bar.
191
+ */
192
+ CIRCULAR_MINIMAL (isMinimal = true , isCircular = true ),
193
+
194
+ /* *
195
+ * A full vertical progress bar with detailed indicators.
196
+ */
197
+ VERTICAL (isVertical = true ),
198
+
199
+ /* *
200
+ * A minimal vertical progress bar.
201
+ */
202
+ VERTICAL_MINIMAL (isMinimal = true , isVertical = true )
203
+ }
204
+
205
+ /* *
206
+ * The current style of the overlay, determining its layout and appearance.
207
+ */
208
+ val overlayStyle: SwipeOverlayStyle
209
+ get() = Settings .SWIPE_OVERLAY_STYLE .get()
210
+ // endregion
140
211
212
+ // region behaviour
141
213
/* *
142
- * should the brightness be saved and restored when exiting or entering fullscreen
214
+ * Indicates whether the brightness level should be saved and restored when entering or exiting fullscreen mode.
143
215
*/
144
216
val shouldSaveAndRestoreBrightness: Boolean
145
217
get() = Settings .SWIPE_SAVE_AND_RESTORE_BRIGHTNESS .get()
146
218
147
219
/* *
148
- * should auto-brightness be enabled at the lowest value of the brightness gesture
220
+ * Indicates whether auto-brightness should be enabled when the brightness gesture reaches its lowest value.
149
221
*/
150
222
val shouldLowestValueEnableAutoBrightness: Boolean
151
223
get() = Settings .SWIPE_LOWEST_VALUE_ENABLE_AUTO_BRIGHTNESS .get()
152
224
153
225
/* *
154
- * variable that stores the brightness gesture value in the settings
226
+ * The saved brightness value for the swipe gesture, used to restore brightness in fullscreen mode.
155
227
*/
156
228
var savedScreenBrightnessValue: Float
157
229
get() = Settings .SWIPE_BRIGHTNESS_VALUE .get()
158
230
set(value) = Settings .SWIPE_BRIGHTNESS_VALUE .save(value)
159
- // endregion
160
- }
231
+ // endregion
232
+ }
0 commit comments