Skip to content

Commit 5988b75

Browse files
LisoUseInAIKyriosoSumAtrIX
authored andcommitted
feat(YouTube): Add Seekbar thumbnails patch (ReVanced#3813)
1 parent beb6436 commit 5988b75

File tree

7 files changed

+102
-3
lines changed

7 files changed

+102
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package app.revanced.extension.youtube.patches;
2+
3+
import app.revanced.extension.youtube.settings.Settings;
4+
5+
@SuppressWarnings("unused")
6+
public class SeekbarThumbnailsPatch {
7+
8+
private static final boolean SEEKBAR_THUMBNAILS_HIGH_QUALITY_ENABLED = Settings.SEEKBAR_THUMBNAILS_HIGH_QUALITY.get();
9+
10+
/**
11+
* Injection point.
12+
*/
13+
public static boolean useHighQualityFullscreenThumbnails() {
14+
return SEEKBAR_THUMBNAILS_HIGH_QUALITY_ENABLED;
15+
}
16+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ public class Settings extends BaseSettings {
250250
public static final BooleanSetting SEEKBAR_TAPPING = new BooleanSetting("revanced_seekbar_tapping", TRUE);
251251
public static final BooleanSetting SLIDE_TO_SEEK = new BooleanSetting("revanced_slide_to_seek", FALSE, true);
252252
public static final BooleanSetting RESTORE_OLD_SEEKBAR_THUMBNAILS = new BooleanSetting("revanced_restore_old_seekbar_thumbnails", TRUE);
253+
public static final BooleanSetting SEEKBAR_THUMBNAILS_HIGH_QUALITY = new BooleanSetting("revanced_seekbar_thumbnails_high_quality", FALSE, true, "revanced_seekbar_thumbnails_high_quality_dialog_message");
253254
public static final BooleanSetting HIDE_SEEKBAR = new BooleanSetting("revanced_hide_seekbar", FALSE, true);
254255
public static final BooleanSetting HIDE_SEEKBAR_THUMBNAIL = new BooleanSetting("revanced_hide_seekbar_thumbnail", FALSE);
255256
public static final BooleanSetting SEEKBAR_CUSTOM_COLOR = new BooleanSetting("revanced_seekbar_custom_color", FALSE, true);

patches/api/patches.api

+4
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,10 @@ public final class app/revanced/patches/youtube/layout/seekbar/SeekbarColorPatch
11961196
public static final fun getSeekbarColorPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
11971197
}
11981198

1199+
public final class app/revanced/patches/youtube/layout/seekbar/SeekbarThumbnailsPatchKt {
1200+
public static final fun getSeekbarThumbnailsPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
1201+
}
1202+
11991203
public final class app/revanced/patches/youtube/layout/shortsautoplay/ShortsAutoplayPatchKt {
12001204
public static final fun getShortsAutoplayPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
12011205
}

patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/Fingerprints.kt

+7
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,10 @@ internal val slideToSeekFingerprint = fingerprint {
117117
)
118118
literal { 67108864 }
119119
}
120+
121+
internal val fullscreenSeekbarThumbnailsQualityFingerprint = fingerprint {
122+
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
123+
returns("Z")
124+
parameters()
125+
literal { 45399684L }
126+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package app.revanced.patches.youtube.layout.seekbar
2+
3+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
4+
import app.revanced.patcher.patch.bytecodePatch
5+
import app.revanced.patches.all.misc.resources.addResources
6+
import app.revanced.patches.all.misc.resources.addResourcesPatch
7+
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
8+
import app.revanced.patches.youtube.interaction.seekbar.fullscreenSeekbarThumbnailsQualityFingerprint
9+
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
10+
import app.revanced.patches.youtube.misc.playservice.is_19_17_or_greater
11+
import app.revanced.patches.youtube.misc.playservice.versionCheckPatch
12+
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
13+
14+
private const val EXTENSION_CLASS_DESCRIPTOR =
15+
"Lapp/revanced/extension/youtube/patches/SeekbarThumbnailsPatch;"
16+
17+
@Suppress("unused")
18+
val seekbarThumbnailsPatch = bytecodePatch(
19+
name = "Seekbar thumbnails",
20+
description = "Adds an option to use high quality fullscreen seekbar thumbnails.",
21+
) {
22+
dependsOn(
23+
sharedExtensionPatch,
24+
addResourcesPatch,
25+
versionCheckPatch,
26+
)
27+
28+
compatibleWith(
29+
"com.google.android.youtube"(
30+
"18.38.44",
31+
"18.49.37",
32+
"19.16.39",
33+
"19.25.37",
34+
"19.34.42",
35+
)
36+
)
37+
38+
val fullscreenSeekbarThumbnailsQualityMatch by fullscreenSeekbarThumbnailsQualityFingerprint()
39+
40+
execute {
41+
addResources("youtube", "layout.seekbar.seekbarThumbnailsPatch")
42+
43+
PreferenceScreen.SEEKBAR.addPreferences(
44+
if (!is_19_17_or_greater) {
45+
SwitchPreference(
46+
key = "revanced_seekbar_thumbnails_high_quality",
47+
summaryOnKey = "revanced_seekbar_thumbnails_high_quality_legacy_summary_on",
48+
summaryOffKey = "revanced_seekbar_thumbnails_high_quality_legacy_summary_on"
49+
)
50+
} else {
51+
SwitchPreference("revanced_seekbar_thumbnails_high_quality")
52+
}
53+
)
54+
55+
fullscreenSeekbarThumbnailsQualityMatch.mutableMethod.addInstructions(
56+
0,
57+
"""
58+
invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->useHighQualityFullscreenThumbnails()Z
59+
move-result v0
60+
return v0
61+
"""
62+
)
63+
}
64+
}

patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/RestoreOldSeekbarThumbnailsPatch.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package app.revanced.patches.youtube.layout.seekbar
22

33
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
44
import app.revanced.patcher.extensions.InstructionExtensions.instructions
5-
import app.revanced.patcher.patch.PatchException
65
import app.revanced.patcher.patch.bytecodePatch
76
import app.revanced.patches.all.misc.resources.addResources
87
import app.revanced.patches.all.misc.resources.addResourcesPatch
@@ -11,6 +10,7 @@ import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
1110
import app.revanced.patches.youtube.misc.playservice.is_19_17_or_greater
1211
import app.revanced.patches.youtube.misc.playservice.versionCheckPatch
1312
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
13+
import java.util.logging.Logger
1414

1515
private const val EXTENSION_CLASS_DESCRIPTOR =
1616
"Lapp/revanced/extension/youtube/patches/RestoreOldSeekbarThumbnailsPatch;"
@@ -39,8 +39,7 @@ val restoreOldSeekbarThumbnailsPatch = bytecodePatch(
3939

4040
execute {
4141
if (is_19_17_or_greater) {
42-
// Give a more informative error, if the user has turned off version checks.
43-
throw PatchException("'Restore old seekbar thumbnails' cannot be patched to any version after 19.16.39")
42+
return@execute Logger.getLogger(this::class.java.name).severe("'Restore old seekbar thumbnails' cannot be patched to any version after 19.16.39")
4443
}
4544

4645
addResources("youtube", "layout.seekbar.restoreOldSeekbarThumbnailsPatch")

patches/src/main/resources/addresources/values/strings.xml

+8
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,14 @@ This is because Crowdin requires temporarily flattening this file and removing t
762762
<string name="revanced_wide_searchbar_summary_on">Wide search bar is enabled</string>
763763
<string name="revanced_wide_searchbar_summary_off">Wide search bar is disabled</string>
764764
</patch>
765+
<patch id="layout.seekbar.seekbarThumbnailsPatch">
766+
<string name="revanced_seekbar_thumbnails_high_quality_title">Enable high quality thumbnails</string>
767+
<string name="revanced_seekbar_thumbnails_high_quality_summary_on">Seekbar thumbnails are high quality</string>
768+
<string name="revanced_seekbar_thumbnails_high_quality_summary_off">Seekbar thumbnails are medium quality</string>
769+
<string name="revanced_seekbar_thumbnails_high_quality_legacy_summary_on">Fullscreen seekbar thumbnails are high quality</string>
770+
<string name="revanced_seekbar_thumbnails_high_quality_legacy_summary_off">Fullscreen seekbar thumbnails are medium quality</string>
771+
<string name="revanced_seekbar_thumbnails_high_quality_dialog_message">This will restore thumbnails to livestreams that do not have seekbar thumbnails.\n\nInternet data usage may be higher, and seekbar thumbnails will have a slight delay before showing.\n\nThis feature works best with a very fast internet connection.</string>
772+
</patch>
765773
<patch id="layout.seekbar.restoreOldSeekbarThumbnailsPatch">
766774
<string name="revanced_restore_old_seekbar_thumbnails_title">Restore old seekbar thumbnails</string>
767775
<string name="revanced_restore_old_seekbar_thumbnails_summary_on">Seekbar thumbnails will appear above the seekbar</string>

0 commit comments

Comments
 (0)