refactor: Simplify filtering a component

This commit is contained in:
oSumAtrIX 2023-10-02 22:05:31 +02:00
parent f451d67dcb
commit 25f73eb3a9
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
3 changed files with 4 additions and 20 deletions

View File

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

View File

@ -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) {

View File

@ -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
*/