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

Commit

Permalink
fix(YouTube - Hide Shorts components): Hide old layout like/dislike b…
Browse files Browse the repository at this point in the history
…uttons without leaving empty space

Also change hide by 1dp to 0dp, and consolidate two methods together
  • Loading branch information
LisoUseInAIKyrios committed May 15, 2024
1 parent 578a27d commit 9782338
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
29 changes: 21 additions & 8 deletions app/src/main/java/app/revanced/integrations/shared/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.preference.PreferenceScreen;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
Expand Down Expand Up @@ -94,7 +95,7 @@ public static String getAppVersionName() {
* @param condition The setting to check for hiding the view.
* @param view The view to hide.
*/
public static void hideViewBy1dpUnderCondition(BooleanSetting condition, View view) {
public static void hideViewBy0dpUnderCondition(BooleanSetting condition, View view) {
if (!condition.get()) return;

Logger.printDebug(() -> "Hiding view with setting: " + condition);
Expand All @@ -116,6 +117,15 @@ public static void hideViewUnderCondition(BooleanSetting condition, View view) {
view.setVisibility(View.GONE);
}

public static void removeViewFromParentUnderConditions(BooleanSetting setting, View view) {
if (setting.get()) {
ViewParent parent = view.getParent();
if (parent instanceof ViewGroup) {
((ViewGroup) parent).removeView(view);
}
}
}

/**
* General purpose pool for network calls and other background tasks.
* All tasks run at max thread priority.
Expand Down Expand Up @@ -412,27 +422,30 @@ public static NetworkType getNetworkType() {
}

/**
* Hide a view by setting its layout params to 1x1
* Hide a view by setting its layout params to 0x0
* @param view The view to hide.
*/
public static void hideViewByLayoutParams(View view) {
if (view instanceof LinearLayout) {
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(1, 1);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, 0);
view.setLayoutParams(layoutParams);
} else if (view instanceof FrameLayout) {
FrameLayout.LayoutParams layoutParams2 = new FrameLayout.LayoutParams(1, 1);
FrameLayout.LayoutParams layoutParams2 = new FrameLayout.LayoutParams(0, 0);
view.setLayoutParams(layoutParams2);
} else if (view instanceof RelativeLayout) {
RelativeLayout.LayoutParams layoutParams3 = new RelativeLayout.LayoutParams(1, 1);
RelativeLayout.LayoutParams layoutParams3 = new RelativeLayout.LayoutParams(0, 0);
view.setLayoutParams(layoutParams3);
} else if (view instanceof Toolbar) {
Toolbar.LayoutParams layoutParams4 = new Toolbar.LayoutParams(1, 1);
Toolbar.LayoutParams layoutParams4 = new Toolbar.LayoutParams(0, 0);
view.setLayoutParams(layoutParams4);
} else if (view instanceof ViewGroup) {
ViewGroup.LayoutParams layoutParams5 = new ViewGroup.LayoutParams(1, 1);
ViewGroup.LayoutParams layoutParams5 = new ViewGroup.LayoutParams(0, 0);
view.setLayoutParams(layoutParams5);
} else {
Logger.printDebug(() -> "Hidden view with id " + view.getId());
ViewGroup.LayoutParams params = view.getLayoutParams();
params.width = 0;
params.height = 0;
view.setLayoutParams(params);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBuff
* @param view The view, which shows ads.
*/
public static void hideAdAttributionView(View view) {
Utils.hideViewBy1dpUnderCondition(Settings.HIDE_GENERAL_ADS, view);
Utils.hideViewBy0dpUnderCondition(Settings.HIDE_GENERAL_ADS, view);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package app.revanced.integrations.youtube.patches.components;

import static app.revanced.integrations.shared.Utils.hideViewUnderCondition;
import static app.revanced.integrations.shared.Utils.removeViewFromParentUnderConditions;
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 @@ -317,29 +314,19 @@ 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,
// Cannot 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);
//
// Setting the view to 0dp works, but that leaves a blank space where
// the button was (only relevant for dislikes button).
//
// Instead remove the view from the parent.
removeViewFromParentUnderConditions(Settings.HIDE_SHORTS_LIKE_BUTTON, likeButtonView);
}

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

public static void hideShortsCommentsButton(final View commentsButtonView) {
Expand Down

0 comments on commit 9782338

Please sign in to comment.