mirror of
https://github.com/revanced/revanced-integrations.git
synced 2025-01-05 17:45:49 +01:00
refactor: Simplify filtering a component
This commit is contained in:
parent
f451d67dcb
commit
25f73eb3a9
@ -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);
|
||||
}
|
||||
|
||||
|
@ -85,18 +85,6 @@ class StringFilterGroup extends FilterGroup<String> {
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -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
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user