This repository has been archived by the owner on Dec 8, 2024. It is now read-only.
forked from ReVanced/revanced-integrations
-
Notifications
You must be signed in to change notification settings - Fork 49
/
FeedPatch.java
221 lines (181 loc) · 8.71 KB
/
FeedPatch.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
package app.revanced.integrations.youtube.patches.feed;
import static app.revanced.integrations.shared.utils.Utils.hideViewBy0dpUnderCondition;
import static app.revanced.integrations.shared.utils.Utils.hideViewUnderCondition;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;
import app.revanced.integrations.shared.utils.Utils;
import app.revanced.integrations.youtube.settings.Settings;
@SuppressWarnings("unused")
public class FeedPatch {
// region [Hide feed components] patch
public static int hideCategoryBarInFeed(final int height) {
return Settings.HIDE_CATEGORY_BAR_IN_FEED.get() ? 0 : height;
}
public static void hideCategoryBarInRelatedVideos(final View chipView) {
Utils.hideViewBy0dpUnderCondition(
Settings.HIDE_CATEGORY_BAR_IN_RELATED_VIDEOS.get() || Settings.HIDE_RELATED_VIDEOS.get(),
chipView
);
}
public static int hideCategoryBarInSearch(final int height) {
return Settings.HIDE_CATEGORY_BAR_IN_SEARCH.get() ? 0 : height;
}
/**
* Rather than simply hiding the channel tab view, completely removes channel tab from list.
* If a channel tab is removed from the list, users will not be able to open it by swiping.
*
* @param channelTabText Text to be assigned to channel tab, such as 'Shorts', 'Playlists', 'Community', 'Store'.
* This text is hardcoded, so it follows the user's language.
* @return Whether to remove the channel tab from the list.
*/
public static boolean hideChannelTab(String channelTabText) {
if (!Settings.HIDE_CHANNEL_TAB.get()) {
return false;
}
if (channelTabText == null || channelTabText.isEmpty()) {
return false;
}
String[] blockList = Settings.HIDE_CHANNEL_TAB_FILTER_STRINGS.get().split("\\n");
for (String filter : blockList) {
if (!filter.isEmpty() && channelTabText.equals(filter)) {
return true;
}
}
return false;
}
public static void hideBreakingNewsShelf(View view) {
hideViewBy0dpUnderCondition(
Settings.HIDE_CAROUSEL_SHELF.get(),
view
);
}
public static View hideCaptionsButton(View view) {
return Settings.HIDE_FEED_CAPTIONS_BUTTON.get() ? null : view;
}
public static void hideCaptionsButtonContainer(View view) {
hideViewUnderCondition(
Settings.HIDE_FEED_CAPTIONS_BUTTON,
view
);
}
public static boolean hideFloatingButton() {
return Settings.HIDE_FLOATING_BUTTON.get();
}
public static void hideLatestVideosButton(View view) {
hideViewUnderCondition(Settings.HIDE_LATEST_VIDEOS_BUTTON.get(), view);
}
public static boolean hideSubscriptionsChannelSection() {
return Settings.HIDE_SUBSCRIPTIONS_CAROUSEL.get();
}
public static void hideSubscriptionsChannelSection(View view) {
hideViewUnderCondition(Settings.HIDE_SUBSCRIPTIONS_CAROUSEL, view);
}
private static FrameLayout.LayoutParams layoutParams;
private static int minimumHeight = -1;
private static int paddingLeft = 12;
private static int paddingTop = 0;
private static int paddingRight = 12;
private static int paddingBottom = 0;
/**
* expandButtonContainer is used in channel profiles as well as search results.
* We need to hide expandButtonContainer only in search results, not in channel profile.
* <p>
* If we hide expandButtonContainer with setVisibility, the empty space occupied by expandButtonContainer will still be left.
* Therefore, we need to dynamically resize the View with LayoutParams.
* <p>
* Unlike other Views, expandButtonContainer cannot make a View invisible using the normal {@link Utils#hideViewByLayoutParams} method.
* We should set the parent view's padding and MinimumHeight to 0 to completely hide the expandButtonContainer.
*
* @param parentView Parent view of expandButtonContainer.
*/
public static void hideShowMoreButton(View parentView) {
if (!Settings.HIDE_SHOW_MORE_BUTTON.get())
return;
if (!(parentView instanceof ViewGroup viewGroup))
return;
if (!(viewGroup.getChildAt(0) instanceof ViewGroup expandButtonContainer))
return;
if (layoutParams == null) {
// We need to get the original LayoutParams and paddings applied to expandButtonContainer.
// Theses are used to make the expandButtonContainer visible again.
if (expandButtonContainer.getLayoutParams() instanceof FrameLayout.LayoutParams lp) {
layoutParams = lp;
paddingLeft = parentView.getPaddingLeft();
paddingTop = parentView.getPaddingTop();
paddingRight = parentView.getPaddingRight();
paddingBottom = parentView.getPaddingBottom();
}
}
// I'm not sure if 'Utils.runOnMainThreadDelayed' is absolutely necessary.
Utils.runOnMainThreadDelayed(() -> {
// MinimumHeight is also needed to make expandButtonContainer visible again.
// Get original MinimumHeight.
if (minimumHeight == -1) {
minimumHeight = parentView.getMinimumHeight();
}
// In the search results, the child view structure of expandButtonContainer is as follows:
// expandButtonContainer
// L TextView (first child view is SHOWN, 'Show more' text)
// L ImageView (second child view is shown, dropdown arrow icon)
// In the channel profiles, the child view structure of expandButtonContainer is as follows:
// expandButtonContainer
// L TextView (first child view is HIDDEN, 'Show more' text)
// L ImageView (second child view is shown, dropdown arrow icon)
if (expandButtonContainer.getChildAt(0).getVisibility() != View.VISIBLE && layoutParams != null) {
// If the first child view (TextView) is HIDDEN, the channel profile is open.
// Restore parent view's padding and MinimumHeight to make them visible.
parentView.setMinimumHeight(minimumHeight);
parentView.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
expandButtonContainer.setLayoutParams(layoutParams);
} else {
// If the first child view (TextView) is SHOWN, the search results is open.
// Set the parent view's padding and MinimumHeight to 0 to completely hide the expandButtonContainer.
parentView.setMinimumHeight(0);
parentView.setPadding(0, 0, 0, 0);
expandButtonContainer.setLayoutParams(new FrameLayout.LayoutParams(0, 0));
}
}, 0
);
}
// endregion
// region [Hide feed flyout menu] patch
/**
* hide feed flyout menu for phone
*
* @param menuTitleCharSequence menu title
*/
@Nullable
public static CharSequence hideFlyoutMenu(@Nullable CharSequence menuTitleCharSequence) {
if (menuTitleCharSequence != null && Settings.HIDE_FEED_FLYOUT_MENU.get()) {
String[] blockList = Settings.HIDE_FEED_FLYOUT_MENU_FILTER_STRINGS.get().split("\\n");
String menuTitleString = menuTitleCharSequence.toString();
for (String filter : blockList) {
if (menuTitleString.equals(filter) && !filter.isEmpty())
return null;
}
}
return menuTitleCharSequence;
}
/**
* hide feed flyout panel for tablet
*
* @param menuTextView flyout text view
* @param menuTitleCharSequence raw text
*/
public static void hideFlyoutMenu(TextView menuTextView, CharSequence menuTitleCharSequence) {
if (menuTitleCharSequence == null || !Settings.HIDE_FEED_FLYOUT_MENU.get())
return;
if (!(menuTextView.getParent() instanceof View parentView))
return;
String[] blockList = Settings.HIDE_FEED_FLYOUT_MENU_FILTER_STRINGS.get().split("\\n");
String menuTitleString = menuTitleCharSequence.toString();
for (String filter : blockList) {
if (menuTitleString.equals(filter) && !filter.isEmpty())
Utils.hideViewByLayoutParams(parentView);
}
}
// endregion
}