refactor: improve readability with comments

This commit is contained in:
oSumAtrIX 2023-08-23 05:27:29 +02:00
parent 842f5f7616
commit 33e3c6b061
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4

View File

@ -9,22 +9,21 @@ import app.revanced.integrations.settings.SettingsEnum;
@RequiresApi(api = Build.VERSION_CODES.N) @RequiresApi(api = Build.VERSION_CODES.N)
final class ButtonsFilter extends Filter { final class ButtonsFilter extends Filter {
private static final String VIDEO_ACTION_BAR_PATH = "video_action_bar.eml"; private static final String VIDEO_ACTION_BAR_PATH = "video_action_bar.eml";
private final StringFilterGroup actionBarRule; private final StringFilterGroup actionBarGroup;
private final StringFilterGroup bufferFilterPathRule; private final StringFilterGroup bufferFilterPathGroup;
private final ByteArrayFilterGroupList bufferButtonsGroupList = new ByteArrayFilterGroupList(); private final ByteArrayFilterGroupList bufferButtonsGroupList = new ByteArrayFilterGroupList();
public ButtonsFilter() { public ButtonsFilter() {
actionBarRule = new StringFilterGroup( actionBarGroup = new StringFilterGroup(
null, null,
VIDEO_ACTION_BAR_PATH VIDEO_ACTION_BAR_PATH
); );
identifierFilterGroups.addAll(actionBarRule); identifierFilterGroups.addAll(actionBarGroup);
bufferFilterPathRule = new StringFilterGroup( bufferFilterPathGroup = new StringFilterGroup(
null, null,
"|CellType|CollectionType|CellType|ContainerType|button.eml|" "|CellType|CollectionType|CellType|ContainerType|button.eml|"
); );
@ -45,7 +44,7 @@ final class ButtonsFilter extends Filter {
SettingsEnum.HIDE_CLIP_BUTTON, SettingsEnum.HIDE_CLIP_BUTTON,
"|clip_button.eml|" "|clip_button.eml|"
), ),
bufferFilterPathRule bufferFilterPathGroup
); );
bufferButtonsGroupList.addAll( bufferButtonsGroupList.addAll(
@ -83,11 +82,11 @@ final class ButtonsFilter extends Filter {
} }
private boolean isEveryFilterGroupEnabled() { private boolean isEveryFilterGroupEnabled() {
for (FilterGroup rule : pathFilterGroups) for (var group : pathFilterGroups)
if (!rule.isEnabled()) return false; if (!group.isEnabled()) return false;
for (FilterGroup rule : bufferButtonsGroupList) for (var group : bufferButtonsGroupList)
if (!rule.isEnabled()) return false; if (!group.isEnabled()) return false;
return true; return true;
} }
@ -95,17 +94,19 @@ final class ButtonsFilter extends Filter {
@Override @Override
public boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBufferArray, public boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBufferArray,
FilterGroupList matchedList, FilterGroup matchedGroup, int matchedIndex) { FilterGroupList matchedList, FilterGroup matchedGroup, int matchedIndex) {
if (matchedGroup == actionBarRule) { // If the current matched group is the action bar group,
// in case every filter group is enabled, hide the action bar.
if (matchedGroup == actionBarGroup) {
if (!isEveryFilterGroupEnabled()) { if (!isEveryFilterGroupEnabled()) {
return false; return false;
} }
} else if (matchedGroup == bufferFilterPathRule) { } else if (matchedGroup == bufferFilterPathGroup) {
if (!path.startsWith(VIDEO_ACTION_BAR_PATH)) { // Make sure the current path is the right one
return false; // Some other unknown button and not part of the player action buttons. // to avoid false positives.
} if (!path.startsWith(VIDEO_ACTION_BAR_PATH)) return false;
if (!bufferButtonsGroupList.check(protobufBufferArray).isFiltered()) {
return false; // Action button is not set to hide. // In case the group list has no match, return false.
} if (!bufferButtonsGroupList.check(protobufBufferArray).isFiltered()) return false;
} }
return super.isFiltered(identifier, path, protobufBufferArray, matchedList, matchedGroup, matchedIndex); return super.isFiltered(identifier, path, protobufBufferArray, matchedList, matchedGroup, matchedIndex);