mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-06-02 11:26:18 +02:00
feat: Add channel page setting
This commit is contained in:
parent
5e398be094
commit
21df76ef4f
|
@ -5,7 +5,10 @@ import androidx.annotation.GuardedBy;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import app.revanced.integrations.shared.settings.BaseSettings;
|
||||
import app.revanced.integrations.shared.settings.EnumSetting;
|
||||
import app.revanced.integrations.shared.settings.Setting;
|
||||
import app.revanced.integrations.youtube.patches.components.AlternativeThumbnailsFilter;
|
||||
import app.revanced.integrations.youtube.settings.Settings;
|
||||
import app.revanced.integrations.shared.Logger;
|
||||
import app.revanced.integrations.shared.Utils;
|
||||
|
@ -25,6 +28,7 @@ import java.util.Map;
|
|||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static app.revanced.integrations.shared.StringRef.str;
|
||||
import static app.revanced.integrations.youtube.settings.Settings.ALT_THUMBNAIL_CHANNEL_PAGES;
|
||||
import static app.revanced.integrations.youtube.settings.Settings.ALT_THUMBNAIL_HOME;
|
||||
import static app.revanced.integrations.youtube.settings.Settings.ALT_THUMBNAIL_SEARCH;
|
||||
import static app.revanced.integrations.youtube.settings.Settings.ALT_THUMBNAIL_SUBSCRIPTIONS;
|
||||
|
@ -59,6 +63,7 @@ public final class AlternativeThumbnailsPatch {
|
|||
return ALT_THUMBNAIL_HOME.get().useDeArrow
|
||||
|| ALT_THUMBNAIL_SUBSCRIPTIONS.get().useDeArrow
|
||||
|| ALT_THUMBNAIL_SEARCH.get().useDeArrow
|
||||
|| ALT_THUMBNAIL_CHANNEL_PAGES.get().useDeArrow
|
||||
|| ALT_THUMBNAIL_WATCH_HISTORY.get().useDeArrow;
|
||||
}
|
||||
|
||||
|
@ -73,6 +78,7 @@ public final class AlternativeThumbnailsPatch {
|
|||
return ALT_THUMBNAIL_HOME.get().useStillImages
|
||||
|| ALT_THUMBNAIL_SUBSCRIPTIONS.get().useStillImages
|
||||
|| ALT_THUMBNAIL_SEARCH.get().useStillImages
|
||||
|| ALT_THUMBNAIL_CHANNEL_PAGES.get().useStillImages
|
||||
|| ALT_THUMBNAIL_WATCH_HISTORY.get().useStillImages;
|
||||
}
|
||||
|
||||
|
@ -112,6 +118,12 @@ public final class AlternativeThumbnailsPatch {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used only for debug logging. The setting for the last thumbnail loaded.
|
||||
*/
|
||||
private static volatile EnumSetting<ThumbnailOption> lastNavigationSetting;
|
||||
|
||||
|
||||
private static final Uri dearrowApiUri;
|
||||
|
||||
/**
|
||||
|
@ -152,19 +164,24 @@ public final class AlternativeThumbnailsPatch {
|
|||
return apiUri;
|
||||
}
|
||||
|
||||
private static ThumbnailOption thumbnailOptionForCurrentNavigation() {
|
||||
private static EnumSetting<ThumbnailOption> settingForCurrentNavigation() {
|
||||
if (NavigationBar.isSearchBarActive()) { // Must check search first.
|
||||
return ALT_THUMBNAIL_SEARCH.get();
|
||||
return ALT_THUMBNAIL_SEARCH;
|
||||
}
|
||||
if (NavigationButton.HOME.isSelected()
|
||||
|| PlayerType.getCurrent().isMaximizedOrFullscreen()) {
|
||||
return ALT_THUMBNAIL_HOME.get();
|
||||
if (PlayerType.getCurrent().isMaximizedOrFullscreen()) {
|
||||
return ALT_THUMBNAIL_HOME;
|
||||
}
|
||||
if (AlternativeThumbnailsFilter.channelPageWasLastLoaded()) {
|
||||
return ALT_THUMBNAIL_CHANNEL_PAGES;
|
||||
}
|
||||
if (NavigationButton.HOME.isSelected()) {
|
||||
return ALT_THUMBNAIL_HOME;
|
||||
}
|
||||
if (NavigationButton.libraryOrYouTabIsSelected()) {
|
||||
return ALT_THUMBNAIL_WATCH_HISTORY.get();
|
||||
return ALT_THUMBNAIL_WATCH_HISTORY;
|
||||
}
|
||||
// User is in the subscription or notification tab.
|
||||
return ALT_THUMBNAIL_SUBSCRIPTIONS.get();
|
||||
return ALT_THUMBNAIL_SUBSCRIPTIONS;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -242,7 +259,14 @@ public final class AlternativeThumbnailsPatch {
|
|||
*/
|
||||
public static String overrideImageURL(String originalUrl) {
|
||||
try {
|
||||
ThumbnailOption option = thumbnailOptionForCurrentNavigation();
|
||||
EnumSetting<ThumbnailOption> currentSetting = settingForCurrentNavigation();
|
||||
if (BaseSettings.DEBUG.get()) {
|
||||
if (currentSetting != lastNavigationSetting) {
|
||||
lastNavigationSetting = currentSetting;
|
||||
Logger.printDebug(() -> "Changed to setting: " + currentSetting.key);
|
||||
}
|
||||
}
|
||||
ThumbnailOption option = currentSetting.get();
|
||||
if (option == ThumbnailOption.ORIGINAL) {
|
||||
return originalUrl;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
package app.revanced.integrations.youtube.patches.components;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import app.revanced.integrations.shared.Logger;
|
||||
import app.revanced.integrations.shared.settings.BaseSettings;
|
||||
import app.revanced.integrations.youtube.shared.NavigationBar;
|
||||
|
||||
/**
|
||||
* Used to discern a channel page is open in the home and subscription tabs.
|
||||
* All other navigation states can be used to rule out a channel page is open or not.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public final class AlternativeThumbnailsFilter extends Filter {
|
||||
|
||||
/**
|
||||
* If the last litho components loaded were part of a channel page.
|
||||
*/
|
||||
private static volatile boolean channelPageWasLastLoaded;
|
||||
|
||||
/**
|
||||
* Used to detect edge cases for viewing a channel page while changing tabs.
|
||||
*/
|
||||
private static volatile boolean homeFeedTabIsSelected;
|
||||
|
||||
public static boolean channelPageWasLastLoaded() {
|
||||
checkIfTabChanged();
|
||||
return channelPageWasLastLoaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* When switching tabs, the home and subscription feed litho may not be reloaded
|
||||
* but the image urls always are. This is particularly noticeable when using tablet mode.
|
||||
* Channel pages always seems to reload even when switching to
|
||||
* a tab that already is on a channel page.
|
||||
* Only need to check for changes of the home or subscription tab.
|
||||
*
|
||||
* Must check for tab change from both the litho and url hook.
|
||||
*/
|
||||
private static void checkIfTabChanged() {
|
||||
final boolean homeSelected = NavigationBar.NavigationButton.HOME.isSelected();
|
||||
if (homeFeedTabIsSelected != homeSelected) {
|
||||
homeFeedTabIsSelected = homeSelected;
|
||||
channelPageWasLastLoaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Video components observed when viewing a channel page.
|
||||
*/
|
||||
private final StringFilterGroup channelPageGroup = new StringFilterGroup(
|
||||
null,
|
||||
"channel_banner.eml",
|
||||
// Appears to be only used for the channel page.
|
||||
"mixed_content_shelf.eml",
|
||||
"grid_video_wrapper.eml",
|
||||
// Tablet layout components.
|
||||
"rich_grid_row.eml",
|
||||
// Appears in search and other places, but not in the home or subscription feed.
|
||||
"compact_video.eml"
|
||||
);
|
||||
|
||||
/**
|
||||
* Video components never observed when viewing a channel page.
|
||||
*
|
||||
* Only include components found in the home and subscription tabs,
|
||||
* when not viewing a channel page.
|
||||
*/
|
||||
private final StringFilterGroup notChannelPageGroup = new StringFilterGroup(
|
||||
null,
|
||||
// Home tab
|
||||
"home_video_with_context.eml",
|
||||
"library_recent_shelf.eml",
|
||||
"horizontal_tile_shelf.eml", // Continue watching and other home recommendations.
|
||||
// Subscription tab
|
||||
"subscriptions_channel_bar.eml",
|
||||
"video_metadata_carousel.eml",
|
||||
"video_with_context.eml"
|
||||
);
|
||||
|
||||
public AlternativeThumbnailsFilter() {
|
||||
addPathCallbacks(channelPageGroup, notChannelPageGroup);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBufferArray,
|
||||
StringFilterGroup matchedGroup, FilterContentType contentType, int contentIndex) {
|
||||
if (contentIndex != 0) {
|
||||
return false; // All filters paths are at the start.
|
||||
}
|
||||
|
||||
checkIfTabChanged();
|
||||
final boolean isChannelPageComponent = (matchedGroup == channelPageGroup);
|
||||
|
||||
if (BaseSettings.DEBUG.get()) {
|
||||
if (channelPageWasLastLoaded != isChannelPageComponent) {
|
||||
Logger.printDebug(() -> "Channel page components: " + isChannelPageComponent);
|
||||
}
|
||||
}
|
||||
|
||||
channelPageWasLastLoaded = isChannelPageComponent;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -59,6 +59,7 @@ public class Settings extends BaseSettings {
|
|||
public static final EnumSetting<ThumbnailOption> ALT_THUMBNAIL_HOME = new EnumSetting<>("revanced_alt_thumbnail_home", ThumbnailOption.ORIGINAL);
|
||||
public static final EnumSetting<ThumbnailOption> ALT_THUMBNAIL_SUBSCRIPTIONS = new EnumSetting<>("revanced_alt_thumbnail_subscription", ThumbnailOption.ORIGINAL);
|
||||
public static final EnumSetting<ThumbnailOption> ALT_THUMBNAIL_SEARCH = new EnumSetting<>("revanced_alt_thumbnail_search", ThumbnailOption.ORIGINAL);
|
||||
public static final EnumSetting<ThumbnailOption> ALT_THUMBNAIL_CHANNEL_PAGES = new EnumSetting<>("revanced_alt_thumbnail_channel_pages", ThumbnailOption.ORIGINAL);
|
||||
public static final EnumSetting<ThumbnailOption> ALT_THUMBNAIL_WATCH_HISTORY = new EnumSetting<>("revanced_alt_thumbnail_history", ThumbnailOption.ORIGINAL);
|
||||
public static final StringSetting ALT_THUMBNAIL_DEARROW_API_URL = new StringSetting("revanced_alt_thumbnail_dearrow_api_url",
|
||||
"https://dearrow-thumb.ajay.app/api/v1/getThumbnail", true, new DeArrowAvailability());
|
||||
|
|
Loading…
Reference in New Issue
Block a user