From d4736e6dc61298552daec029c72717b9ad7b6dbc Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Thu, 16 Jan 2025 12:08:05 +0900 Subject: [PATCH] fix(YouTube Music - Dark theme): Gradient not applied to playlist header background --- .../patches/utils/DrawableColorPatch.java | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 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 1c79d233d..beccf6178 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 @@ -1,6 +1,7 @@ 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; @@ -35,17 +36,29 @@ public class DrawableColorPatch { viewGroup.getViewTreeObserver().addOnGlobalLayoutListener(() -> { if (!(viewGroup instanceof FrameLayout frameLayout)) return; - if (!(frameLayout.getChildAt(0) instanceof ViewGroup parentViewGroup)) + if (!(frameLayout.getChildAt(0) instanceof ViewGroup firstChildView)) return; - if (!(parentViewGroup.getChildAt(0) instanceof ImageView gradientView)) - return; - // 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); + View secondChildView = firstChildView.getChildAt(0); + + if (secondChildView instanceof ImageView gradientView) { + // Album + setHeaderGradient(viewGroup, gradientView); + } else if (secondChildView instanceof ViewGroup thirdChildView && + thirdChildView.getChildCount() == 1 && + thirdChildView.getChildAt(0) instanceof ImageView gradientView) { + // Playlist + setHeaderGradient(viewGroup, gradientView); } }); } + + 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) { + gradientView.setForeground(headerGradient); + } + } }