fix(YouTube Music - Dark theme): Gradient not applied to playlist header background

This commit is contained in:
inotia00 2025-01-16 12:08:05 +09:00
parent 44600d9525
commit d4736e6dc6

View File

@ -1,6 +1,7 @@
package app.revanced.extension.music.patches.utils; package app.revanced.extension.music.patches.utils;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
@ -35,17 +36,29 @@ public class DrawableColorPatch {
viewGroup.getViewTreeObserver().addOnGlobalLayoutListener(() -> { viewGroup.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
if (!(viewGroup instanceof FrameLayout frameLayout)) if (!(viewGroup instanceof FrameLayout frameLayout))
return; return;
if (!(frameLayout.getChildAt(0) instanceof ViewGroup parentViewGroup)) if (!(frameLayout.getChildAt(0) instanceof ViewGroup firstChildView))
return; return;
if (!(parentViewGroup.getChildAt(0) instanceof ImageView gradientView)) View secondChildView = firstChildView.getChildAt(0);
return;
// For some reason, it sometimes applies to other lithoViews. if (secondChildView instanceof ImageView gradientView) {
// To prevent this, check the viewId before applying the gradient. // Album
if (headerGradient != null && viewGroup.getId() == elementsContainerIdentifier) { setHeaderGradient(viewGroup, gradientView);
gradientView.setForeground(headerGradient); } 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);
}
}
} }