mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-21 00:37:18 +02:00
fix(YouTube Music - Dark theme): Gradient applied to wrong image
This commit is contained in:
parent
07d31c08e9
commit
bcc9547b5f
@ -2,12 +2,12 @@ package app.revanced.extension.music.patches.utils;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import app.revanced.extension.shared.utils.ResourceUtils;
|
||||
import app.revanced.extension.shared.utils.Utils;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class DrawableColorPatch {
|
||||
@ -22,6 +22,8 @@ public class DrawableColorPatch {
|
||||
ResourceUtils.getDrawable("revanced_header_gradient");
|
||||
private static final int blackColor =
|
||||
ResourceUtils.getColor("yt_black1");
|
||||
private static final int elementsContainerIdentifier =
|
||||
ResourceUtils.getIdIdentifier("elements_container");
|
||||
|
||||
public static int getLithoColor(int originalValue) {
|
||||
return ArrayUtils.contains(DARK_VALUES, originalValue)
|
||||
@ -30,15 +32,19 @@ public class DrawableColorPatch {
|
||||
}
|
||||
|
||||
public static void setHeaderGradient(ViewGroup viewGroup) {
|
||||
viewGroup.getViewTreeObserver().addOnGlobalLayoutListener(() -> Utils.runOnMainThreadDelayed(() -> {
|
||||
if (!(viewGroup.getChildAt(0) instanceof ViewGroup parentViewGroup))
|
||||
viewGroup.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
|
||||
if (!(viewGroup instanceof FrameLayout frameLayout))
|
||||
return;
|
||||
if (!(frameLayout.getChildAt(0) instanceof ViewGroup parentViewGroup))
|
||||
return;
|
||||
if (!(parentViewGroup.getChildAt(0) instanceof ImageView gradientView))
|
||||
return;
|
||||
if (headerGradient != null) {
|
||||
// For some reason, it sometimes applies to other lithoViews.
|
||||
// To prevent this, check the viewId before applying the gradient.
|
||||
if (headerGradient != null && viewGroup.getId() == elementsContainerIdentifier) {
|
||||
gradientView.setForeground(headerGradient);
|
||||
}
|
||||
}, 0));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,8 @@ private val darkThemeBytecodePatch = bytecodePatch(
|
||||
execute {
|
||||
addDrawableColorHook("$EXTENSION_CLASS_DESCRIPTOR->getLithoColor(I)I")
|
||||
|
||||
// The images in the playlist and album headers have a black gradient (probably applied server-side).
|
||||
// Applies a new gradient to the images in the playlist and album headers.
|
||||
elementsContainerFingerprint.methodOrThrow().apply {
|
||||
val index = indexOfFirstInstructionReversedOrThrow(Opcode.CHECK_CAST)
|
||||
val register = getInstruction<OneRegisterInstruction>(index).registerA
|
||||
@ -63,7 +65,7 @@ private val darkThemeBytecodePatch = bytecodePatch(
|
||||
|
||||
val DARK_COLOR = arrayOf(
|
||||
"yt_black0", "yt_black1", "yt_black1_opacity95", "yt_black1_opacity98",
|
||||
"yt_black2", "yt_black3", "yt_black4","yt_black_pure",
|
||||
"yt_black2", "yt_black3", "yt_black4", "yt_black_pure",
|
||||
"yt_black_pure_opacity80", "yt_status_bar_background_dark",
|
||||
"ytm_color_grey_12", "material_grey_800", "material_grey_850",
|
||||
)
|
||||
|
@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="material_grey_50">@android:color/system_neutral1_900</color>
|
||||
<color name="material_grey_100">@android:color/system_neutral1_900</color>
|
||||
<color name="material_grey_600">@android:color/system_neutral1_900</color>
|
||||
<color name="material_grey_800">@android:color/system_neutral1_900</color>
|
||||
<color name="material_grey_850">@android:color/system_neutral1_900</color>
|
||||
<color name="material_grey_900">@android:color/system_neutral1_900</color>
|
||||
<color name="yt_black0">@android:color/system_neutral1_900</color>
|
||||
<color name="yt_black1">@android:color/system_neutral1_900</color>
|
||||
<color name="yt_black1_opacity95">@android:color/system_neutral1_900</color>
|
||||
<color name="yt_black1_opacity98">@android:color/system_neutral1_900</color>
|
||||
<color name="yt_black2">@android:color/system_neutral1_900</color>
|
||||
<color name="yt_black3">@android:color/system_neutral1_900</color>
|
||||
<color name="yt_black4">@android:color/system_neutral1_900</color>
|
||||
<color name="yt_black_pure">@android:color/system_neutral1_900</color>
|
||||
<color name="yt_black_pure_opacity80">@android:color/system_neutral1_900</color>
|
||||
<color name="yt_status_bar_background_dark">@android:color/system_neutral1_900</color>
|
||||
<color name="ytm_color_grey_12">@android:color/system_neutral1_900</color>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user