mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-11-27 14:26:49 +01:00
fix(YouTube - Disable suggested end screen): Reliably hide end screen
This commit is contained in:
parent
b40687c5c7
commit
b4ab5f65d5
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user