chore(YouTube - Seekbar components): Match with ReVanced

This commit is contained in:
inotia00
2025-01-22 13:23:07 +09:00
parent 5dd79073f1
commit f1d04b5323
5 changed files with 113 additions and 16 deletions

View File

@ -27,23 +27,28 @@ public class SeekbarColorPatch {
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.
*/
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#ENABLE_CUSTOM_SEEKBAR_COLOR} is enabled,
* this is the color value of {@link Settings#ENABLE_CUSTOM_SEEKBAR_COLOR_VALUE}.
* this is the color value of {@link Settings#CUSTOM_SEEKBAR_COLOR_VALUE}.
* Otherwise this is {@link #ORIGINAL_SEEKBAR_COLOR}.
*/
private static int seekbarColor = ORIGINAL_SEEKBAR_COLOR;
@ -53,6 +58,11 @@ public class SeekbarColorPatch {
*/
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 {
float[] hsv = new float[3];
Color.colorToHSV(ORIGINAL_SEEKBAR_COLOR, hsv);
@ -61,16 +71,18 @@ public class SeekbarColorPatch {
if (CUSTOM_SEEKBAR_COLOR_ENABLED) {
loadCustomSeekbarColor();
}
Arrays.fill(customSeekbarColorInt, seekbarColor);
}
private static void loadCustomSeekbarColor() {
try {
seekbarColor = Color.parseColor(Settings.ENABLE_CUSTOM_SEEKBAR_COLOR_VALUE.get());
seekbarColor = Color.parseColor(Settings.CUSTOM_SEEKBAR_COLOR_VALUE.get());
Color.colorToHSV(seekbarColor, customSeekbarColorHSV);
} catch (Exception ex) {
Utils.showToastShort(str("revanced_custom_seekbar_color_value_invalid_invalid_toast"));
Utils.showToastShort(str("revanced_extended_reset_to_default_toast"));
Settings.ENABLE_CUSTOM_SEEKBAR_COLOR_VALUE.resetToDefault();
Settings.CUSTOM_SEEKBAR_COLOR_VALUE.resetToDefault();
loadCustomSeekbarColor();
}
}
@ -165,6 +177,33 @@ public class SeekbarColorPatch {
return colorValue;
}
/**
* Injection point.
*/
public static int[] getLinearGradient(int[] original) {
if (Settings.HIDE_SEEKBAR_THUMBNAIL.get()) {
return HIDDEN_SEEKBAR_GRADIENT_COLORS;
}
return CUSTOM_SEEKBAR_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.
*/
@ -174,15 +213,15 @@ public class SeekbarColorPatch {
if (CUSTOM_SEEKBAR_COLOR_ENABLED || hideSeekbar) {
// Most litho usage of linear gradients is hooked here,
// so must only change if the values are those for the seekbar.
if (Arrays.equals(ORIGINAL_SEEKBAR_GRADIENT_COLORS, colors)
&& Arrays.equals(ORIGINAL_SEEKBAR_GRADIENT_POSITIONS, positions)) {
if ((Arrays.equals(FEED_ORIGINAL_SEEKBAR_GRADIENT_COLORS, colors)
&& Arrays.equals(FEED_ORIGINAL_SEEKBAR_GRADIENT_POSITIONS, positions))) {
Arrays.fill(colors, hideSeekbar
? 0x00000000
: seekbarColor);
return;
}
Logger.printDebug(() -> "Ignoring gradient colors: " + Arrays.toString(colors)
Logger.printDebug(() -> "Ignoring gradient colors: " + colorArrayToHex(colors)
+ " positions: " + Arrays.toString(positions));
}
}