Skip to content

Commit

Permalink
feat(YouTube - Hide Shorts components): Hide like / dislike button in…
Browse files Browse the repository at this point in the history
… video ads (#619)
  • Loading branch information
LisoUseInAIKyrios committed Apr 21, 2024
1 parent 4e64b69 commit b2b6b8c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Expand Up @@ -235,7 +235,7 @@ private static CharSequence onLithoTextLoaded(@NonNull Object conversionContext,
true, isRollingNumber);
} else if (!isRollingNumber && conversionContextString.contains("|shorts_dislike_button.eml|")) {
// Litho Shorts player.
if (!Settings.RYD_SHORTS.get()) {
if (!Settings.RYD_SHORTS.get() || Settings.HIDE_SHORTS_DISLIKE_BUTTON.get()) {
// Must clear the current video here, otherwise if the user opens a regular video
// then opens a litho short (while keeping the regular video on screen), then closes the short,
// the original video may show the incorrect dislike value.
Expand Down Expand Up @@ -451,7 +451,7 @@ public static boolean setShortsDislikes(@NonNull View likeDislikeView) {
if (!Settings.RYD_ENABLED.get()) {
return false;
}
if (!Settings.RYD_SHORTS.get()) {
if (!Settings.RYD_SHORTS.get() || Settings.HIDE_SHORTS_DISLIKE_BUTTON.get()) {
// Must clear the data here, in case a new video was loaded while PlayerType
// suggested the video was not a short (can happen when spoofing to an old app version).
clearData();
Expand Down
Expand Up @@ -4,12 +4,16 @@
import static app.revanced.integrations.youtube.shared.NavigationBar.NavigationButton;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.google.android.libraries.youtube.rendering.ui.pivotbar.PivotBar;

import app.revanced.integrations.shared.Logger;
import app.revanced.integrations.shared.Utils;
import app.revanced.integrations.shared.settings.BooleanSetting;
import app.revanced.integrations.youtube.settings.Settings;
import app.revanced.integrations.youtube.shared.NavigationBar;
import app.revanced.integrations.youtube.shared.PlayerType;
Expand Down Expand Up @@ -310,6 +314,31 @@ public static void hideShortsShelf(final View shortsShelfView) {

// region Hide the buttons in older versions of YouTube. New versions use Litho.

private static void hideTextViewUnderCondition(BooleanSetting setting, View view) {
try {
if (setting.get()) {
TextView textView = (TextView) view;
ViewGroup.LayoutParams params = textView.getLayoutParams();
params.width = 0;
params.height = 0;
textView.setLayoutParams(params);
}
} catch (Exception ex) {
Logger.printException(() -> "hideTextViewUnderCondition failure", ex);
}
}

public static void hideLikeButton(final View likeButtonView) {
// Cannot simply set the visibility to gone for like/dislike,
// as some other unknown YT code also sets the visibility after this hook.
// Instead set the layout to a zero size.
hideTextViewUnderCondition(Settings.HIDE_SHORTS_LIKE_BUTTON, likeButtonView);
}

public static void hideDislikeButton(final View dislikeButtonView) {
hideTextViewUnderCondition(Settings.HIDE_SHORTS_DISLIKE_BUTTON, dislikeButtonView);
}

public static void hideShortsCommentsButton(final View commentsButtonView) {
hideViewUnderCondition(Settings.HIDE_SHORTS_COMMENTS_BUTTON, commentsButtonView);
}
Expand Down

0 comments on commit b2b6b8c

Please sign in to comment.