fix(YouTube - Disable suggested video end screen): Hide the view once possible

Previously the patch tried to hide the screen when it was not visible to begin with.
This commit is contained in:
oSumAtrIX 2023-10-25 18:52:23 +02:00
parent 21bccf6a99
commit df278222e8
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4

View File

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