1
mirror of https://github.com/revanced/revanced-integrations synced 2024-11-22 05:02:19 +01:00

fix(YouTube - Hide Shorts components): Hide old layout like/dislike buttons without leaving empty space

Also change hide by 1dp to 0dp, and consolidate two methods together
This commit is contained in:
LisoUseInAIKyrios 2024-05-15 22:16:30 +04:00
parent 578a27dea5
commit 978233843d
3 changed files with 31 additions and 31 deletions

View File

@ -15,6 +15,7 @@ import android.preference.PreferenceGroup;
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;
@ -94,7 +95,7 @@ public class Utils {
* @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);
@ -116,6 +117,15 @@ public class Utils {
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.
@ -412,27 +422,30 @@ public class Utils {
}
/**
* 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);
}
}

View File

@ -175,7 +175,7 @@ public final class AdsFilter extends Filter {
* @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);
}
/**

View File

@ -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;
@ -317,29 +314,19 @@ 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,
// 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) {