From d3d074e34f644bb1c80fa4ad2c28dae1cc1eef03 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Wed, 29 Jan 2025 18:58:28 +0900 Subject: [PATCH] fix(YouTube Music - Dark theme): Gradient layer overlaps --- .../music/patches/utils/DrawableColorPatch.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/extensions/shared/src/main/java/app/revanced/extension/music/patches/utils/DrawableColorPatch.java b/extensions/shared/src/main/java/app/revanced/extension/music/patches/utils/DrawableColorPatch.java index 18da455ad..599eac586 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/music/patches/utils/DrawableColorPatch.java +++ b/extensions/shared/src/main/java/app/revanced/extension/music/patches/utils/DrawableColorPatch.java @@ -3,11 +3,11 @@ package app.revanced.extension.music.patches.utils; import android.graphics.drawable.Drawable; import android.view.View; import android.view.ViewGroup; -import android.widget.FrameLayout; import android.widget.ImageView; import org.apache.commons.lang3.ArrayUtils; +import app.revanced.extension.shared.utils.Logger; import app.revanced.extension.shared.utils.ResourceUtils; @SuppressWarnings("unused") @@ -34,9 +34,7 @@ public class DrawableColorPatch { public static void setHeaderGradient(ViewGroup viewGroup) { viewGroup.getViewTreeObserver().addOnGlobalLayoutListener(() -> { - if (!(viewGroup instanceof FrameLayout frameLayout)) - return; - if (!(frameLayout.getChildAt(0) instanceof ViewGroup firstChildView)) + if (!(viewGroup.getChildAt(0) instanceof ViewGroup firstChildView)) return; View secondChildView = firstChildView.getChildAt(0); @@ -55,7 +53,11 @@ public class DrawableColorPatch { private static void setHeaderGradient(ViewGroup viewGroup, ImageView gradientView) { // 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) { + if (gradientView.getForeground() == null && headerGradient != null && viewGroup.getId() == elementsContainerIdentifier) { + viewGroup.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); + gradientView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); + Logger.printDebug(() -> "set header gradient.\nviewGroup measured width: " + viewGroup.getMeasuredWidth() + ", gradientView measured width: " + gradientView.getMeasuredWidth()); + gradientView.setForeground(headerGradient); } }