mirror of
https://github.com/ReVanced/revanced-patches.git
synced 2025-05-11 21:25:40 +02:00
fix(YouTube - Theme): Replace custom seekbar gradient colors instead of disabling (#4329)
This commit is contained in:
parent
b4cc1493b2
commit
f03da98305
3 changed files with 100 additions and 30 deletions
|
@ -25,20 +25,25 @@ public final class SeekbarColorPatch {
|
||||||
private static final int ORIGINAL_SEEKBAR_COLOR = 0xFFFF0000;
|
private static final int ORIGINAL_SEEKBAR_COLOR = 0xFFFF0000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default colors of the gradient seekbar.
|
* Feed default colors of the gradient seekbar.
|
||||||
*/
|
*/
|
||||||
private static final int[] ORIGINAL_SEEKBAR_GRADIENT_COLORS = { 0xFFFF0033, 0xFFFF2791 };
|
private static final int[] FEED_ORIGINAL_SEEKBAR_GRADIENT_COLORS = { 0xFFFF0033, 0xFFFF2791 };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default positions of the gradient seekbar.
|
* Feed default positions of the gradient seekbar.
|
||||||
*/
|
*/
|
||||||
private static final float[] ORIGINAL_SEEKBAR_GRADIENT_POSITIONS = { 0.8f, 1.0f };
|
private static final float[] FEED_ORIGINAL_SEEKBAR_GRADIENT_POSITIONS = { 0.8f, 1.0f };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default YouTube seekbar color brightness.
|
* Default YouTube seekbar color brightness.
|
||||||
*/
|
*/
|
||||||
private static final float ORIGINAL_SEEKBAR_COLOR_BRIGHTNESS;
|
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,
|
* If {@link Settings#SEEKBAR_CUSTOM_COLOR} is enabled,
|
||||||
* this is the color value of {@link Settings#SEEKBAR_CUSTOM_COLOR_VALUE}.
|
* this is the color value of {@link Settings#SEEKBAR_CUSTOM_COLOR_VALUE}.
|
||||||
|
@ -51,6 +56,11 @@ public final class SeekbarColorPatch {
|
||||||
*/
|
*/
|
||||||
private static final float[] customSeekbarColorHSV = new float[3];
|
private static final float[] customSeekbarColorHSV = new float[3];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom seekbar color, used for linear gradient replacements.
|
||||||
|
*/
|
||||||
|
private static final int[] customSeekbarColorInt = new int[2];
|
||||||
|
|
||||||
static {
|
static {
|
||||||
float[] hsv = new float[3];
|
float[] hsv = new float[3];
|
||||||
Color.colorToHSV(ORIGINAL_SEEKBAR_COLOR, hsv);
|
Color.colorToHSV(ORIGINAL_SEEKBAR_COLOR, hsv);
|
||||||
|
@ -58,6 +68,8 @@ public final class SeekbarColorPatch {
|
||||||
|
|
||||||
if (SEEKBAR_CUSTOM_COLOR_ENABLED) {
|
if (SEEKBAR_CUSTOM_COLOR_ENABLED) {
|
||||||
loadCustomSeekbarColor();
|
loadCustomSeekbarColor();
|
||||||
|
|
||||||
|
Arrays.fill(customSeekbarColorInt, seekbarColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,15 +88,6 @@ public final class SeekbarColorPatch {
|
||||||
return seekbarColor;
|
return seekbarColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Injection point
|
|
||||||
*/
|
|
||||||
public static boolean playerSeekbarGradientEnabled(boolean original) {
|
|
||||||
if (SEEKBAR_CUSTOM_COLOR_ENABLED) return false;
|
|
||||||
|
|
||||||
return original;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Injection point
|
* Injection point
|
||||||
*/
|
*/
|
||||||
|
@ -165,6 +168,36 @@ public final class SeekbarColorPatch {
|
||||||
return colorValue;
|
return 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);
|
||||||
|
builder.append("[");
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for (int color : colors) {
|
||||||
|
builder.append(String.format("#%X", color));
|
||||||
|
if (++i < length) {
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Injection point.
|
* Injection point.
|
||||||
*/
|
*/
|
||||||
|
@ -174,15 +207,15 @@ public final class SeekbarColorPatch {
|
||||||
if (SEEKBAR_CUSTOM_COLOR_ENABLED || hideSeekbar) {
|
if (SEEKBAR_CUSTOM_COLOR_ENABLED || hideSeekbar) {
|
||||||
// Most litho usage of linear gradients is hooked here,
|
// Most litho usage of linear gradients is hooked here,
|
||||||
// so must only change if the values are those for the seekbar.
|
// so must only change if the values are those for the seekbar.
|
||||||
if (Arrays.equals(ORIGINAL_SEEKBAR_GRADIENT_COLORS, colors)
|
if ((Arrays.equals(FEED_ORIGINAL_SEEKBAR_GRADIENT_COLORS, colors)
|
||||||
&& Arrays.equals(ORIGINAL_SEEKBAR_GRADIENT_POSITIONS, positions)) {
|
&& Arrays.equals(FEED_ORIGINAL_SEEKBAR_GRADIENT_POSITIONS, positions))) {
|
||||||
Arrays.fill(colors, hideSeekbar
|
Arrays.fill(colors, hideSeekbar
|
||||||
? 0x00000000
|
? 0x00000000
|
||||||
: seekbarColor);
|
: seekbarColor);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.printDebug(() -> "Ignoring gradient colors: " + Arrays.toString(colors)
|
Logger.printDebug(() -> "Ignoring gradient colors: " + colorArrayToHex(colors)
|
||||||
+ " positions: " + Arrays.toString(positions));
|
+ " positions: " + Arrays.toString(positions));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,21 +34,42 @@ internal val shortsSeekbarColorFingerprint = fingerprint {
|
||||||
literal { reelTimeBarPlayedColorId }
|
literal { reelTimeBarPlayedColorId }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal const val PLAYER_SEEKBAR_GRADIENT_FEATURE_FLAG = 45617850L
|
|
||||||
|
|
||||||
internal val playerSeekbarGradientConfigFingerprint = fingerprint {
|
|
||||||
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
|
|
||||||
returns("Z")
|
|
||||||
parameters()
|
|
||||||
literal { PLAYER_SEEKBAR_GRADIENT_FEATURE_FLAG }
|
|
||||||
}
|
|
||||||
|
|
||||||
internal val lithoLinearGradientFingerprint = fingerprint {
|
internal val lithoLinearGradientFingerprint = fingerprint {
|
||||||
accessFlags(AccessFlags.STATIC)
|
accessFlags(AccessFlags.STATIC)
|
||||||
returns("Landroid/graphics/LinearGradient;")
|
returns("Landroid/graphics/LinearGradient;")
|
||||||
parameters("F", "F", "F", "F", "[I", "[F")
|
parameters("F", "F", "F", "F", "[I", "[F")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 29.25 - 19.50
|
||||||
|
*/
|
||||||
|
internal val playerLinearGradientLegacyFingerprint = fingerprint {
|
||||||
|
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
|
||||||
|
parameters("I", "I", "I", "I")
|
||||||
|
returns("V")
|
||||||
|
opcodes(
|
||||||
|
Opcode.FILLED_NEW_ARRAY,
|
||||||
|
Opcode.MOVE_RESULT_OBJECT
|
||||||
|
)
|
||||||
|
custom { method, _ ->
|
||||||
|
method.name == "setBounds" && method.containsLiteralInstruction(ytYoutubeMagentaColorId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 20.03+
|
||||||
|
*/
|
||||||
|
internal val playerLinearGradientFingerprint = fingerprint {
|
||||||
|
accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC)
|
||||||
|
parameters("I", "I", "I", "I", "Landroid/content/Context;", "I")
|
||||||
|
returns("Landroid/graphics/LinearGradient;")
|
||||||
|
opcodes(
|
||||||
|
Opcode.FILLED_NEW_ARRAY,
|
||||||
|
Opcode.MOVE_RESULT_OBJECT
|
||||||
|
)
|
||||||
|
literal { ytYoutubeMagentaColorId }
|
||||||
|
}
|
||||||
|
|
||||||
internal const val launchScreenLayoutTypeLotteFeatureFlag = 268507948L
|
internal const val launchScreenLayoutTypeLotteFeatureFlag = 268507948L
|
||||||
|
|
||||||
internal val launchScreenLayoutTypeFingerprint = fingerprint {
|
internal val launchScreenLayoutTypeFingerprint = fingerprint {
|
||||||
|
|
|
@ -39,6 +39,8 @@ internal var inlineTimeBarColorizedBarPlayedColorDarkId = -1L
|
||||||
private set
|
private set
|
||||||
internal var inlineTimeBarPlayedNotHighlightedColorId = -1L
|
internal var inlineTimeBarPlayedNotHighlightedColorId = -1L
|
||||||
private set
|
private set
|
||||||
|
internal var ytYoutubeMagentaColorId = -1L
|
||||||
|
private set
|
||||||
|
|
||||||
internal const val splashSeekbarColorAttributeName = "splash_custom_seekbar_color"
|
internal const val splashSeekbarColorAttributeName = "splash_custom_seekbar_color"
|
||||||
|
|
||||||
|
@ -62,6 +64,10 @@ private val seekbarColorResourcePatch = resourcePatch {
|
||||||
"color",
|
"color",
|
||||||
"inline_time_bar_played_not_highlighted_color",
|
"inline_time_bar_played_not_highlighted_color",
|
||||||
]
|
]
|
||||||
|
ytYoutubeMagentaColorId = resourceMappings[
|
||||||
|
"color",
|
||||||
|
"yt_youtube_magenta",
|
||||||
|
]
|
||||||
|
|
||||||
// Modify the resume playback drawable and replace the progress bar with a custom drawable.
|
// Modify the resume playback drawable and replace the progress bar with a custom drawable.
|
||||||
document("res/drawable/resume_playback_progressbar_drawable.xml").use { document ->
|
document("res/drawable/resume_playback_progressbar_drawable.xml").use { document ->
|
||||||
|
@ -229,16 +235,26 @@ val seekbarColorPatch = bytecodePatch(
|
||||||
|
|
||||||
// 19.25+ changes
|
// 19.25+ changes
|
||||||
|
|
||||||
playerSeekbarGradientConfigFingerprint.method.insertFeatureFlagBooleanOverride(
|
|
||||||
PLAYER_SEEKBAR_GRADIENT_FEATURE_FLAG,
|
|
||||||
"$EXTENSION_CLASS_DESCRIPTOR->playerSeekbarGradientEnabled(Z)Z"
|
|
||||||
)
|
|
||||||
|
|
||||||
lithoLinearGradientFingerprint.method.addInstruction(
|
lithoLinearGradientFingerprint.method.addInstruction(
|
||||||
0,
|
0,
|
||||||
"invoke-static/range { p4 .. p5 }, $EXTENSION_CLASS_DESCRIPTOR->setLinearGradient([I[F)V"
|
"invoke-static/range { p4 .. p5 }, $EXTENSION_CLASS_DESCRIPTOR->setLinearGradient([I[F)V"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: add 20.03 support
|
||||||
|
playerLinearGradientLegacyFingerprint.let {
|
||||||
|
it.method.apply {
|
||||||
|
val index = it.patternMatch!!.endIndex
|
||||||
|
val register = getInstruction<OneRegisterInstruction>(index).registerA
|
||||||
|
|
||||||
|
addInstructions(
|
||||||
|
index + 1,
|
||||||
|
"""
|
||||||
|
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->getLinearGradient([I)[I
|
||||||
|
move-result-object v$register
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// region apply seekbar custom color to splash screen animation.
|
// region apply seekbar custom color to splash screen animation.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue