From b4ab5f65d5607678a000783aae14257b845706b5 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sun, 25 Feb 2024 19:27:02 +0100 Subject: [PATCH] fix(YouTube - Disable suggested end screen): Reliably hide end screen --- .../DisableSuggestedVideoEndScreenPatch.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/DisableSuggestedVideoEndScreenPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/DisableSuggestedVideoEndScreenPatch.java index 3ceea0cc..0b7897ba 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/DisableSuggestedVideoEndScreenPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/DisableSuggestedVideoEndScreenPatch.java @@ -3,29 +3,27 @@ package app.revanced.integrations.youtube.patches; import android.annotation.SuppressLint; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.widget.ImageView; +import androidx.annotation.NonNull; +import app.revanced.integrations.shared.Logger; import app.revanced.integrations.youtube.settings.Settings; /** @noinspection unused*/ public final class DisableSuggestedVideoEndScreenPatch { @SuppressLint("StaticFieldLeak") - private static View lastView; + private static ImageView lastView; public static void closeEndScreen(final ImageView imageView) { if (!Settings.DISABLE_SUGGESTED_VIDEO_END_SCREEN.get()) return; - // Get a parent view which can be listened to for layout changes. - final var parent = imageView.getParent().getParent(); - // Prevent adding the listener multiple times. - if (lastView == parent) return; + if (lastView == imageView) return; + lastView = imageView; - lastView = (ViewGroup)parent; - lastView.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> { - // Disable sound effects to prevent the click sound. - imageView.setSoundEffectsEnabled(false); - imageView.performClick(); + imageView.getViewTreeObserver().addOnGlobalLayoutListener(() -> { + if (imageView.isShown()) imageView.callOnClick(); }); } }