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;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
@ -35,16 +36,28 @@ public class DrawableColorPatch {
viewGroup.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
if (!(viewGroup instanceof FrameLayout frameLayout))
return;
if (!(frameLayout.getChildAt(0) instanceof ViewGroup parentViewGroup))
return;
if (!(parentViewGroup.getChildAt(0) instanceof ImageView gradientView))
if (!(frameLayout.getChildAt(0) instanceof ViewGroup firstChildView))
return;
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);
}
});
}
}