From bcc9547b5fb3a077b575b747e017ae6c34864e00 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:02:07 +0900 Subject: [PATCH] fix(YouTube Music - Dark theme): Gradient applied to wrong image --- .../patches/utils/DrawableColorPatch.java | 16 ++++++++++----- .../music/layout/theme/DarkThemePatch.kt | 4 +++- .../materialyou/host/values-v31/colors.xml | 20 ------------------- 3 files changed, 14 insertions(+), 26 deletions(-) delete mode 100644 patches/src/main/resources/music/materialyou/host/values-v31/colors.xml 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 febdf3cb3..1c79d233d 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 @@ -2,12 +2,12 @@ package app.revanced.extension.music.patches.utils; import android.graphics.drawable.Drawable; import android.view.ViewGroup; +import android.widget.FrameLayout; import android.widget.ImageView; import org.apache.commons.lang3.ArrayUtils; import app.revanced.extension.shared.utils.ResourceUtils; -import app.revanced.extension.shared.utils.Utils; @SuppressWarnings("unused") public class DrawableColorPatch { @@ -22,6 +22,8 @@ public class DrawableColorPatch { ResourceUtils.getDrawable("revanced_header_gradient"); private static final int blackColor = ResourceUtils.getColor("yt_black1"); + private static final int elementsContainerIdentifier = + ResourceUtils.getIdIdentifier("elements_container"); public static int getLithoColor(int originalValue) { return ArrayUtils.contains(DARK_VALUES, originalValue) @@ -30,15 +32,19 @@ public class DrawableColorPatch { } public static void setHeaderGradient(ViewGroup viewGroup) { - viewGroup.getViewTreeObserver().addOnGlobalLayoutListener(() -> Utils.runOnMainThreadDelayed(() -> { - if (!(viewGroup.getChildAt(0) instanceof ViewGroup parentViewGroup)) + viewGroup.getViewTreeObserver().addOnGlobalLayoutListener(() -> { + if (!(viewGroup instanceof FrameLayout frameLayout)) + return; + if (!(frameLayout.getChildAt(0) instanceof ViewGroup parentViewGroup)) return; if (!(parentViewGroup.getChildAt(0) instanceof ImageView gradientView)) return; - if (headerGradient != null) { + // 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)); + }); } } diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/theme/DarkThemePatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/theme/DarkThemePatch.kt index c13c3e7e7..45f85b967 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/theme/DarkThemePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/theme/DarkThemePatch.kt @@ -42,6 +42,8 @@ private val darkThemeBytecodePatch = bytecodePatch( execute { addDrawableColorHook("$EXTENSION_CLASS_DESCRIPTOR->getLithoColor(I)I") + // The images in the playlist and album headers have a black gradient (probably applied server-side). + // Applies a new gradient to the images in the playlist and album headers. elementsContainerFingerprint.methodOrThrow().apply { val index = indexOfFirstInstructionReversedOrThrow(Opcode.CHECK_CAST) val register = getInstruction(index).registerA @@ -63,7 +65,7 @@ private val darkThemeBytecodePatch = bytecodePatch( val DARK_COLOR = arrayOf( "yt_black0", "yt_black1", "yt_black1_opacity95", "yt_black1_opacity98", - "yt_black2", "yt_black3", "yt_black4","yt_black_pure", + "yt_black2", "yt_black3", "yt_black4", "yt_black_pure", "yt_black_pure_opacity80", "yt_status_bar_background_dark", "ytm_color_grey_12", "material_grey_800", "material_grey_850", ) diff --git a/patches/src/main/resources/music/materialyou/host/values-v31/colors.xml b/patches/src/main/resources/music/materialyou/host/values-v31/colors.xml deleted file mode 100644 index 16d8f326d..000000000 --- a/patches/src/main/resources/music/materialyou/host/values-v31/colors.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - @android:color/system_neutral1_900 - @android:color/system_neutral1_900 - @android:color/system_neutral1_900 - @android:color/system_neutral1_900 - @android:color/system_neutral1_900 - @android:color/system_neutral1_900 - @android:color/system_neutral1_900 - @android:color/system_neutral1_900 - @android:color/system_neutral1_900 - @android:color/system_neutral1_900 - @android:color/system_neutral1_900 - @android:color/system_neutral1_900 - @android:color/system_neutral1_900 - @android:color/system_neutral1_900 - @android:color/system_neutral1_900 - @android:color/system_neutral1_900 - @android:color/system_neutral1_900 -