Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
feat(YouTube - Hide feed components): Add Hide related videos setting
Browse files Browse the repository at this point in the history
  • Loading branch information
anddea committed Sep 30, 2024
1 parent d96ecc7 commit 33fb91c
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package app.revanced.integrations.youtube.patches.feed;

import androidx.annotation.Nullable;

import java.util.concurrent.atomic.AtomicBoolean;

import app.revanced.integrations.youtube.settings.Settings;
import app.revanced.integrations.youtube.shared.BottomSheetState;
import app.revanced.integrations.youtube.shared.RootView;

@SuppressWarnings("unused")
public final class RelatedVideoPatch {
private static final boolean HIDE_RELATED_VIDEOS = Settings.HIDE_RELATED_VIDEOS.get();

private static final int OFFSET = Settings.RELATED_VIDEOS_OFFSET.get();

// video title,channel bar, video action bar, comment
private static final int MAX_ITEM_COUNT = 4 + OFFSET;

private static final AtomicBoolean engagementPanelOpen = new AtomicBoolean(false);

public static void showEngagementPanel(@Nullable Object object) {
engagementPanelOpen.set(object != null);
}

public static void hideEngagementPanel() {
engagementPanelOpen.compareAndSet(true, false);
}

public static int overrideItemCounts(int itemCounts) {
if (!HIDE_RELATED_VIDEOS) {
return itemCounts;
}
if (itemCounts < MAX_ITEM_COUNT) {
return itemCounts;
}
if (!RootView.isPlayerActive()) {
return itemCounts;
}
if (BottomSheetState.getCurrent().isOpen()) {
return itemCounts;
}
if (engagementPanelOpen.get()) {
return itemCounts;
}
return MAX_ITEM_COUNT;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package app.revanced.integrations.youtube.patches.utils;

import app.revanced.integrations.youtube.shared.BottomSheetState;

@SuppressWarnings("unused")
public class BottomSheetHookPatch {
/**
* Injection point.
*/
public static void onAttachedToWindow() {
BottomSheetState.set(BottomSheetState.OPEN);
}

/**
* Injection point.
*/
public static void onDetachedFromWindow() {
BottomSheetState.set(BottomSheetState.CLOSED);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ public class Settings extends BaseSettings {
public static final StringSetting HIDE_VIDEO_VIEW_COUNTS_MULTIPLIER = new StringSetting("revanced_hide_video_view_counts_multiplier", str("revanced_hide_video_view_counts_multiplier_default_value"), true,
parentsAny(HIDE_VIDEO_BY_VIEW_COUNTS_HOME, HIDE_VIDEO_BY_VIEW_COUNTS_SEARCH, HIDE_VIDEO_BY_VIEW_COUNTS_SUBSCRIPTIONS));

// Experimental Flags
public static final BooleanSetting HIDE_RELATED_VIDEOS = new BooleanSetting("revanced_hide_related_videos", FALSE, true, "revanced_hide_related_videos_user_dialog_message");
public static final IntegerSetting RELATED_VIDEOS_OFFSET = new IntegerSetting("revanced_related_videos_offset", 1, true, parent(HIDE_RELATED_VIDEOS));


// PreferenceScreen: General
public static final EnumSetting<StartPage> CHANGE_START_PAGE = new EnumSetting<>("revanced_change_start_page", StartPage.ORIGINAL, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package app.revanced.integrations.youtube.shared

import app.revanced.integrations.shared.utils.Event
import app.revanced.integrations.shared.utils.Logger

/**
* BottomSheetState bottom sheet state.
*/
enum class BottomSheetState {
CLOSED,
OPEN;

companion object {

@JvmStatic
fun set(enum: BottomSheetState) {
if (current != enum) {
Logger.printDebug { "BottomSheetState changed to: ${enum.name}" }
current = enum
}
}

/**
* The current bottom sheet state.
*/
@JvmStatic
var current
get() = currentBottomSheetState
private set(value) {
currentBottomSheetState = value
onChange(currentBottomSheetState)
}

@Volatile // value is read/write from different threads
private var currentBottomSheetState = CLOSED

/**
* bottom sheet state change listener
*/
@JvmStatic
val onChange = Event<BottomSheetState>()
}

/**
* Check if the bottom sheet is [OPEN].
* Useful for checking if a bottom sheet is open.
*/
fun isOpen(): Boolean {
return this == OPEN
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum class LockModeState {

companion object {

private val nameToLockModeState = values().associateBy { it.name }
private val nameToLockModeState = entries.associateBy { it.name }

@JvmStatic
fun setFromString(enumName: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ enum class PlayerType {

companion object {

private val nameToPlayerType = values().associateBy { it.name }
private val nameToPlayerType = entries.associateBy { it.name }

@JvmStatic
fun setFromString(enumName: String) {
Expand Down Expand Up @@ -129,12 +129,12 @@ enum class PlayerType {

/**
* Check if the current player type is
* [WATCH_WHILE_MAXIMIZED], [WATCH_WHILE_FULLSCREEN], [WATCH_WHILE_SLIDING_MINIMIZED_MAXIMIZED].
* [WATCH_WHILE_MAXIMIZED], [WATCH_WHILE_FULLSCREEN], [WATCH_WHILE_SLIDING_MINIMIZED_MAXIMIZED], [WATCH_WHILE_SLIDING_MAXIMIZED_FULLSCREEN].
*
* Useful to check if a regular video is being played.
*/
fun isMaximizedOrFullscreenOrSliding(): Boolean {
return this == WATCH_WHILE_MAXIMIZED || this == WATCH_WHILE_FULLSCREEN || this == WATCH_WHILE_SLIDING_MINIMIZED_MAXIMIZED
return this == WATCH_WHILE_MAXIMIZED || this == WATCH_WHILE_FULLSCREEN || this == WATCH_WHILE_SLIDING_MINIMIZED_MAXIMIZED || this == WATCH_WHILE_SLIDING_MAXIMIZED_FULLSCREEN
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum class VideoState {

companion object {

private val nameToVideoState = values().associateBy { it.name }
private val nameToVideoState = entries.associateBy { it.name }

@JvmStatic
fun setFromString(enumName: String) {
Expand Down

0 comments on commit 33fb91c

Please sign in to comment.