From 25f73eb3a93699301d1211c306b7f4a896377b5e Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Mon, 2 Oct 2023 22:05:31 +0200 Subject: [PATCH] refactor: Simplify filtering a component --- .../patches/components/LayoutComponentsFilter.java | 6 ++++-- .../patches/components/LithoFilterPatch.java | 12 ------------ .../revanced/integrations/utils/ReVancedUtils.java | 6 ------ 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/patches/components/LayoutComponentsFilter.java b/app/src/main/java/app/revanced/integrations/patches/components/LayoutComponentsFilter.java index d03ccbb0..e197d4c8 100644 --- a/app/src/main/java/app/revanced/integrations/patches/components/LayoutComponentsFilter.java +++ b/app/src/main/java/app/revanced/integrations/patches/components/LayoutComponentsFilter.java @@ -19,6 +19,7 @@ public final class LayoutComponentsFilter extends Filter { SettingsEnum.HIDE_MIX_PLAYLISTS, "&list=" ); + private final StringFilterGroup searchResultShelfHeader; @RequiresApi(api = Build.VERSION_CODES.N) public LayoutComponentsFilter() { @@ -152,7 +153,7 @@ public final class LayoutComponentsFilter extends Filter { "timed_reaction" ); - final var searchResultShelfHeader = new StartsWithStringFilterGroup( + searchResultShelfHeader = new StringFilterGroup( SettingsEnum.HIDE_SEARCH_RESULT_SHELF_HEADER, "shelf_header.eml" ); @@ -194,7 +195,6 @@ public final class LayoutComponentsFilter extends Filter { artistCard, timedReactions, imageShelf, - searchResultShelfHeader, channelMemberShelf, custom ); @@ -211,6 +211,8 @@ public final class LayoutComponentsFilter extends Filter { if (matchedGroup != custom && exceptions.matches(path)) return false; // Exceptions are not filtered. + if (matchedGroup == searchResultShelfHeader && matchedIndex == 0) return true; + return super.isFiltered(identifier, path, protobufBufferArray, matchedList, matchedGroup, matchedIndex); } diff --git a/app/src/main/java/app/revanced/integrations/patches/components/LithoFilterPatch.java b/app/src/main/java/app/revanced/integrations/patches/components/LithoFilterPatch.java index da030a37..7cfe060b 100644 --- a/app/src/main/java/app/revanced/integrations/patches/components/LithoFilterPatch.java +++ b/app/src/main/java/app/revanced/integrations/patches/components/LithoFilterPatch.java @@ -85,18 +85,6 @@ class StringFilterGroup extends FilterGroup { } } -class StartsWithStringFilterGroup extends StringFilterGroup { - - public StartsWithStringFilterGroup(final SettingsEnum setting, final String... filters) { - super(setting, filters); - } - - @Override - public FilterGroupResult check(final String string) { - return new FilterGroupResult(setting, isEnabled() && ReVancedUtils.startsWithAny(string, filters)); - } -} - final class CustomFilterGroup extends StringFilterGroup { public CustomFilterGroup(final SettingsEnum setting, final SettingsEnum filter) { diff --git a/app/src/main/java/app/revanced/integrations/utils/ReVancedUtils.java b/app/src/main/java/app/revanced/integrations/utils/ReVancedUtils.java index a145bbfc..940dd508 100644 --- a/app/src/main/java/app/revanced/integrations/utils/ReVancedUtils.java +++ b/app/src/main/java/app/revanced/integrations/utils/ReVancedUtils.java @@ -88,12 +88,6 @@ public class ReVancedUtils { return false; } - public static boolean startsWithAny(@NonNull String value, @NonNull String... targets) { - for (String string : targets) - if (!string.isEmpty() && value.startsWith(string)) return true; - return false; - } - /** * @return zero, if the resource is not found */