diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/theme/SeekbarColorPatch.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/theme/SeekbarColorPatch.java index 686cc51cf..17e6b258e 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/theme/SeekbarColorPatch.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/theme/SeekbarColorPatch.java @@ -18,6 +18,8 @@ public final class SeekbarColorPatch { private static final boolean SEEKBAR_CUSTOM_COLOR_ENABLED = Settings.SEEKBAR_CUSTOM_COLOR.get(); + private static final boolean HIDE_SEEKBAR_THUMBNAIL_ENABLED = Settings.HIDE_SEEKBAR_THUMBNAIL.get(); + /** * Default color of the litho seekbar. * Differs slightly from the default custom seekbar color setting. @@ -39,11 +41,6 @@ public final class SeekbarColorPatch { */ private static final float ORIGINAL_SEEKBAR_COLOR_BRIGHTNESS; - /** - * Empty seekbar gradient, if hide seekbar in feed is enabled. - */ - private static final int[] HIDDEN_SEEKBAR_GRADIENT_COLORS = { 0x00000000, 0x00000000 }; - /** * If {@link Settings#SEEKBAR_CUSTOM_COLOR} is enabled, * this is the color value of {@link Settings#SEEKBAR_CUSTOM_COLOR_VALUE}. @@ -149,6 +146,22 @@ public final class SeekbarColorPatch { } } + /** + * Injection point. + */ + public static boolean showWatchHistoryProgressDrawable(boolean original) { + return !HIDE_SEEKBAR_THUMBNAIL_ENABLED && original; + } + + /** + * Injection point. + */ + public static int getSeekbarScrubHandleColor(int colorValue) { + return SEEKBAR_CUSTOM_COLOR_ENABLED + ? seekbarColor + : colorValue; + } + /** * Injection point. * @@ -159,7 +172,7 @@ public final class SeekbarColorPatch { */ public static int getLithoColor(int colorValue) { if (colorValue == ORIGINAL_SEEKBAR_COLOR) { - if (Settings.HIDE_SEEKBAR_THUMBNAIL.get()) { + if (HIDE_SEEKBAR_THUMBNAIL_ENABLED) { return 0x00000000; } @@ -172,10 +185,6 @@ public final class SeekbarColorPatch { * Injection point. */ public static int[] getLinearGradient(int[] original) { - if (Settings.HIDE_SEEKBAR_THUMBNAIL.get()) { - return HIDDEN_SEEKBAR_GRADIENT_COLORS; - } - return SEEKBAR_CUSTOM_COLOR_ENABLED ? customSeekbarColorInt : original; @@ -183,7 +192,7 @@ public final class SeekbarColorPatch { private static String colorArrayToHex(int[] colors) { final int length = colors.length; - StringBuilder builder = new StringBuilder(length * 10); + StringBuilder builder = new StringBuilder(length * 12); builder.append("["); int i = 0; @@ -202,14 +211,12 @@ public final class SeekbarColorPatch { * Injection point. */ public static void setLinearGradient(int[] colors, float[] positions) { - final boolean hideSeekbar = Settings.HIDE_SEEKBAR_THUMBNAIL.get(); - - if (SEEKBAR_CUSTOM_COLOR_ENABLED || hideSeekbar) { + if (SEEKBAR_CUSTOM_COLOR_ENABLED || HIDE_SEEKBAR_THUMBNAIL_ENABLED) { // Most litho usage of linear gradients is hooked here, // so must only change if the values are those for the seekbar. if ((Arrays.equals(FEED_ORIGINAL_SEEKBAR_GRADIENT_COLORS, colors) && Arrays.equals(FEED_ORIGINAL_SEEKBAR_GRADIENT_POSITIONS, positions))) { - Arrays.fill(colors, hideSeekbar + Arrays.fill(colors, HIDE_SEEKBAR_THUMBNAIL_ENABLED ? 0x00000000 : seekbarColor); return; diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java index 5817e5aca..6d76255c5 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java @@ -270,7 +270,7 @@ public class Settings extends BaseSettings { public static final BooleanSetting DISABLE_PRECISE_SEEKING_GESTURE = new BooleanSetting("revanced_disable_precise_seeking_gesture", TRUE); 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 HIDE_SEEKBAR_THUMBNAIL = new BooleanSetting("revanced_hide_seekbar_thumbnail", FALSE, true); public static final BooleanSetting HIDE_TIMESTAMP = new BooleanSetting("revanced_hide_timestamp", FALSE); public static final BooleanSetting RESTORE_OLD_SEEKBAR_THUMBNAILS = new BooleanSetting("revanced_restore_old_seekbar_thumbnails", TRUE); public static final BooleanSetting SEEKBAR_CUSTOM_COLOR = new BooleanSetting("revanced_seekbar_custom_color", FALSE, true); diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/Fingerprints.kt index 4c08cdd92..5735f57d5 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/Fingerprints.kt @@ -34,6 +34,19 @@ internal val shortsSeekbarColorFingerprint = fingerprint { literal { reelTimeBarPlayedColorId } } +internal val playerSeekbarHandleColorFingerprint = fingerprint { + accessFlags(AccessFlags.PUBLIC, AccessFlags.CONSTRUCTOR) + parameters("Landroid/content/Context;") + literal { ytStaticBrandRedId } +} + +internal val watchHistoryMenuUseProgressDrawableFingerprint = fingerprint { + accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) + returns("V") + parameters("L") + literal { -1712394514 } +} + internal val lithoLinearGradientFingerprint = fingerprint { accessFlags(AccessFlags.STATIC) returns("Landroid/graphics/LinearGradient;") diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/SeekbarColorPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/SeekbarColorPatch.kt index d138ae6ef..5ccbdad84 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/SeekbarColorPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/SeekbarColorPatch.kt @@ -14,6 +14,7 @@ import app.revanced.patches.youtube.layout.theme.lithoColorHookPatch import app.revanced.patches.youtube.layout.theme.lithoColorOverrideHook import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.misc.playservice.is_19_25_or_greater +import app.revanced.patches.youtube.misc.playservice.is_19_34_or_greater import app.revanced.patches.youtube.misc.playservice.is_19_46_or_greater import app.revanced.patches.youtube.misc.playservice.is_19_49_or_greater import app.revanced.patches.youtube.misc.playservice.versionCheckPatch @@ -42,6 +43,8 @@ internal var inlineTimeBarPlayedNotHighlightedColorId = -1L private set internal var ytYoutubeMagentaColorId = -1L private set +internal var ytStaticBrandRedId = -1L + private set internal const val splashSeekbarColorAttributeName = "splash_custom_seekbar_color" @@ -69,6 +72,10 @@ private val seekbarColorResourcePatch = resourcePatch { "color", "yt_youtube_magenta", ] + ytStaticBrandRedId = resourceMappings[ + "attr", + "ytStaticBrandRed", + ] // Modify the resume playback drawable and replace the progress bar with a custom drawable. document("res/drawable/resume_playback_progressbar_drawable.xml").use { document -> @@ -237,6 +244,42 @@ val seekbarColorPatch = bytecodePatch( // 19.25+ changes + playerSeekbarHandleColorFingerprint.method.apply { + val index = indexOfFirstLiteralInstructionOrThrow(ytStaticBrandRedId) + val insertIndex = indexOfFirstInstructionOrThrow(index, Opcode.MOVE_RESULT) + val register = getInstruction(insertIndex).registerA + + addInstructions( + insertIndex + 1, + """ + invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->getSeekbarScrubHandleColor(I)I + move-result v$register + """ + ) + } + + // If hiding feed seekbar thumbnails, then turn off the cairo gradient + // of the watch history menu items as they use the same gradient as the + // player and there is no easy way to distinguish which to use a transparent color. + if (is_19_34_or_greater) { + watchHistoryMenuUseProgressDrawableFingerprint.method.apply { + val progressIndex = indexOfFirstInstructionOrThrow { + val reference = getReference() + reference?.definingClass == "Landroid/widget/ProgressBar;" && reference.name == "setMax" + } + val index = indexOfFirstInstructionOrThrow(progressIndex, Opcode.MOVE_RESULT) + val register = getInstruction(index).registerA + + addInstructions( + index + 1, + """ + invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->showWatchHistoryProgressDrawable(Z)Z + move-result v$register + """ + ) + } + } + lithoLinearGradientFingerprint.method.addInstruction( 0, "invoke-static/range { p4 .. p5 }, $EXTENSION_CLASS_DESCRIPTOR->setLinearGradient([I[F)V" @@ -259,7 +302,7 @@ val seekbarColorPatch = bytecodePatch( addInstructions( index + 1, """ - invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->getLinearGradient([I)[I + invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->getLinearGradient([I)[I move-result-object v$register """ )