fix(YouTube - Disable suggested video end screen): Do not spam click to disable the screen

This commit is contained in:
oSumAtrIX 2023-11-06 23:23:05 +01:00
parent e94de61eb0
commit 4f57d56042
1 changed files with 12 additions and 2 deletions

View File

@ -14,13 +14,23 @@ public final class DisableSuggestedVideoEndScreenPatch {
public static void closeEndScreen(final ImageView imageView) {
if (!SettingsEnum.DISABLE_SUGGESTED_VIDEO_END_SCREEN.getBoolean()) return;
// Get the view which can be listened to for layout changes.
// 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;
lastView = (ViewGroup)parent;
lastView.addOnLayoutChangeListener((view, i, i1, i2, i3, i4, i5, i6, i7) -> imageView.performClick());
lastView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
int oldRight, int oldBottom) {
// Disable sound effects to prevent the click sound.
imageView.performClick();
// Remove the listener to prevent it from being called multiple times.
lastView.removeOnLayoutChangeListener(this);
}
});
}
}