Skip to content

Commit

Permalink
fix(YouTube Music - Dark theme): Gradient not applied to playlist hea…
Browse files Browse the repository at this point in the history
…der background
  • Loading branch information
inotia00 authored and anddea committed Jan 16, 2025
1 parent 082e385 commit e5f4a98
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -35,17 +36,29 @@ public static void setHeaderGradient(ViewGroup viewGroup) {
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);
}
}
}


0 comments on commit e5f4a98

Please sign in to comment.