Skip to content

Commit

Permalink
fix(YouTube - Hide seekbar): Do not hide player seekbar if hide feed …
Browse files Browse the repository at this point in the history
…seekbar is enabled (#4333)
  • Loading branch information
LisoUseInAIKyrios authored Jan 22, 2025
1 parent c84eb82 commit f5cf6f2
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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}.
Expand Down Expand Up @@ -149,6 +146,22 @@ public static void setSplashAnimationDrawableTheme(AnimatedVectorDrawable vector
}
}

/**
* 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.
*
Expand All @@ -159,7 +172,7 @@ public static void setSplashAnimationDrawableTheme(AnimatedVectorDrawable vector
*/
public static int getLithoColor(int colorValue) {
if (colorValue == ORIGINAL_SEEKBAR_COLOR) {
if (Settings.HIDE_SEEKBAR_THUMBNAIL.get()) {
if (HIDE_SEEKBAR_THUMBNAIL_ENABLED) {
return 0x00000000;
}

Expand All @@ -172,18 +185,14 @@ public static int getLithoColor(int colorValue) {
* 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;
}

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;
Expand All @@ -202,14 +211,12 @@ private static String colorArrayToHex(int[] colors) {
* 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -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<OneRegisterInstruction>(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<MethodReference>()
reference?.definingClass == "Landroid/widget/ProgressBar;" && reference.name == "setMax"
}
val index = indexOfFirstInstructionOrThrow(progressIndex, Opcode.MOVE_RESULT)
val register = getInstruction<OneRegisterInstruction>(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"
Expand All @@ -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
"""
)
Expand Down

0 comments on commit f5cf6f2

Please sign in to comment.