mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-11-30 15:52:55 +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.annotation.SuppressLint;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import app.revanced.integrations.shared.Logger;
|
||||||
import app.revanced.integrations.youtube.settings.Settings;
|
import app.revanced.integrations.youtube.settings.Settings;
|
||||||
|
|
||||||
/** @noinspection unused*/
|
/** @noinspection unused*/
|
||||||
public final class DisableSuggestedVideoEndScreenPatch {
|
public final class DisableSuggestedVideoEndScreenPatch {
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
private static View lastView;
|
private static ImageView lastView;
|
||||||
|
|
||||||
public static void closeEndScreen(final ImageView imageView) {
|
public static void closeEndScreen(final ImageView imageView) {
|
||||||
if (!Settings.DISABLE_SUGGESTED_VIDEO_END_SCREEN.get()) return;
|
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.
|
// Prevent adding the listener multiple times.
|
||||||
if (lastView == parent) return;
|
if (lastView == imageView) return;
|
||||||
|
lastView = imageView;
|
||||||
|
|
||||||
lastView = (ViewGroup)parent;
|
imageView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
|
||||||
lastView.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
|
if (imageView.isShown()) imageView.callOnClick();
|
||||||
// Disable sound effects to prevent the click sound.
|
|
||||||
imageView.setSoundEffectsEnabled(false);
|
|
||||||
imageView.performClick();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user