fix(YouTube - Disable suggested end screen): Reliably hide end screen

This commit is contained in:
oSumAtrIX 2024-02-25 19:27:02 +01:00
parent b40687c5c7
commit b4ab5f65d5
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4

View File

@ -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();
});
}
}