feat(youtube): add hide-shorts-components patch

This commit is contained in:
oSumAtrIX 2023-05-10 01:04:38 +02:00
parent 5652c32345
commit 5ec90db28a
13 changed files with 202 additions and 118 deletions

View File

@ -8,6 +8,6 @@ import app.revanced.integrations.utils.ReVancedUtils;
public class HideAlbumCardsPatch { public class HideAlbumCardsPatch {
public static void hideAlbumCard(View view) { public static void hideAlbumCard(View view) {
if (!SettingsEnum.HIDE_ALBUM_CARDS.getBoolean()) return; if (!SettingsEnum.HIDE_ALBUM_CARDS.getBoolean()) return;
ReVancedUtils.HideViewByLayoutParams(view); ReVancedUtils.hideViewByLayoutParams(view);
} }
} }

View File

@ -24,6 +24,6 @@ public class HideBreakingNewsPatch {
public static void hideBreakingNews(View view) { public static void hideBreakingNews(View view) {
if (!SettingsEnum.HIDE_BREAKING_NEWS.getBoolean() if (!SettingsEnum.HIDE_BREAKING_NEWS.getBoolean()
|| isSpoofingOldVersionWithHorizontalCardListWatchHistory()) return; || isSpoofingOldVersionWithHorizontalCardListWatchHistory()) return;
ReVancedUtils.HideViewByLayoutParams(view); ReVancedUtils.hideViewByLayoutParams(view);
} }
} }

View File

@ -9,6 +9,6 @@ public class HideCrowdfundingBoxPatch {
//Used by app.revanced.patches.youtube.layout.hidecrowdfundingbox.patch.HideCrowdfundingBoxPatch //Used by app.revanced.patches.youtube.layout.hidecrowdfundingbox.patch.HideCrowdfundingBoxPatch
public static void hideCrowdfundingBox(View view) { public static void hideCrowdfundingBox(View view) {
if (!SettingsEnum.HIDE_CROWDFUNDING_BOX.getBoolean()) return; if (!SettingsEnum.HIDE_CROWDFUNDING_BOX.getBoolean()) return;
ReVancedUtils.HideViewByLayoutParams(view); ReVancedUtils.hideViewByLayoutParams(view);
} }
} }

View File

@ -14,7 +14,7 @@ public final class HideFilterBarPatch {
public static void hideInRelatedVideos(final View chipView) { public static void hideInRelatedVideos(final View chipView) {
if (!SettingsEnum.HIDE_FILTER_BAR_FEED_IN_RELATED_VIDEOS.getBoolean()) return; if (!SettingsEnum.HIDE_FILTER_BAR_FEED_IN_RELATED_VIDEOS.getBoolean()) return;
ReVancedUtils.HideViewByLayoutParams(chipView); ReVancedUtils.hideViewByLayoutParams(chipView);
} }
public static int hideInSearch(final int height) { public static int hideInSearch(final int height) {

View File

@ -8,6 +8,6 @@ import app.revanced.integrations.utils.ReVancedUtils;
public class HideLoadMoreButtonPatch { public class HideLoadMoreButtonPatch {
public static void hideLoadMoreButton(View view){ public static void hideLoadMoreButton(View view){
if(!SettingsEnum.HIDE_LOAD_MORE_BUTTON.getBoolean()) return; if(!SettingsEnum.HIDE_LOAD_MORE_BUTTON.getBoolean()) return;
ReVancedUtils.HideViewByLayoutParams(view); ReVancedUtils.hideViewByLayoutParams(view);
} }
} }

View File

@ -1,13 +0,0 @@
package app.revanced.integrations.patches;
import android.view.View;
import app.revanced.integrations.settings.SettingsEnum;
public class HideShortsCommentsButtonPatch {
//Used by app.revanced.patches.youtube.layout.comments.patch.CommentsPatch
public static void hideShortsCommentsButton(View view) {
if (!SettingsEnum.HIDE_SHORTS_COMMENTS_BUTTON.getBoolean()) return;
view.setVisibility(View.GONE);
}
}

View File

@ -1,19 +1,19 @@
package app.revanced.integrations.patches.litho; package app.revanced.integrations.patches.components;
import android.view.View; import android.view.View;
import app.revanced.integrations.adremover.AdRemoverAPI;
import app.revanced.integrations.settings.SettingsEnum; import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper; import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils; import app.revanced.integrations.utils.ReVancedUtils;
public final class AdsFilter extends Filter { public final class AdsFilter extends Filter {
private final String[] EXCEPTIONS; private final String[] exceptions;
private final CustomFilterGroup custom; private final CustomFilterGroup custom;
public AdsFilter() { public AdsFilter() {
EXCEPTIONS = new String[]{ exceptions = new String[]{
"home_video_with_context", "home_video_with_context",
"related_video_with_context", "related_video_with_context",
"comment_thread", // skip filtering anything in the comments "comment_thread", // skip filtering anything in the comments
@ -22,70 +22,70 @@ public final class AdsFilter extends Filter {
}; };
custom = new CustomFilterGroup( custom = new CustomFilterGroup(
SettingsEnum.ADREMOVER_CUSTOM_ENABLED, SettingsEnum.CUSTOM_FILTER,
SettingsEnum.ADREMOVER_CUSTOM_REMOVAL SettingsEnum.CUSTOM_FILTER_STRINGS
); );
final var communityPosts = new StringFilterGroup( final var communityPosts = new StringFilterGroup(
SettingsEnum.ADREMOVER_COMMUNITY_POSTS_REMOVAL, SettingsEnum.HIDE_COMMUNITY_POSTS,
"post_base_wrapper" "post_base_wrapper"
); );
final var communityGuidelines = new StringFilterGroup( final var communityGuidelines = new StringFilterGroup(
SettingsEnum.ADREMOVER_COMMUNITY_GUIDELINES_REMOVAL, SettingsEnum.HIDE_COMMUNITY_GUIDELINES,
"community_guidelines" "community_guidelines"
); );
final var subscribersCommunityGuidelines = new StringFilterGroup( final var subscribersCommunityGuidelines = new StringFilterGroup(
SettingsEnum.ADREMOVER_SUBSCRIBERS_COMMUNITY_GUIDELINES_REMOVAL, SettingsEnum.HIDE_SUBSCRIBERS_COMMUNITY_GUIDELINES,
"sponsorships_comments_upsell" "sponsorships_comments_upsell"
); );
final var channelMemberShelf = new StringFilterGroup( final var channelMemberShelf = new StringFilterGroup(
SettingsEnum.ADREMOVER_CHANNEL_MEMBER_SHELF_REMOVAL, SettingsEnum.HIDE_CHANNEL_MEMBER_SHELF,
"member_recognition_shelf" "member_recognition_shelf"
); );
final var compactBanner = new StringFilterGroup( final var compactBanner = new StringFilterGroup(
SettingsEnum.ADREMOVER_COMPACT_BANNER_REMOVAL, SettingsEnum.HIDE_COMPACT_BANNER,
"compact_banner" "compact_banner"
); );
final var inFeedSurvey = new StringFilterGroup( final var inFeedSurvey = new StringFilterGroup(
SettingsEnum.ADREMOVER_FEED_SURVEY_REMOVAL, SettingsEnum.HIDE_FEED_SURVEY,
"in_feed_survey", "in_feed_survey",
"slimline_survey" "slimline_survey"
); );
final var medicalPanel = new StringFilterGroup( final var medicalPanel = new StringFilterGroup(
SettingsEnum.ADREMOVER_MEDICAL_PANEL_REMOVAL, SettingsEnum.HIDE_MEDICAL_PANELS,
"medical_panel" "medical_panel"
); );
final var paidContent = new StringFilterGroup( final var paidContent = new StringFilterGroup(
SettingsEnum.ADREMOVER_PAID_CONTENT_REMOVAL, SettingsEnum.HIDE_PAID_CONTENT,
"paid_content_overlay" "paid_content_overlay"
); );
final var merchandise = new StringFilterGroup( final var merchandise = new StringFilterGroup(
SettingsEnum.ADREMOVER_MERCHANDISE_REMOVAL, SettingsEnum.HIDE_MERCHANDISE_BANNERS,
"product_carousel" "product_carousel"
); );
final var infoPanel = new StringFilterGroup( final var infoPanel = new StringFilterGroup(
SettingsEnum.ADREMOVER_INFO_PANEL_REMOVAL, SettingsEnum.HIDE_HIDE_INFO_PANELS,
"publisher_transparency_panel", "publisher_transparency_panel",
"single_item_information_panel" "single_item_information_panel"
); );
final var latestPosts = new StringFilterGroup( final var latestPosts = new StringFilterGroup(
SettingsEnum.ADREMOVER_HIDE_LATEST_POSTS, SettingsEnum.HIDE_HIDE_LATEST_POSTS,
"post_shelf" "post_shelf"
); );
final var channelGuidelines = new StringFilterGroup( final var channelGuidelines = new StringFilterGroup(
SettingsEnum.ADREMOVER_HIDE_CHANNEL_GUIDELINES, SettingsEnum.HIDE_HIDE_CHANNEL_GUIDELINES,
"channel_guidelines_entry_banner" "channel_guidelines_entry_banner"
); );
@ -100,54 +100,54 @@ public final class AdsFilter extends Filter {
); );
final var selfSponsor = new StringFilterGroup( final var selfSponsor = new StringFilterGroup(
SettingsEnum.ADREMOVER_SELF_SPONSOR_REMOVAL, SettingsEnum.HIDE_SELF_SPONSOR,
"cta_shelf_card" "cta_shelf_card"
); );
final var chapterTeaser = new StringFilterGroup( final var chapterTeaser = new StringFilterGroup(
SettingsEnum.ADREMOVER_CHAPTER_TEASER_REMOVAL, SettingsEnum.HIDE_CHAPTER_TEASER,
"expandable_metadata", "expandable_metadata",
"macro_markers_carousel" "macro_markers_carousel"
); );
final var viewProducts = new StringFilterGroup( final var viewProducts = new StringFilterGroup(
SettingsEnum.ADREMOVER_VIEW_PRODUCTS, SettingsEnum.HIDE_PRODUCTS_BANNER,
"product_item", "product_item",
"products_in_video" "products_in_video"
); );
final var webLinkPanel = new StringFilterGroup( final var webLinkPanel = new StringFilterGroup(
SettingsEnum.ADREMOVER_WEB_SEARCH_RESULTS, SettingsEnum.HIDE_WEB_SEARCH_RESULTS,
"web_link_panel" "web_link_panel"
); );
final var channelBar = new StringFilterGroup( final var channelBar = new StringFilterGroup(
SettingsEnum.ADREMOVER_CHANNEL_BAR, SettingsEnum.HIDE_CHANNEL_BAR,
"channel_bar" "channel_bar"
); );
final var relatedVideos = new StringFilterGroup( final var relatedVideos = new StringFilterGroup(
SettingsEnum.ADREMOVER_RELATED_VIDEOS, SettingsEnum.HIDE_RELATED_VIDEOS,
"fullscreen_related_videos" "fullscreen_related_videos"
); );
final var quickActions = new StringFilterGroup( final var quickActions = new StringFilterGroup(
SettingsEnum.ADREMOVER_QUICK_ACTIONS, SettingsEnum.HIDE_QUICK_ACTIONS,
"quick_actions" "quick_actions"
); );
final var imageShelf = new StringFilterGroup( final var imageShelf = new StringFilterGroup(
SettingsEnum.ADREMOVER_IMAGE_SHELF, SettingsEnum.HIDE_IMAGE_SHELF,
"image_shelf" "image_shelf"
); );
final var graySeparator = new StringFilterGroup( final var graySeparator = new StringFilterGroup(
SettingsEnum.ADREMOVER_GRAY_SEPARATOR, SettingsEnum.HIDE_GRAY_SEPARATOR,
"cell_divider" // layout residue (gray line above the buttoned ad), "cell_divider" // layout residue (gray line above the buttoned ad),
); );
final var buttonedAd = new StringFilterGroup( final var buttonedAd = new StringFilterGroup(
SettingsEnum.ADREMOVER_BUTTONED_REMOVAL, SettingsEnum.HIDE_BUTTONED_ADS,
"_buttoned_layout", "_buttoned_layout",
"full_width_square_image_layout", "full_width_square_image_layout",
"_ad_with", "_ad_with",
@ -156,7 +156,7 @@ public final class AdsFilter extends Filter {
); );
final var generalAds = new StringFilterGroup( final var generalAds = new StringFilterGroup(
SettingsEnum.ADREMOVER_GENERAL_ADS_REMOVAL, SettingsEnum.HIDE_GENERAL_ADS,
"ads_video_with_context", "ads_video_with_context",
"banner_text_icon", "banner_text_icon",
"square_image_layout", "square_image_layout",
@ -173,7 +173,7 @@ public final class AdsFilter extends Filter {
); );
final var movieAds = new StringFilterGroup( final var movieAds = new StringFilterGroup(
SettingsEnum.ADREMOVER_MOVIE_REMOVAL, SettingsEnum.HIDE_MOVIES_SECTION,
"browsy_bar", "browsy_bar",
"compact_movie", "compact_movie",
"horizontal_movie_shelf", "horizontal_movie_shelf",
@ -211,20 +211,11 @@ public final class AdsFilter extends Filter {
); );
final var carouselAd = new StringFilterGroup( final var carouselAd = new StringFilterGroup(
SettingsEnum.ADREMOVER_GENERAL_ADS_REMOVAL, SettingsEnum.HIDE_GENERAL_ADS,
"carousel_ad" "carousel_ad"
); );
final var shorts = new StringFilterGroup(
SettingsEnum.ADREMOVER_SHORTS_REMOVAL,
"reels_player_overlay",
"shorts_shelf",
"inline_shorts",
"shorts_grid"
);
this.identifierFilterGroups.addAll( this.identifierFilterGroups.addAll(
shorts,
graySeparator, graySeparator,
carouselAd carouselAd
); );
@ -234,9 +225,9 @@ public final class AdsFilter extends Filter {
public boolean isFiltered(final String path, final String identifier, final byte[] _protobufBufferArray) { public boolean isFiltered(final String path, final String identifier, final byte[] _protobufBufferArray) {
FilterResult result; FilterResult result;
if (custom.isEnabled() && custom.contains(path).isFiltered()) if (custom.isEnabled() && custom.check(path).isFiltered())
result = FilterResult.CUSTOM; result = FilterResult.CUSTOM;
else if (ReVancedUtils.containsAny(path, EXCEPTIONS)) else if (ReVancedUtils.containsAny(path, exceptions))
result = FilterResult.EXCEPTION; result = FilterResult.EXCEPTION;
else if (pathFilterGroups.contains(path) || identifierFilterGroups.contains(identifier)) else if (pathFilterGroups.contains(path) || identifierFilterGroups.contains(identifier))
result = FilterResult.FILTERED; result = FilterResult.FILTERED;
@ -263,35 +254,12 @@ public final class AdsFilter extends Filter {
} }
} }
/**
* Hide a view.
*
* @param condition The setting to check for hiding the view.
* @param view The view to hide.
*/
private static void hideView(SettingsEnum condition, View view) {
if (!condition.getBoolean()) return;
LogHelper.printDebug(() -> "Hiding view with setting: " + condition);
AdRemoverAPI.HideViewWithLayout1dp(view);
}
/** /**
* Hide the view, which shows ads in the homepage. * Hide the view, which shows ads in the homepage.
* *
* @param view The view, which shows ads. * @param view The view, which shows ads.
*/ */
public static void hideAdAttributionView(View view) { public static void hideAdAttributionView(View view) {
hideView(SettingsEnum.ADREMOVER_GENERAL_ADS_REMOVAL, view); ReVancedUtils.hideViewBy1dpUnderCondition(SettingsEnum.HIDE_GENERAL_ADS, view);
}
/**
* Hide the view, which shows reels in the homepage.
*
* @param view The view, which shows reels.
*/
public static void hideReelView(View view) {
hideView(SettingsEnum.ADREMOVER_SHORTS_REMOVAL, view);
} }
} }

View File

@ -1,4 +1,4 @@
package app.revanced.integrations.patches.litho; package app.revanced.integrations.patches.components;
import app.revanced.integrations.settings.SettingsEnum; import app.revanced.integrations.settings.SettingsEnum;
@ -47,7 +47,7 @@ final class ButtonsFilter extends Filter {
@Override @Override
public boolean isFiltered(final String path, final String identifier, final byte[] _protobufBufferArray) { public boolean isFiltered(final String path, final String identifier, final byte[] _protobufBufferArray) {
if (isEveryFilterGroupEnabled()) if (isEveryFilterGroupEnabled())
if (actionBarRule.contains(identifier).isFiltered()) return true; if (actionBarRule.check(identifier).isFiltered()) return true;
return super.isFiltered(path, identifier, _protobufBufferArray); return super.isFiltered(path, identifier, _protobufBufferArray);
} }

View File

@ -1,4 +1,4 @@
package app.revanced.integrations.patches.litho; package app.revanced.integrations.patches.components;
import app.revanced.integrations.settings.SettingsEnum; import app.revanced.integrations.settings.SettingsEnum;

View File

@ -1,4 +1,4 @@
package app.revanced.integrations.patches.litho; package app.revanced.integrations.patches.components;
import android.os.Build; import android.os.Build;
@ -42,7 +42,7 @@ abstract class FilterGroup<T> {
* Initialize a new filter group. * Initialize a new filter group.
* *
* @param setting The associated setting. * @param setting The associated setting.
* @param filters The filters. * @param filters The filters.
*/ */
@SafeVarargs @SafeVarargs
public FilterGroup(final SettingsEnum setting, final T... filters) { public FilterGroup(final SettingsEnum setting, final T... filters) {
@ -54,7 +54,7 @@ abstract class FilterGroup<T> {
return setting.getBoolean(); return setting.getBoolean();
} }
public abstract FilterGroupResult contains(final T stack); public abstract FilterGroupResult check(final T stack);
} }
class StringFilterGroup extends FilterGroup<String> { class StringFilterGroup extends FilterGroup<String> {
@ -67,7 +67,7 @@ class StringFilterGroup extends FilterGroup<String> {
} }
@Override @Override
public FilterGroupResult contains(final String string) { public FilterGroupResult check(final String string) {
return new FilterGroupResult(setting, string != null && ReVancedUtils.containsAny(string, filters)); return new FilterGroupResult(setting, string != null && ReVancedUtils.containsAny(string, filters));
} }
} }
@ -82,7 +82,7 @@ final class CustomFilterGroup extends StringFilterGroup {
} }
} }
final class ByteArrayFilterGroup extends FilterGroup<byte[]> { class ByteArrayFilterGroup extends FilterGroup<byte[]> {
// Modified implementation from https://stackoverflow.com/a/1507813 // Modified implementation from https://stackoverflow.com/a/1507813
private int indexOf(final byte[] data, final byte[] pattern) { private int indexOf(final byte[] data, final byte[] pattern) {
// Computes the failure function using a boot-strapping process, // Computes the failure function using a boot-strapping process,
@ -102,7 +102,7 @@ final class ByteArrayFilterGroup extends FilterGroup<byte[]> {
} }
// Finds the first occurrence of the pattern in the byte array using // Finds the first occurrence of the pattern in the byte array using
// KNP matching algorithm. // KMP matching algorithm.
j = 0; j = 0;
if (data.length == 0) return -1; if (data.length == 0) return -1;
@ -129,7 +129,7 @@ final class ByteArrayFilterGroup extends FilterGroup<byte[]> {
} }
@Override @Override
public FilterGroupResult contains(final byte[] bytes) { public FilterGroupResult check(final byte[] bytes) {
var matched = false; var matched = false;
for (byte[] filter : filters) { for (byte[] filter : filters) {
if (indexOf(bytes, filter) == -1) continue; if (indexOf(bytes, filter) == -1) continue;
@ -143,6 +143,17 @@ final class ByteArrayFilterGroup extends FilterGroup<byte[]> {
} }
} }
final class ByteArrayAsStringFilterGroup extends ByteArrayFilterGroup {
/**
* {@link ByteArrayFilterGroup#ByteArrayFilterGroup(SettingsEnum, byte[]...)}
*/
@RequiresApi(api = Build.VERSION_CODES.N)
public ByteArrayAsStringFilterGroup(SettingsEnum setting, String... filters) {
super(setting, Arrays.stream(filters).map(String::getBytes).toArray(byte[][]::new));
}
}
abstract class FilterGroupList<V, T extends FilterGroup<V>> implements Iterable<T> { abstract class FilterGroupList<V, T extends FilterGroup<V>> implements Iterable<T> {
private final ArrayList<T> filterGroups = new ArrayList<>(); private final ArrayList<T> filterGroups = new ArrayList<>();
@ -174,7 +185,7 @@ abstract class FilterGroupList<V, T extends FilterGroup<V>> implements Iterable<
for (T filterGroup : this) { for (T filterGroup : this) {
if (!filterGroup.isEnabled()) continue; if (!filterGroup.isEnabled()) continue;
var result = filterGroup.contains(stack); var result = filterGroup.check(stack);
if (result.isFiltered()) { if (result.isFiltered()) {
return true; return true;
} }
@ -193,10 +204,11 @@ final class ByteArrayFilterGroupList extends FilterGroupList<byte[], ByteArrayFi
abstract class Filter { abstract class Filter {
final protected StringFilterGroupList pathFilterGroups = new StringFilterGroupList(); final protected StringFilterGroupList pathFilterGroups = new StringFilterGroupList();
final protected StringFilterGroupList identifierFilterGroups = new StringFilterGroupList(); final protected StringFilterGroupList identifierFilterGroups = new StringFilterGroupList();
final protected ByteArrayFilterGroupList protobufBufferFilterGroup = new ByteArrayFilterGroupList(); final protected ByteArrayFilterGroupList protobufBufferFilterGroups = new ByteArrayFilterGroupList();
/** /**
* Check if the given path, identifier or protobuf buffer is filtered by any {@link FilterGroup}. * Check if the given path, identifier or protobuf buffer is filtered by any {@link FilterGroup}.
*
* @return True if filtered, false otherwise. * @return True if filtered, false otherwise.
*/ */
boolean isFiltered(final String path, final String identifier, final byte[] protobufBufferArray) { boolean isFiltered(final String path, final String identifier, final byte[] protobufBufferArray) {
@ -210,7 +222,7 @@ abstract class Filter {
return true; return true;
} }
if (protobufBufferFilterGroup.contains(protobufBufferArray)) { if (protobufBufferFilterGroups.contains(protobufBufferArray)) {
LogHelper.printDebug(() -> "Filtered from protobuf-buffer"); LogHelper.printDebug(() -> "Filtered from protobuf-buffer");
return true; return true;
} }
@ -219,12 +231,14 @@ abstract class Filter {
} }
} }
@RequiresApi(api = Build.VERSION_CODES.N)
@SuppressWarnings("unused") @SuppressWarnings("unused")
public final class LithoFilterPatch { public final class LithoFilterPatch {
private static final Filter[] filters = new Filter[]{ private static final Filter[] filters = new Filter[]{
new AdsFilter(), new AdsFilter(),
new ButtonsFilter(), new ButtonsFilter(),
new CommentsFilter(), new CommentsFilter(),
new ShortsFilter()
}; };
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -246,4 +260,4 @@ public final class LithoFilterPatch {
return false; return false;
} }
} }

View File

@ -0,0 +1,72 @@
package app.revanced.integrations.patches.components;
import static app.revanced.integrations.utils.ReVancedUtils.hideViewBy1dpUnderCondition;
import static app.revanced.integrations.utils.ReVancedUtils.hideViewUnderCondition;
import android.os.Build;
import android.view.View;
import app.revanced.integrations.settings.SettingsEnum;
public final class ShortsFilter extends Filter {
private final StringFilterGroup reelChannelBar = new StringFilterGroup(
null,
"reel_channel_bar"
);
public ShortsFilter() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return;
final var thanksButton = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS_THANKS_BUTTON,
"suggested_action"
);
final var subscribeButton = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS_SUBSCRIBE_BUTTON,
"subscribe_button"
);
final var joinButton = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS_JOIN_BUTTON,
"sponsor_button"
);
final var shorts = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS,
"shorts_shelf",
"inline_shorts",
"shorts_grid"
);
this.pathFilterGroups.addAll(joinButton, subscribeButton);
this.identifierFilterGroups.addAll(shorts, thanksButton);
}
@Override
boolean isFiltered(final String path, final String identifier, final byte[] protobufBufferArray) {
// Filter the path only when reelChannelBar is visible.
if (reelChannelBar.check(path).isFiltered())
if (this.pathFilterGroups.contains(path)) return true;
return this.identifierFilterGroups.contains(identifier);
}
public static void hideShortsShelf(final View shortsShelfView) {
hideViewBy1dpUnderCondition(SettingsEnum.HIDE_SHORTS, shortsShelfView);
}
// Additional components that have to be hidden by setting their visibility
public static void hideShortsCommentsButton(final View commentsButtonView) {
hideViewUnderCondition(SettingsEnum.HIDE_SHORTS_COMMENTS_BUTTON, commentsButtonView);
}
public static void hideShortsRemixButton(final View remixButtonView) {
hideViewUnderCondition(SettingsEnum.HIDE_SHORTS_REMIX_BUTTON, remixButtonView);
}
public static void hideShortsShareButton(final View shareButtonView) {
hideViewUnderCondition(SettingsEnum.HIDE_SHORTS_SHARE_BUTTON, shareButtonView);
}
}

View File

@ -16,6 +16,11 @@ import android.content.Context;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import app.revanced.integrations.sponsorblock.SponsorBlockSettings;
import app.revanced.integrations.utils.ReVancedUtils;
import app.revanced.integrations.utils.StringRef;
import app.revanced.integrations.utils.LogHelper;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -24,10 +29,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import app.revanced.integrations.sponsorblock.SponsorBlockSettings;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils;
import app.revanced.integrations.utils.StringRef;
public enum SettingsEnum { public enum SettingsEnum {
// External downloader // External downloader
@ -82,7 +83,6 @@ public enum SettingsEnum {
HIDE_SUBSCRIBERS_COMMUNITY_GUIDELINES("revanced_hide_subscribers_community_guidelines", BOOLEAN, TRUE), HIDE_SUBSCRIBERS_COMMUNITY_GUIDELINES("revanced_hide_subscribers_community_guidelines", BOOLEAN, TRUE),
HIDE_PRODUCTS_BANNER("revanced_hide_products_banner", BOOLEAN, TRUE), HIDE_PRODUCTS_BANNER("revanced_hide_products_banner", BOOLEAN, TRUE),
HIDE_WEB_SEARCH_RESULTS("revanced_hide_web_search_results", BOOLEAN, TRUE), HIDE_WEB_SEARCH_RESULTS("revanced_hide_web_search_results", BOOLEAN, TRUE),
HIDE_SHORTS("revanced_hide_shorts", BOOLEAN, TRUE, true),
HIDE_QUICK_ACTIONS("revanced_hide_quick_actions", BOOLEAN, FALSE), HIDE_QUICK_ACTIONS("revanced_hide_quick_actions", BOOLEAN, FALSE),
HIDE_RELATED_VIDEOS("revanced_hide_related_videos", BOOLEAN, FALSE), HIDE_RELATED_VIDEOS("revanced_hide_related_videos", BOOLEAN, FALSE),
@ -119,7 +119,6 @@ public enum SettingsEnum {
HIDE_HOME_BUTTON("revanced_hide_home_button", BOOLEAN, FALSE, true), HIDE_HOME_BUTTON("revanced_hide_home_button", BOOLEAN, FALSE, true),
HIDE_SHORTS_BUTTON("revanced_hide_shorts_button", BOOLEAN, TRUE, true), HIDE_SHORTS_BUTTON("revanced_hide_shorts_button", BOOLEAN, TRUE, true),
HIDE_SUBSCRIPTIONS_BUTTON("revanced_hide_subscriptions_button", BOOLEAN, FALSE, true), HIDE_SUBSCRIPTIONS_BUTTON("revanced_hide_subscriptions_button", BOOLEAN, FALSE, true),
HIDE_SHORTS_COMMENTS_BUTTON("revanced_hide_shorts_comments_button", BOOLEAN, FALSE),
HIDE_TIMESTAMP("revanced_hide_timestamp", BOOLEAN, FALSE), HIDE_TIMESTAMP("revanced_hide_timestamp", BOOLEAN, FALSE),
HIDE_VIDEO_WATERMARK("revanced_hide_video_watermark", BOOLEAN, TRUE), HIDE_VIDEO_WATERMARK("revanced_hide_video_watermark", BOOLEAN, TRUE),
HIDE_WATCH_IN_VR("revanced_hide_watch_in_vr", BOOLEAN, FALSE, true), HIDE_WATCH_IN_VR("revanced_hide_watch_in_vr", BOOLEAN, FALSE, true),
@ -133,6 +132,13 @@ public enum SettingsEnum {
HIDE_FILTER_BAR_FEED_IN_FEED("revanced_hide_filter_bar_feed_in_feed", BOOLEAN, FALSE, true), HIDE_FILTER_BAR_FEED_IN_FEED("revanced_hide_filter_bar_feed_in_feed", BOOLEAN, FALSE, true),
HIDE_FILTER_BAR_FEED_IN_SEARCH("revanced_hide_filter_bar_feed_in_search", BOOLEAN, FALSE, true), HIDE_FILTER_BAR_FEED_IN_SEARCH("revanced_hide_filter_bar_feed_in_search", BOOLEAN, FALSE, true),
HIDE_FILTER_BAR_FEED_IN_RELATED_VIDEOS("revanced_hide_filter_bar_feed_in_related_videos", BOOLEAN, FALSE, true), HIDE_FILTER_BAR_FEED_IN_RELATED_VIDEOS("revanced_hide_filter_bar_feed_in_related_videos", BOOLEAN, FALSE, true),
HIDE_SHORTS_JOIN_BUTTON("revanced_hide_shorts_join_button", BOOLEAN, FALSE),
HIDE_SHORTS_SUBSCRIBE_BUTTON("revanced_hide_shorts_subscribe_button", BOOLEAN, FALSE),
HIDE_SHORTS_THANKS_BUTTON("revanced_hide_shorts_thanks_button", BOOLEAN, FALSE),
HIDE_SHORTS_COMMENTS_BUTTON("revanced_hide_shorts_comments_button", BOOLEAN, FALSE),
HIDE_SHORTS_REMIX_BUTTON("revanced_hide_shorts_remix_button", BOOLEAN, FALSE),
HIDE_SHORTS_SHARE_BUTTON("revanced_hide_shorts_share_button", BOOLEAN, FALSE),
HIDE_SHORTS("revanced_hide_shorts", BOOLEAN, FALSE, true),
// Misc // Misc
AUTO_CAPTIONS("revanced_auto_captions", BOOLEAN, FALSE), AUTO_CAPTIONS("revanced_auto_captions", BOOLEAN, FALSE),
@ -343,7 +349,7 @@ public enum SettingsEnum {
// TODO END // TODO END
// //
private static SettingsEnum[] parents(SettingsEnum ... parents) { private static SettingsEnum[] parents(SettingsEnum... parents) {
return parents; return parents;
} }
@ -386,26 +392,32 @@ public enum SettingsEnum {
SettingsEnum(String path, ReturnType returnType, Object defaultValue) { SettingsEnum(String path, ReturnType returnType, Object defaultValue) {
this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, false, null, null); this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, false, null, null);
} }
SettingsEnum(String path, ReturnType returnType, Object defaultValue, SettingsEnum(String path, ReturnType returnType, Object defaultValue,
boolean rebootApp) { boolean rebootApp) {
this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, rebootApp, null,null); this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, rebootApp, null, null);
} }
SettingsEnum(String path, ReturnType returnType, Object defaultValue, SettingsEnum(String path, ReturnType returnType, Object defaultValue,
String userDialogMessage) { String userDialogMessage) {
this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, false, userDialogMessage, null); this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, false, userDialogMessage, null);
} }
SettingsEnum(String path, ReturnType returnType, Object defaultValue, SettingsEnum(String path, ReturnType returnType, Object defaultValue,
SettingsEnum[] parents) { SettingsEnum[] parents) {
this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, false, null, parents); this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, false, null, parents);
} }
SettingsEnum(String path, ReturnType returnType, Object defaultValue, SettingsEnum(String path, ReturnType returnType, Object defaultValue,
boolean rebootApp, String userDialogMessage) { boolean rebootApp, String userDialogMessage) {
this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, rebootApp, userDialogMessage, null); this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, rebootApp, userDialogMessage, null);
} }
SettingsEnum(String path, ReturnType returnType, Object defaultValue, SettingsEnum(String path, ReturnType returnType, Object defaultValue,
boolean rebootApp, SettingsEnum[] parents) { boolean rebootApp, SettingsEnum[] parents) {
this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, rebootApp, null, parents); this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, rebootApp, null, parents);
} }
SettingsEnum(String path, ReturnType returnType, Object defaultValue, SettingsEnum(String path, ReturnType returnType, Object defaultValue,
boolean rebootApp, String userDialogMessage, SettingsEnum[] parents) { boolean rebootApp, String userDialogMessage, SettingsEnum[] parents) {
this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, rebootApp, userDialogMessage, parents); this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, rebootApp, userDialogMessage, parents);
@ -414,20 +426,24 @@ public enum SettingsEnum {
SettingsEnum(String path, ReturnType returnType, Object defaultValue, SharedPrefCategory prefName) { SettingsEnum(String path, ReturnType returnType, Object defaultValue, SharedPrefCategory prefName) {
this(path, returnType, defaultValue, prefName, false, null, null); this(path, returnType, defaultValue, prefName, false, null, null);
} }
SettingsEnum(String path, ReturnType returnType, Object defaultValue, SharedPrefCategory prefName, SettingsEnum(String path, ReturnType returnType, Object defaultValue, SharedPrefCategory prefName,
boolean rebootApp) { boolean rebootApp) {
this(path, returnType, defaultValue, prefName, rebootApp, null, null); this(path, returnType, defaultValue, prefName, rebootApp, null, null);
} }
SettingsEnum(String path, ReturnType returnType, Object defaultValue, SharedPrefCategory prefName, SettingsEnum(String path, ReturnType returnType, Object defaultValue, SharedPrefCategory prefName,
String userDialogMessage) { String userDialogMessage) {
this(path, returnType, defaultValue, prefName, false, userDialogMessage, null); this(path, returnType, defaultValue, prefName, false, userDialogMessage, null);
} }
SettingsEnum(String path, ReturnType returnType, Object defaultValue, SharedPrefCategory prefName, SettingsEnum(String path, ReturnType returnType, Object defaultValue, SharedPrefCategory prefName,
SettingsEnum[] parents) { SettingsEnum[] parents) {
this(path, returnType, defaultValue, prefName, false, null, parents); this(path, returnType, defaultValue, prefName, false, null, parents);
} }
SettingsEnum(String path, ReturnType returnType, Object defaultValue, SharedPrefCategory prefName, SettingsEnum(String path, ReturnType returnType, Object defaultValue, SharedPrefCategory prefName,
boolean rebootApp, @Nullable String userDialogMessage, @Nullable SettingsEnum[] parents) { boolean rebootApp, @Nullable String userDialogMessage, @Nullable SettingsEnum[] parents) {
this.path = Objects.requireNonNull(path); this.path = Objects.requireNonNull(path);
this.returnType = Objects.requireNonNull(returnType); this.returnType = Objects.requireNonNull(returnType);
this.value = this.defaultValue = Objects.requireNonNull(defaultValue); this.value = this.defaultValue = Objects.requireNonNull(defaultValue);
@ -599,10 +615,10 @@ public enum SettingsEnum {
/** /**
* Sets, but does _not_ persistently save the value. * Sets, but does _not_ persistently save the value.
* * <p>
* This intentionally is a static method, to deter accidental usage * This intentionally is a static method, to deter accidental usage
* when {@link #saveValue(Object)} was intended. * when {@link #saveValue(Object)} was intended.
* * <p>
* This method is only to be used by the Settings preference code. * This method is only to be used by the Settings preference code.
*/ */
public static void setValue(@NonNull SettingsEnum setting, @NonNull String newValue) { public static void setValue(@NonNull SettingsEnum setting, @NonNull String newValue) {
@ -627,6 +643,7 @@ public enum SettingsEnum {
throw new IllegalStateException(setting.name()); throw new IllegalStateException(setting.name());
} }
} }
/** /**
* This method is only to be used by the Settings preference code. * This method is only to be used by the Settings preference code.
*/ */
@ -664,7 +681,7 @@ public enum SettingsEnum {
/** /**
* @return if this setting can be configured and used. * @return if this setting can be configured and used.
* * <p>
* Not to be confused with {@link #getBoolean()} * Not to be confused with {@link #getBoolean()}
*/ */
public boolean isAvailable() { public boolean isAvailable() {

View File

@ -11,18 +11,14 @@ import android.view.ViewGroup;
import android.view.animation.Animation; import android.view.animation.Animation;
import android.view.animation.AnimationUtils; import android.view.animation.AnimationUtils;
import android.widget.*; import android.widget.*;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import app.revanced.integrations.settings.SettingsEnum;
import java.text.Bidi; import java.text.Bidi;
import java.util.Locale; import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.Callable; import java.util.concurrent.*;
import java.util.concurrent.Future;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class ReVancedUtils { public class ReVancedUtils {
@ -32,6 +28,35 @@ public class ReVancedUtils {
private ReVancedUtils() { private ReVancedUtils() {
} // utility class } // utility class
/**
* Hide a view by setting its layout height and width to 1dp.
*
* @param condition The setting to check for hiding the view.
* @param view The view to hide.
*/
public static void hideViewBy1dpUnderCondition(SettingsEnum condition, View view) {
if (!condition.getBoolean()) return;
LogHelper.printDebug(() -> "Hiding view with setting: " + condition);
hideViewByLayoutParams(view);
}
/**
* Hide a view by setting its visibility to GONE.
*
* @param condition The setting to check for hiding the view.
* @param view The view to hide.
*/
public static void hideViewUnderCondition(SettingsEnum condition, View view) {
if (!condition.getBoolean()) return;
LogHelper.printDebug(() -> "Hiding view with setting: " + condition);
view.setVisibility(View.GONE);
}
/** /**
* General purpose pool for network calls and other background tasks. * General purpose pool for network calls and other background tasks.
* All tasks run at max thread priority. * All tasks run at max thread priority.
@ -119,6 +144,7 @@ public class ReVancedUtils {
@Nullable @Nullable
private static Boolean isRightToLeftTextLayout; private static Boolean isRightToLeftTextLayout;
/** /**
* If the device language uses right to left text layout (hebrew, arabic, etc) * If the device language uses right to left text layout (hebrew, arabic, etc)
*/ */
@ -245,7 +271,7 @@ public class ReVancedUtils {
* Hide a view by setting its layout params to 1x1 * Hide a view by setting its layout params to 1x1
* @param view The view to hide. * @param view The view to hide.
*/ */
public static void HideViewByLayoutParams(View view) { public static void hideViewByLayoutParams(View view) {
if (view instanceof LinearLayout) { if (view instanceof LinearLayout) {
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(1, 1); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(1, 1);
view.setLayoutParams(layoutParams); view.setLayoutParams(layoutParams);