This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
forked from ReVanced/revanced-integrations
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube - Hide feed components): Add
Hide related videos
setting
- Loading branch information
Showing
7 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
app/src/main/java/app/revanced/integrations/youtube/patches/feed/RelatedVideoPatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/app/revanced/integrations/youtube/patches/utils/BottomSheetHookPatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
app/src/main/java/app/revanced/integrations/youtube/shared/BottomSheetState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters