Skip to content

Commit 6c5aaaa

Browse files
committed
YouTube: Add Swipe controls
1 parent 9bdbbc5 commit 6c5aaaa

39 files changed

+2822
-6
lines changed

app/src/main/java/app/revanced/extension/shared/settings/preference/ColorPickerPreference.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/*
2+
* Custom changes: Keep, lazy load setting
3+
* */
14
package app.revanced.extension.shared.settings.preference;
25

36
import static app.revanced.extension.shared.StringRef.str;
@@ -159,11 +162,6 @@ public ColorPickerPreference(Context context, AttributeSet attrs, int defStyleAt
159162
* Initializes the preference by setting up the EditText, loading the color, and set the widget layout.
160163
*/
161164
private void init() {
162-
colorSetting = (StringSetting) Setting.getSettingFromPath(getKey());
163-
if (colorSetting == null) {
164-
Logger.printException(() -> "Could not find color setting for: " + getKey());
165-
}
166-
167165
EditText editText = getEditText();
168166
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS
169167
| InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
@@ -175,6 +173,17 @@ private void init() {
175173
setWidgetLayoutResource(getResourceIdentifier("revanced_color_dot_widget", "layout"));
176174
}
177175

176+
private StringSetting getColorSettings() {
177+
if (colorSetting != null)
178+
return colorSetting;
179+
180+
colorSetting = (StringSetting) Setting.getSettingFromPath(getKey());
181+
if (colorSetting == null) {
182+
Logger.printException(() -> "Could not find color setting for: " + getKey());
183+
}
184+
return colorSetting;
185+
}
186+
178187
/**
179188
* Sets the selected color and updates the UI and settings.
180189
*
@@ -183,6 +192,7 @@ private void init() {
183192
*/
184193
@Override
185194
public final void setText(String colorString) {
195+
getColorSettings();
186196
try {
187197
Logger.printDebug(() -> "setText: " + colorString);
188198
super.setText(colorString);
@@ -412,7 +422,7 @@ protected void showDialog(Bundle state) {
412422
Button button = dialog.getButton(AlertDialog.BUTTON_NEUTRAL);
413423
button.setOnClickListener(view -> {
414424
try {
415-
final int defaultColor = Color.parseColor(colorSetting.defaultValue) & 0x00FFFFFF;
425+
final int defaultColor = Color.parseColor(getColorSettings().defaultValue) & 0x00FFFFFF;
416426
// Setting view color causes listener callback into this class.
417427
dialogColorPickerView.setColor(defaultColor);
418428
} catch (Exception ex) {

app/src/main/java/app/revanced/extension/shared/settings/preference/ResettableEditTextPreference.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/*
2+
* custom chagnes: Keep
3+
* */
14
package app.revanced.extension.shared.settings.preference;
25

36
import static app.revanced.extension.shared.StringRef.str;
@@ -10,6 +13,7 @@
1013
import android.widget.Button;
1114
import android.widget.EditText;
1215

16+
import androidx.annotation.Keep;
1317
import androidx.annotation.Nullable;
1418

1519
import java.util.Objects;
@@ -33,6 +37,7 @@ public ResettableEditTextPreference(Context context, AttributeSet attrs, int def
3337
public ResettableEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) {
3438
super(context, attrs, defStyleAttr);
3539
}
40+
@Keep
3641
public ResettableEditTextPreference(Context context, AttributeSet attrs) {
3742
super(context, attrs);
3843
}

app/src/main/java/app/revanced/extension/youtube/settings/Settings.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
import static java.lang.Boolean.FALSE;
44
import static java.lang.Boolean.TRUE;
55
import static app.revanced.extension.shared.settings.Setting.parent;
6+
import static app.revanced.extension.shared.settings.Setting.parentsAny;
67
import static app.revanced.extension.youtube.sponsorblock.objects.CategoryBehaviour.IGNORE;
78
import static app.revanced.extension.youtube.sponsorblock.objects.CategoryBehaviour.MANUAL_SKIP;
89
import static app.revanced.extension.youtube.sponsorblock.objects.CategoryBehaviour.SKIP_AUTOMATICALLY;
910
import static app.revanced.extension.youtube.sponsorblock.objects.CategoryBehaviour.SKIP_AUTOMATICALLY_ONCE;
1011

1112
import app.revanced.extension.shared.settings.BaseSettings;
1213
import app.revanced.extension.shared.settings.BooleanSetting;
14+
import app.revanced.extension.shared.settings.EnumSetting;
1315
import app.revanced.extension.shared.settings.FloatSetting;
1416
import app.revanced.extension.shared.settings.IntegerSetting;
1517
import app.revanced.extension.shared.settings.LongSetting;
1618
import app.revanced.extension.shared.settings.StringSetting;
1719
import app.revanced.extension.youtube.sponsorblock.SponsorBlockSettings;
20+
import app.revanced.extension.youtube.swipecontrols.SwipeControlsConfigurationProvider.SwipeOverlayStyle;
1821

1922
@SuppressWarnings("deprecation")
2023
public class Settings extends BaseSettings {
@@ -54,6 +57,35 @@ public class Settings extends BaseSettings {
5457
public static final BooleanSetting SETTINGS_SEARCH_HISTORY = new BooleanSetting("revanced_settings_search_history", TRUE, true);
5558
public static final StringSetting SETTINGS_SEARCH_ENTRIES = new StringSetting("revanced_settings_search_entries", "", true);
5659

60+
// Swipe controls
61+
public static final BooleanSetting SWIPE_CHANGE_VIDEO = new BooleanSetting("revanced_swipe_change_video", FALSE, true);
62+
public static final BooleanSetting SWIPE_BRIGHTNESS = new BooleanSetting("revanced_swipe_brightness", FALSE, true);
63+
public static final BooleanSetting SWIPE_VOLUME = new BooleanSetting("revanced_swipe_volume", FALSE, true);
64+
public static final BooleanSetting SWIPE_PRESS_TO_ENGAGE = new BooleanSetting("revanced_swipe_press_to_engage", FALSE, true,
65+
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
66+
public static final BooleanSetting SWIPE_HAPTIC_FEEDBACK = new BooleanSetting("revanced_swipe_haptic_feedback", TRUE, true,
67+
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
68+
public static final IntegerSetting SWIPE_MAGNITUDE_THRESHOLD = new IntegerSetting("revanced_swipe_threshold", 30, true,
69+
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
70+
public static final IntegerSetting SWIPE_VOLUME_SENSITIVITY = new IntegerSetting("revanced_swipe_volume_sensitivity", 1, true, parent(SWIPE_VOLUME));
71+
public static final EnumSetting<SwipeOverlayStyle> SWIPE_OVERLAY_STYLE = new EnumSetting<>("revanced_swipe_overlay_style", SwipeOverlayStyle.HORIZONTAL,true,
72+
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
73+
public static final IntegerSetting SWIPE_OVERLAY_TEXT_SIZE = new IntegerSetting("revanced_swipe_text_overlay_size", 14, true,
74+
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
75+
public static final IntegerSetting SWIPE_OVERLAY_OPACITY = new IntegerSetting("revanced_swipe_overlay_background_opacity", 60, true,
76+
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
77+
public static final StringSetting SWIPE_OVERLAY_BRIGHTNESS_COLOR = new StringSetting("revanced_swipe_overlay_progress_brightness_color", "#FFFFFF", true,
78+
parent(SWIPE_BRIGHTNESS));
79+
public static final StringSetting SWIPE_OVERLAY_VOLUME_COLOR = new StringSetting("revanced_swipe_overlay_progress_volume_color", "#FFFFFF", true,
80+
parent(SWIPE_VOLUME));
81+
public static final LongSetting SWIPE_OVERLAY_TIMEOUT = new LongSetting("revanced_swipe_overlay_timeout", 500L, true,
82+
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
83+
public static final BooleanSetting SWIPE_SAVE_AND_RESTORE_BRIGHTNESS = new BooleanSetting("revanced_swipe_save_and_restore_brightness", TRUE, true,
84+
parent(SWIPE_BRIGHTNESS));
85+
public static final FloatSetting SWIPE_BRIGHTNESS_VALUE = new FloatSetting("revanced_swipe_brightness_value", -1f);
86+
public static final BooleanSetting SWIPE_LOWEST_VALUE_ENABLE_AUTO_BRIGHTNESS = new BooleanSetting("revanced_swipe_lowest_value_enable_auto_brightness", FALSE, true,
87+
parent(SWIPE_BRIGHTNESS));
88+
5789
// SponsorBlock
5890
public static final BooleanSetting SB_ENABLED = new BooleanSetting("sb_enabled", TRUE);
5991
/** Do not use id setting directly. Instead use {@link SponsorBlockSettings}. */
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package app.revanced.extension.youtube.shared
2+
3+
import android.app.Activity
4+
import android.view.View
5+
import android.view.ViewGroup
6+
import app.revanced.extension.shared.Utils
7+
import java.lang.ref.WeakReference
8+
9+
/**
10+
* default implementation of [PlayerControlsVisibilityObserver]
11+
*
12+
* @param activity activity that contains the controls_layout view
13+
*/
14+
class PlayerControlsVisibilityObserverImpl(
15+
private val activity: Activity,
16+
) : PlayerControlsVisibilityObserver {
17+
18+
/**
19+
* id of the direct parent of controls_layout, R.id.youtube_controls_overlay
20+
*/
21+
private val controlsLayoutParentId =
22+
Utils.getResourceIdentifier(activity, "youtube_controls_overlay", "id")
23+
24+
/**
25+
* id of R.id.controls_layout
26+
*/
27+
private val controlsLayoutId =
28+
Utils.getResourceIdentifier(activity, "controls_layout", "id")
29+
30+
/**
31+
* reference to the controls layout view
32+
*/
33+
private var controlsLayoutView = WeakReference<View>(null)
34+
35+
/**
36+
* is the [controlsLayoutView] set to a valid reference of a view?
37+
*/
38+
private val isAttached: Boolean
39+
get() {
40+
val view = controlsLayoutView.get()
41+
return view != null && view.parent != null
42+
}
43+
44+
/**
45+
* find and attach the controls_layout view if needed
46+
*/
47+
private fun maybeAttach() {
48+
if (isAttached) return
49+
50+
// find parent, then controls_layout view
51+
// this is needed because there may be two views where id=R.id.controls_layout
52+
// because why should google confine themselves to their own guidelines...
53+
activity.findViewById<ViewGroup>(controlsLayoutParentId)?.let { parent ->
54+
parent.findViewById<View>(controlsLayoutId)?.let {
55+
controlsLayoutView = WeakReference(it)
56+
}
57+
}
58+
}
59+
60+
override val playerControlsVisibility: Int
61+
get() {
62+
maybeAttach()
63+
return controlsLayoutView.get()?.visibility ?: View.GONE
64+
}
65+
66+
override val arePlayerControlsVisible: Boolean
67+
get() = playerControlsVisibility == View.VISIBLE
68+
}
69+
70+
/**
71+
* provides the visibility status of the fullscreen player controls_layout view.
72+
* this can be used for detecting when the player controls are shown
73+
*/
74+
interface PlayerControlsVisibilityObserver {
75+
/**
76+
* current visibility int of the controls_layout view
77+
*/
78+
val playerControlsVisibility: Int
79+
80+
/**
81+
* is the value of [playerControlsVisibility] equal to [View.VISIBLE]?
82+
*/
83+
val arePlayerControlsVisible: Boolean
84+
}

0 commit comments

Comments
 (0)