feat(YouTube - Hide Shorts components): Hide like / dislike button in video ads (#619)

This commit is contained in:
LisoUseInAIKyrios 2024-04-21 18:55:19 +04:00 committed by GitHub
parent 4e64b690ab
commit b2b6b8c3d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 2 deletions

View File

@ -235,7 +235,7 @@ public class ReturnYouTubeDislikePatch {
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.
@ -451,7 +451,7 @@ public class ReturnYouTubeDislikePatch {
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();

View File

@ -4,12 +4,16 @@ import static app.revanced.integrations.shared.Utils.hideViewUnderCondition;
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;
@ -310,6 +314,31 @@ public final class ShortsFilter extends Filter {
// 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);
}