fix(YouTube): Merge Restore old seekbar thumbnails into Seekbar thumbnails (#3860)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
LisoUseInAIKyrios 2024-11-04 19:22:41 -04:00 committed by oSumAtrIX
parent a37096bf4d
commit e377b1e6ad
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
8 changed files with 46 additions and 85 deletions

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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,21 +41,35 @@ val seekbarThumbnailsPatch = bytecodePatch(
val fullscreenSeekbarThumbnailsQualityMatch by fullscreenSeekbarThumbnailsQualityFingerprint()
val fullscreenSeekbarThumbnailsMatch by fullscreenSeekbarThumbnailsFingerprint()
execute {
addResources("youtube", "layout.seekbar.seekbarThumbnailsPatch")
if (is_19_17_or_greater) {
PreferenceScreen.SEEKBAR.addPreferences(
if (!is_19_17_or_greater) {
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,
"""

View File

@ -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",
)
}
}
}

View File

@ -777,9 +777,7 @@ This is because Crowdin requires temporarily flattening this file and removing t
<string name="revanced_seekbar_thumbnails_high_quality_summary_off">Seekbar thumbnails are medium quality</string>
<string name="revanced_seekbar_thumbnails_high_quality_legacy_summary_on">Fullscreen seekbar thumbnails are high quality</string>
<string name="revanced_seekbar_thumbnails_high_quality_legacy_summary_off">Fullscreen seekbar thumbnails are medium quality</string>
<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>
</patch>
<patch id="layout.seekbar.restoreOldSeekbarThumbnailsPatch">
<string name="revanced_seekbar_thumbnails_high_quality_dialog_message">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.</string>
<string name="revanced_restore_old_seekbar_thumbnails_title">Restore old seekbar thumbnails</string>
<string name="revanced_restore_old_seekbar_thumbnails_summary_on">Seekbar thumbnails will appear above the seekbar</string>
<string name="revanced_restore_old_seekbar_thumbnails_summary_off">Seekbar thumbnails will appear in fullscreen</string>