From e377b1e6ad93dea8e5f3829cd3894f71851887a3 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Mon, 4 Nov 2024 19:22:41 -0400 Subject: [PATCH] fix(YouTube): Merge `Restore old seekbar thumbnails` into `Seekbar thumbnails` (#3860) Co-authored-by: oSumAtrIX --- .../RestoreOldSeekbarThumbnailsPatch.java | 10 ---- .../patches/SeekbarThumbnailsPatch.java | 18 +++++- .../youtube/patches/VersionCheckPatch.java | 1 + .../extension/youtube/settings/Settings.java | 4 +- patches/api/patches.api | 4 -- .../seekbar/SeekbarThumbnailsPatch.kt | 30 ++++++++-- .../RestoreOldSeekbarThumbnailsPatch.kt | 60 ------------------- .../resources/addresources/values/strings.xml | 4 +- 8 files changed, 46 insertions(+), 85 deletions(-) delete mode 100644 extensions/shared/src/main/java/app/revanced/extension/youtube/patches/RestoreOldSeekbarThumbnailsPatch.java delete mode 100644 patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/RestoreOldSeekbarThumbnailsPatch.kt diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/RestoreOldSeekbarThumbnailsPatch.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/RestoreOldSeekbarThumbnailsPatch.java deleted file mode 100644 index 8322ea70b..000000000 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/RestoreOldSeekbarThumbnailsPatch.java +++ /dev/null @@ -1,10 +0,0 @@ -package app.revanced.extension.youtube.patches; - -import app.revanced.extension.youtube.settings.Settings; - -@SuppressWarnings("unused") -public final class RestoreOldSeekbarThumbnailsPatch { - public static boolean useFullscreenSeekbarThumbnails() { - return !Settings.RESTORE_OLD_SEEKBAR_THUMBNAILS.get(); - } -} diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/SeekbarThumbnailsPatch.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/SeekbarThumbnailsPatch.java index a48274336..e9a469026 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/SeekbarThumbnailsPatch.java +++ b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/SeekbarThumbnailsPatch.java @@ -1,11 +1,20 @@ package app.revanced.extension.youtube.patches; +import app.revanced.extension.shared.settings.Setting; import app.revanced.extension.youtube.settings.Settings; @SuppressWarnings("unused") public class SeekbarThumbnailsPatch { - private static final boolean SEEKBAR_THUMBNAILS_HIGH_QUALITY_ENABLED = Settings.SEEKBAR_THUMBNAILS_HIGH_QUALITY.get(); + public static final class SeekbarThumbnailsHighQualityAvailability implements Setting.Availability { + @Override + public boolean isAvailable() { + return VersionCheckPatch.IS_19_17_OR_GREATER || !Settings.RESTORE_OLD_SEEKBAR_THUMBNAILS.get(); + } + } + + private static final boolean SEEKBAR_THUMBNAILS_HIGH_QUALITY_ENABLED + = Settings.SEEKBAR_THUMBNAILS_HIGH_QUALITY.get(); /** * Injection point. @@ -13,4 +22,11 @@ public class SeekbarThumbnailsPatch { public static boolean useHighQualityFullscreenThumbnails() { return SEEKBAR_THUMBNAILS_HIGH_QUALITY_ENABLED; } + + /** + * Injection point. + */ + public static boolean useFullscreenSeekbarThumbnails() { + return !Settings.RESTORE_OLD_SEEKBAR_THUMBNAILS.get(); + } } diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/VersionCheckPatch.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/VersionCheckPatch.java index 2d3817ce9..74f082bf4 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/VersionCheckPatch.java +++ b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/VersionCheckPatch.java @@ -3,6 +3,7 @@ package app.revanced.extension.youtube.patches; import app.revanced.extension.shared.Utils; public class VersionCheckPatch { + public static final boolean IS_19_17_OR_GREATER = Utils.getAppVersionName().compareTo("19.17.00") >= 0; public static final boolean IS_19_20_OR_GREATER = Utils.getAppVersionName().compareTo("19.20.00") >= 0; public static final boolean IS_19_21_OR_GREATER = Utils.getAppVersionName().compareTo("19.21.00") >= 0; public static final boolean IS_19_26_OR_GREATER = Utils.getAppVersionName().compareTo("19.26.00") >= 0; diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java index c3d1f9f96..ced98122b 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java +++ b/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java @@ -7,6 +7,7 @@ import static app.revanced.extension.youtube.patches.ChangeStartPagePatch.StartP import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerHideExpandCloseAvailability; import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerType; import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerType.*; +import static app.revanced.extension.youtube.patches.SeekbarThumbnailsPatch.SeekbarThumbnailsHighQualityAvailability; import static app.revanced.extension.youtube.sponsorblock.objects.CategoryBehaviour.*; import app.revanced.extension.shared.Logger; @@ -256,7 +257,8 @@ public class Settings extends BaseSettings { public static final BooleanSetting SEEKBAR_TAPPING = new BooleanSetting("revanced_seekbar_tapping", TRUE); public static final BooleanSetting SLIDE_TO_SEEK = new BooleanSetting("revanced_slide_to_seek", FALSE, true); public static final BooleanSetting RESTORE_OLD_SEEKBAR_THUMBNAILS = new BooleanSetting("revanced_restore_old_seekbar_thumbnails", TRUE); - public static final BooleanSetting SEEKBAR_THUMBNAILS_HIGH_QUALITY = new BooleanSetting("revanced_seekbar_thumbnails_high_quality", FALSE, true, "revanced_seekbar_thumbnails_high_quality_dialog_message"); + public static final BooleanSetting SEEKBAR_THUMBNAILS_HIGH_QUALITY = new BooleanSetting("revanced_seekbar_thumbnails_high_quality", FALSE, true, + "revanced_seekbar_thumbnails_high_quality_dialog_message", new SeekbarThumbnailsHighQualityAvailability()); public static final BooleanSetting HIDE_SEEKBAR = new BooleanSetting("revanced_hide_seekbar", FALSE, true); public static final BooleanSetting HIDE_SEEKBAR_THUMBNAIL = new BooleanSetting("revanced_hide_seekbar_thumbnail", FALSE); public static final BooleanSetting SEEKBAR_CUSTOM_COLOR = new BooleanSetting("revanced_seekbar_custom_color", FALSE, true); diff --git a/patches/api/patches.api b/patches/api/patches.api index d950a583e..bf2c99b23 100644 --- a/patches/api/patches.api +++ b/patches/api/patches.api @@ -1192,10 +1192,6 @@ public final class app/revanced/patches/youtube/layout/seekbar/FingerprintsKt { public static final field PLAYER_SEEKBAR_GRADIENT_FEATURE_FLAG J } -public final class app/revanced/patches/youtube/layout/seekbar/RestoreOldSeekbarThumbnailsPatchKt { - public static final fun getRestoreOldSeekbarThumbnailsPatch ()Lapp/revanced/patcher/patch/BytecodePatch; -} - public final class app/revanced/patches/youtube/layout/seekbar/SeekbarColorPatchKt { public static final fun getSeekbarColorPatch ()Lapp/revanced/patcher/patch/BytecodePatch; } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/SeekbarThumbnailsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/SeekbarThumbnailsPatch.kt index 08501859d..1116f56be 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/SeekbarThumbnailsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/SeekbarThumbnailsPatch.kt @@ -1,10 +1,13 @@ package app.revanced.patches.youtube.interaction.seekbar +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.extensions.InstructionExtensions.instructions import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.all.misc.resources.addResources import app.revanced.patches.all.misc.resources.addResourcesPatch import app.revanced.patches.shared.misc.settings.preference.SwitchPreference +import app.revanced.patches.youtube.layout.seekbar.fullscreenSeekbarThumbnailsFingerprint import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.misc.playservice.is_19_17_or_greater import app.revanced.patches.youtube.misc.playservice.versionCheckPatch @@ -16,7 +19,8 @@ private const val EXTENSION_CLASS_DESCRIPTOR = @Suppress("unused") val seekbarThumbnailsPatch = bytecodePatch( name = "Seekbar thumbnails", - description = "Adds an option to use high quality fullscreen seekbar thumbnails.", + description = "Adds an option to use high quality fullscreen seekbar thumbnails. " + + "Patching 19.16.39 or lower adds an option to restore old seekbar thumbnails.", ) { dependsOn( sharedExtensionPatch, @@ -37,20 +41,34 @@ val seekbarThumbnailsPatch = bytecodePatch( val fullscreenSeekbarThumbnailsQualityMatch by fullscreenSeekbarThumbnailsQualityFingerprint() + val fullscreenSeekbarThumbnailsMatch by fullscreenSeekbarThumbnailsFingerprint() + execute { addResources("youtube", "layout.seekbar.seekbarThumbnailsPatch") - PreferenceScreen.SEEKBAR.addPreferences( - if (!is_19_17_or_greater) { + if (is_19_17_or_greater) { + PreferenceScreen.SEEKBAR.addPreferences( + SwitchPreference("revanced_seekbar_thumbnails_high_quality") + ) + } else { + PreferenceScreen.SEEKBAR.addPreferences( + SwitchPreference("revanced_restore_old_seekbar_thumbnails"), SwitchPreference( key = "revanced_seekbar_thumbnails_high_quality", summaryOnKey = "revanced_seekbar_thumbnails_high_quality_legacy_summary_on", summaryOffKey = "revanced_seekbar_thumbnails_high_quality_legacy_summary_on" ) - } else { - SwitchPreference("revanced_seekbar_thumbnails_high_quality") + ) + + fullscreenSeekbarThumbnailsMatch.mutableMethod.apply { + val moveResultIndex = instructions.lastIndex - 1 + + addInstruction( + moveResultIndex, + "invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->useFullscreenSeekbarThumbnails()Z", + ) } - ) + } fullscreenSeekbarThumbnailsQualityMatch.mutableMethod.addInstructions( 0, diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/RestoreOldSeekbarThumbnailsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/RestoreOldSeekbarThumbnailsPatch.kt deleted file mode 100644 index 1dbdad884..000000000 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/RestoreOldSeekbarThumbnailsPatch.kt +++ /dev/null @@ -1,60 +0,0 @@ -package app.revanced.patches.youtube.layout.seekbar - -import app.revanced.patcher.extensions.InstructionExtensions.addInstruction -import app.revanced.patcher.extensions.InstructionExtensions.instructions -import app.revanced.patcher.patch.bytecodePatch -import app.revanced.patches.all.misc.resources.addResources -import app.revanced.patches.all.misc.resources.addResourcesPatch -import app.revanced.patches.shared.misc.settings.preference.SwitchPreference -import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch -import app.revanced.patches.youtube.misc.playservice.is_19_17_or_greater -import app.revanced.patches.youtube.misc.playservice.versionCheckPatch -import app.revanced.patches.youtube.misc.settings.PreferenceScreen -import java.util.logging.Logger - -private const val EXTENSION_CLASS_DESCRIPTOR = - "Lapp/revanced/extension/youtube/patches/RestoreOldSeekbarThumbnailsPatch;" - -@Suppress("unused") -val restoreOldSeekbarThumbnailsPatch = bytecodePatch( - name = "Restore old seekbar thumbnails", - description = "Adds an option to restore the old seekbar thumbnails that appear above the seekbar while seeking instead of fullscreen thumbnails.", -) { - dependsOn( - sharedExtensionPatch, - addResourcesPatch, - versionCheckPatch, - ) - - compatibleWith( - "com.google.android.youtube"( - "18.38.44", - "18.49.37", - "19.16.39", - // 19.17+ is not supported. - ), - ) - - val fullscreenSeekbarThumbnailsMatch by fullscreenSeekbarThumbnailsFingerprint() - - execute { - if (is_19_17_or_greater) { - return@execute Logger.getLogger(this::class.java.name).severe("'Restore old seekbar thumbnails' cannot be patched to any version after 19.16.39") - } - - addResources("youtube", "layout.seekbar.restoreOldSeekbarThumbnailsPatch") - - PreferenceScreen.SEEKBAR.addPreferences( - SwitchPreference("revanced_restore_old_seekbar_thumbnails"), - ) - - fullscreenSeekbarThumbnailsMatch.mutableMethod.apply { - val moveResultIndex = instructions.lastIndex - 1 - - addInstruction( - moveResultIndex, - "invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->useFullscreenSeekbarThumbnails()Z", - ) - } - } -} diff --git a/patches/src/main/resources/addresources/values/strings.xml b/patches/src/main/resources/addresources/values/strings.xml index b5cea7be1..f93620055 100644 --- a/patches/src/main/resources/addresources/values/strings.xml +++ b/patches/src/main/resources/addresources/values/strings.xml @@ -777,9 +777,7 @@ This is because Crowdin requires temporarily flattening this file and removing t Seekbar thumbnails are medium quality Fullscreen seekbar thumbnails are high quality Fullscreen seekbar thumbnails are medium quality - 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. - - + This will also restore thumbnails on livestreams that do not have seekbar thumbnails.\n\nSeekbar thumbnails will use the same quality as the current video.\n\nThis feature works best with a video quality of 720p or lower and when using a very fast internet connection. Restore old seekbar thumbnails Seekbar thumbnails will appear above the seekbar Seekbar thumbnails will appear in fullscreen