diff --git a/app/src/main/java/app/revanced/integrations/patches/DisableSuggestedVideoEndScreenPatch.java b/app/src/main/java/app/revanced/integrations/patches/DisableSuggestedVideoEndScreenPatch.java index 9f435818..6a5c3ca3 100644 --- a/app/src/main/java/app/revanced/integrations/patches/DisableSuggestedVideoEndScreenPatch.java +++ b/app/src/main/java/app/revanced/integrations/patches/DisableSuggestedVideoEndScreenPatch.java @@ -1,13 +1,26 @@ package app.revanced.integrations.patches; +import android.annotation.SuppressLint; +import android.view.View; +import android.view.ViewGroup; import android.widget.ImageView; import app.revanced.integrations.settings.SettingsEnum; /** @noinspection unused*/ public final class DisableSuggestedVideoEndScreenPatch { - public static void closeEndScreen(ImageView imageView) { + @SuppressLint("StaticFieldLeak") + private static View lastView; + + public static void closeEndScreen(final ImageView imageView) { if (!SettingsEnum.DISABLE_SUGGESTED_VIDEO_END_SCREEN.getBoolean()) return; - imageView.performClick(); + // Get the 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; + + lastView = (ViewGroup)parent; + lastView.addOnLayoutChangeListener((view, i, i1, i2, i3, i4, i5, i6, i7) -> imageView.performClick()); } }