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 static void hideAlbumCard(View view) {
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) {
if (!SettingsEnum.HIDE_BREAKING_NEWS.getBoolean()
|| 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
public static void hideCrowdfundingBox(View view) {
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) {
if (!SettingsEnum.HIDE_FILTER_BAR_FEED_IN_RELATED_VIDEOS.getBoolean()) return;
ReVancedUtils.HideViewByLayoutParams(chipView);
ReVancedUtils.hideViewByLayoutParams(chipView);
}
public static int hideInSearch(final int height) {

View File

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

View File

@ -1,4 +1,4 @@
package app.revanced.integrations.patches.litho;
package app.revanced.integrations.patches.components;
import android.os.Build;
@ -42,7 +42,7 @@ abstract class FilterGroup<T> {
* Initialize a new filter group.
*
* @param setting The associated setting.
* @param filters The filters.
* @param filters The filters.
*/
@SafeVarargs
public FilterGroup(final SettingsEnum setting, final T... filters) {
@ -54,7 +54,7 @@ abstract class FilterGroup<T> {
return setting.getBoolean();
}
public abstract FilterGroupResult contains(final T stack);
public abstract FilterGroupResult check(final T stack);
}
class StringFilterGroup extends FilterGroup<String> {
@ -67,7 +67,7 @@ class StringFilterGroup extends FilterGroup<String> {
}
@Override
public FilterGroupResult contains(final String string) {
public FilterGroupResult check(final String string) {
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
private int indexOf(final byte[] data, final byte[] pattern) {
// 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
// KNP matching algorithm.
// KMP matching algorithm.
j = 0;
if (data.length == 0) return -1;
@ -129,7 +129,7 @@ final class ByteArrayFilterGroup extends FilterGroup<byte[]> {
}
@Override
public FilterGroupResult contains(final byte[] bytes) {
public FilterGroupResult check(final byte[] bytes) {
var matched = false;
for (byte[] filter : filters) {
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> {
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) {
if (!filterGroup.isEnabled()) continue;
var result = filterGroup.contains(stack);
var result = filterGroup.check(stack);
if (result.isFiltered()) {
return true;
}
@ -193,10 +204,11 @@ final class ByteArrayFilterGroupList extends FilterGroupList<byte[], ByteArrayFi
abstract class Filter {
final protected StringFilterGroupList pathFilterGroups = 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}.
*
* @return True if filtered, false otherwise.
*/
boolean isFiltered(final String path, final String identifier, final byte[] protobufBufferArray) {
@ -210,7 +222,7 @@ abstract class Filter {
return true;
}
if (protobufBufferFilterGroup.contains(protobufBufferArray)) {
if (protobufBufferFilterGroups.contains(protobufBufferArray)) {
LogHelper.printDebug(() -> "Filtered from protobuf-buffer");
return true;
}
@ -219,12 +231,14 @@ abstract class Filter {
}
}
@RequiresApi(api = Build.VERSION_CODES.N)
@SuppressWarnings("unused")
public final class LithoFilterPatch {
private static final Filter[] filters = new Filter[]{
new AdsFilter(),
new ButtonsFilter(),
new CommentsFilter(),
new ShortsFilter()
};
@SuppressWarnings("unused")
@ -246,4 +260,4 @@ public final class LithoFilterPatch {
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.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.JSONObject;
@ -24,10 +29,6 @@ import java.util.HashMap;
import java.util.Map;
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 {
// External downloader
@ -82,7 +83,6 @@ public enum SettingsEnum {
HIDE_SUBSCRIBERS_COMMUNITY_GUIDELINES("revanced_hide_subscribers_community_guidelines", BOOLEAN, TRUE),
HIDE_PRODUCTS_BANNER("revanced_hide_products_banner", 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_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_SHORTS_BUTTON("revanced_hide_shorts_button", BOOLEAN, TRUE, 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_VIDEO_WATERMARK("revanced_hide_video_watermark", BOOLEAN, 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_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_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
AUTO_CAPTIONS("revanced_auto_captions", BOOLEAN, FALSE),
@ -343,7 +349,7 @@ public enum SettingsEnum {
// TODO END
//
private static SettingsEnum[] parents(SettingsEnum ... parents) {
private static SettingsEnum[] parents(SettingsEnum... parents) {
return parents;
}
@ -386,26 +392,32 @@ public enum SettingsEnum {
SettingsEnum(String path, ReturnType returnType, Object defaultValue) {
this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, false, null, null);
}
SettingsEnum(String path, ReturnType returnType, Object defaultValue,
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,
String userDialogMessage) {
this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, false, userDialogMessage, null);
}
SettingsEnum(String path, ReturnType returnType, Object defaultValue,
SettingsEnum[] parents) {
this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, false, null, parents);
}
SettingsEnum(String path, ReturnType returnType, Object defaultValue,
boolean rebootApp, String userDialogMessage) {
this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, rebootApp, userDialogMessage, null);
}
SettingsEnum(String path, ReturnType returnType, Object defaultValue,
boolean rebootApp, SettingsEnum[] parents) {
this(path, returnType, defaultValue, SharedPrefCategory.YOUTUBE, rebootApp, null, parents);
}
SettingsEnum(String path, ReturnType returnType, Object defaultValue,
boolean rebootApp, String userDialogMessage, SettingsEnum[] 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) {
this(path, returnType, defaultValue, prefName, false, null, null);
}
SettingsEnum(String path, ReturnType returnType, Object defaultValue, SharedPrefCategory prefName,
boolean rebootApp) {
this(path, returnType, defaultValue, prefName, rebootApp, null, null);
}
SettingsEnum(String path, ReturnType returnType, Object defaultValue, SharedPrefCategory prefName,
String userDialogMessage) {
this(path, returnType, defaultValue, prefName, false, userDialogMessage, null);
}
SettingsEnum(String path, ReturnType returnType, Object defaultValue, SharedPrefCategory prefName,
SettingsEnum[] parents) {
this(path, returnType, defaultValue, prefName, false, null, parents);
}
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.returnType = Objects.requireNonNull(returnType);
this.value = this.defaultValue = Objects.requireNonNull(defaultValue);
@ -599,10 +615,10 @@ public enum SettingsEnum {
/**
* Sets, but does _not_ persistently save the value.
*
* <p>
* This intentionally is a static method, to deter accidental usage
* when {@link #saveValue(Object)} was intended.
*
* <p>
* This method is only to be used by the Settings preference code.
*/
public static void setValue(@NonNull SettingsEnum setting, @NonNull String newValue) {
@ -627,6 +643,7 @@ public enum SettingsEnum {
throw new IllegalStateException(setting.name());
}
}
/**
* 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.
*
* <p>
* Not to be confused with {@link #getBoolean()}
*/
public boolean isAvailable() {

View File

@ -11,18 +11,14 @@ import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.*;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import app.revanced.integrations.settings.SettingsEnum;
import java.text.Bidi;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
public class ReVancedUtils {
@ -32,6 +28,35 @@ public class ReVancedUtils {
private ReVancedUtils() {
} // 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.
* All tasks run at max thread priority.
@ -119,6 +144,7 @@ public class ReVancedUtils {
@Nullable
private static Boolean isRightToLeftTextLayout;
/**
* 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
* @param view The view to hide.
*/
public static void HideViewByLayoutParams(View view) {
public static void hideViewByLayoutParams(View view) {
if (view instanceof LinearLayout) {
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(1, 1);
view.setLayoutParams(layoutParams);