From bf82e0219fff0eb8512adf270f43d129a62a31ac Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Mon, 3 Oct 2022 13:40:05 +0200 Subject: [PATCH] feat: `hide-video-buttons` patch --- .../patches/LithoFilterPatch.java | 59 ++++++++++++++++++- .../integrations/settings/SettingsEnum.java | 7 +++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/app/revanced/integrations/patches/LithoFilterPatch.java b/app/src/main/java/app/revanced/integrations/patches/LithoFilterPatch.java index 7bbd2a58..c4bc4187 100644 --- a/app/src/main/java/app/revanced/integrations/patches/LithoFilterPatch.java +++ b/app/src/main/java/app/revanced/integrations/patches/LithoFilterPatch.java @@ -115,7 +115,8 @@ final class LithoBlockRegister implements Iterable { public final class LithoFilterPatch { private static final Filter[] filters = new Filter[]{ - new GeneralBytecodeAdsPatch() + new GeneralBytecodeAdsPatch(), + new ButtonsPatch() }; public static boolean filter(final StringBuilder pathBuilder, final String identifier) { @@ -132,6 +133,62 @@ public final class LithoFilterPatch { } } +final class ButtonsPatch extends Filter { + private final BlockRule actionButtonsRule; + private final BlockRule dislikeRule; + private final BlockRule actionBarRule; + + private final BlockRule[] rules; + + public ButtonsPatch() { + BlockRule like = new BlockRule(SettingsEnum.HIDE_LIKE_BUTTON, "|like_button"); + dislikeRule = new BlockRule(SettingsEnum.HIDE_DISLIKE_BUTTON, "dislike_button"); + BlockRule download = new BlockRule(SettingsEnum.HIDE_DOWNLOAD_BUTTON, "download_button"); + actionButtonsRule = new BlockRule(SettingsEnum.HIDE_ACTION_BUTTON, "ContainerType|video_action_button"); + BlockRule playlist = new BlockRule(SettingsEnum.HIDE_PLAYLIST_BUTTON, "save_to_playlist_button"); + rules = new BlockRule[]{like, dislikeRule, download, actionButtonsRule, playlist}; + + actionBarRule = new BlockRule(null, "video_action_bar"); + + this.register.registerAll( + like, + dislikeRule, + download, + playlist + ); + } + + private boolean hideActionBar() { + for (BlockRule rule : rules) if (!rule.isEnabled()) return false; + return true; + } + + @Override + public boolean filter(final String path, final String identifier) { + if (hideActionBar() && actionBarRule.check(identifier).isBlocked()) return true; + + var currentIsActionButton = actionButtonsRule.check(path).isBlocked(); + + if (dislikeRule.check(path).isBlocked()) ActionButton.doNotBlockCounter = 4; + + if (currentIsActionButton && ActionButton.doNotBlockCounter-- > 0) { + if (SettingsEnum.HIDE_SHARE_BUTTON.getBoolean()) { + LogHelper.debug(ButtonsPatch.class, "Hiding share button"); + return true; + } else return false; + } + + if ((currentIsActionButton && ActionButton.doNotBlockCounter <= 0 && actionButtonsRule.isEnabled()) || Extensions.any(register, path)) { + LogHelper.debug(ButtonsPatch.class, "Blocked: " + path); + return true; + } else return false; + } + + static class ActionButton { + public static int doNotBlockCounter = 4; + } +} + class GeneralBytecodeAdsPatch extends Filter { private final BlockRule identifierBlock; diff --git a/app/src/main/java/app/revanced/integrations/settings/SettingsEnum.java b/app/src/main/java/app/revanced/integrations/settings/SettingsEnum.java index 2311f237..4c227dcd 100644 --- a/app/src/main/java/app/revanced/integrations/settings/SettingsEnum.java +++ b/app/src/main/java/app/revanced/integrations/settings/SettingsEnum.java @@ -45,6 +45,13 @@ public enum SettingsEnum { ADREMOVER_SUGGESTIONS_REMOVAL("revanced_adremover_hide_suggestions", true, ReturnType.BOOLEAN, true), ADREMOVER_HIDE_LATEST_POSTS("revanced_adremover_hide_latest_posts", true, ReturnType.BOOLEAN, true), ADREMOVER_HIDE_CHANNEL_GUIDELINES("revanced_adremover_hide_channel_guidelines", true, ReturnType.BOOLEAN, true), + // Buttons + HIDE_LIKE_BUTTON("revanced_like_button", false, ReturnType.BOOLEAN, false), + HIDE_DISLIKE_BUTTON("revanced_dislike_button", false, ReturnType.BOOLEAN, false), + HIDE_DOWNLOAD_BUTTON("revanced_download_button", false, ReturnType.BOOLEAN, false), + HIDE_PLAYLIST_BUTTON("revanced_playlist_button", false, ReturnType.BOOLEAN, false), + HIDE_ACTION_BUTTON("revanced_action_button", false, ReturnType.BOOLEAN, false), + HIDE_SHARE_BUTTON("revanced_share_button", false, ReturnType.BOOLEAN, false), //Layout settings REEL_BUTTON_SHOWN("revanced_reel_button_enabled", false, ReturnType.BOOLEAN, true),