From 5a5e8824c5ec9665819605ed55ec9fd020b82333 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sun, 17 Jul 2022 15:58:13 +0200 Subject: [PATCH] fix: `old-quality-layout` patch --- .../patches/OldQualityLayoutPatch.java | 40 +++++++++++++++++++ .../patches/OldStyleQualityPatch.java | 11 ----- 2 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/app/revanced/integrations/patches/OldQualityLayoutPatch.java delete mode 100644 app/src/main/java/app/revanced/integrations/patches/OldStyleQualityPatch.java diff --git a/app/src/main/java/app/revanced/integrations/patches/OldQualityLayoutPatch.java b/app/src/main/java/app/revanced/integrations/patches/OldQualityLayoutPatch.java new file mode 100644 index 0000000000..6fe8993dd7 --- /dev/null +++ b/app/src/main/java/app/revanced/integrations/patches/OldQualityLayoutPatch.java @@ -0,0 +1,40 @@ +package app.revanced.integrations.patches; + +import android.os.Handler; +import android.os.Looper; +import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ListView; +import android.widget.RelativeLayout; + +import java.util.Arrays; + +import app.revanced.integrations.settings.SettingsEnum; +import app.revanced.integrations.utils.LogHelper; + +public class OldQualityLayoutPatch { + // TODO: hide listView, OnHierarchyChange will not be triggered though + public static void showOldQualityMenu(ListView listView) + { + if (!SettingsEnum.OLD_STYLE_QUALITY_SETTINGS.getBoolean()) return; + + listView.setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() { + @Override + public void onChildViewAdded(View parent, View child) { + LogHelper.debug(OldQualityLayoutPatch.class, "Added: " + child); + + final var indexOfAdvancedQualityMenuItem = 4; + if (listView.indexOfChild(child) != indexOfAdvancedQualityMenuItem) return; + + LogHelper.debug(OldQualityLayoutPatch.class, "Found advanced menu: " + child); + + final var qualityItemMenuPosition = 4; + listView.performItemClick(null, qualityItemMenuPosition, 0); + } + + @Override + public void onChildViewRemoved(View parent, View child) {} + }); + } +} diff --git a/app/src/main/java/app/revanced/integrations/patches/OldStyleQualityPatch.java b/app/src/main/java/app/revanced/integrations/patches/OldStyleQualityPatch.java deleted file mode 100644 index c4f138a859..0000000000 --- a/app/src/main/java/app/revanced/integrations/patches/OldStyleQualityPatch.java +++ /dev/null @@ -1,11 +0,0 @@ -package app.revanced.integrations.patches; - -import app.revanced.integrations.settings.SettingsEnum; - -public class OldStyleQualityPatch { - - //Used by app.revanced.patches.youtube.layout.oldqualitylayout.patch.OldQualityLayoutPatch - public static boolean useOldStyleQualitySettings() { - return SettingsEnum.OLD_STYLE_QUALITY_SETTINGS.getBoolean(); - } -}