From 2694158c3c9935ede21c96832533222f850068df Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Tue, 17 Dec 2024 04:22:16 +0400 Subject: [PATCH] fix(YouTube - Miniplayer): Use estimated maximum on screen size for devices with low density screens (#4150) --- .../youtube/patches/MiniplayerPatch.java | 38 +++++++++++-------- .../extension/youtube/settings/Settings.java | 2 +- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/MiniplayerPatch.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/MiniplayerPatch.java index 9842f50598..be27811c92 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/MiniplayerPatch.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/MiniplayerPatch.java @@ -82,7 +82,13 @@ public boolean isModern() { final int WIDTH_DIP_MIN = 170; // Seems to be the smallest that works. final int HORIZONTAL_PADDING_DIP = 15; // Estimated padding. // Round down to the nearest 5 pixels, to keep any error toasts easier to read. - final int WIDTH_DIP_MAX = 5 * ((deviceDipWidth - HORIZONTAL_PADDING_DIP) / 5); + final int estimatedWidthDipMax = 5 * ((deviceDipWidth - HORIZONTAL_PADDING_DIP) / 5); + // On some ultra low end devices the pixel width and density are the same number, + // which causes the estimate to always give a value of 1. + // Fix this by using a fixed size of double the min width. + final int WIDTH_DIP_MAX = estimatedWidthDipMax <= WIDTH_DIP_MIN + ? 2 * WIDTH_DIP_MIN + : estimatedWidthDipMax; Logger.printDebug(() -> "Screen dip width: " + deviceDipWidth + " maxWidth: " + WIDTH_DIP_MAX); int dipWidth = Settings.MINIPLAYER_WIDTH_DIP.get(); @@ -127,8 +133,10 @@ public boolean isModern() { private static final boolean HIDE_SUBTEXT_ENABLED = (CURRENT_TYPE == MODERN_1 || CURRENT_TYPE == MODERN_3) && Settings.MINIPLAYER_HIDE_SUBTEXT.get(); - private static final boolean HIDE_REWIND_FORWARD_ENABLED = - CURRENT_TYPE == MODERN_1 && Settings.MINIPLAYER_HIDE_REWIND_FORWARD.get(); + // 19.25 is last version that has forward/back buttons for phones, + // but buttons still show for tablets/foldable devices and they don't work well so always hide. + private static final boolean HIDE_REWIND_FORWARD_ENABLED = CURRENT_TYPE == MODERN_1 + && (VersionCheckPatch.IS_19_34_OR_GREATER || Settings.MINIPLAYER_HIDE_REWIND_FORWARD.get()); private static final boolean MINIPLAYER_ROUNDED_CORNERS_ENABLED = Settings.MINIPLAYER_ROUNDED_CORNERS.get(); @@ -145,6 +153,18 @@ public boolean isModern() { private static final int OPACITY_LEVEL; + static { + int opacity = Settings.MINIPLAYER_OPACITY.get(); + + if (opacity < 0 || opacity > 100) { + Utils.showToastLong(str("revanced_miniplayer_opacity_invalid_toast")); + Settings.MINIPLAYER_OPACITY.resetToDefault(); + opacity = Settings.MINIPLAYER_OPACITY.defaultValue; + } + + OPACITY_LEVEL = (opacity * 255) / 100; + } + public static final class MiniplayerHorizontalDragAvailability implements Setting.Availability { @Override public boolean isAvailable() { @@ -163,18 +183,6 @@ public boolean isAvailable() { } } - static { - int opacity = Settings.MINIPLAYER_OPACITY.get(); - - if (opacity < 0 || opacity > 100) { - Utils.showToastLong(str("revanced_miniplayer_opacity_invalid_toast")); - Settings.MINIPLAYER_OPACITY.resetToDefault(); - opacity = Settings.MINIPLAYER_OPACITY.defaultValue; - } - - OPACITY_LEVEL = (opacity * 255) / 100; - } - /** * Injection point. * diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java index e5027a9cc3..0c0a06721f 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java @@ -149,7 +149,7 @@ public class Settings extends BaseSettings { public static final BooleanSetting MINIPLAYER_HORIZONTAL_DRAG = new BooleanSetting("revanced_miniplayer_horizontal_drag", FALSE, true, new MiniplayerHorizontalDragAvailability()); public static final BooleanSetting MINIPLAYER_HIDE_EXPAND_CLOSE = new BooleanSetting("revanced_miniplayer_hide_expand_close", FALSE, true, new MiniplayerHideExpandCloseAvailability()); public static final BooleanSetting MINIPLAYER_HIDE_SUBTEXT = new BooleanSetting("revanced_miniplayer_hide_subtext", FALSE, true, MINIPLAYER_TYPE.availability(MODERN_1, MODERN_3)); - public static final BooleanSetting MINIPLAYER_HIDE_REWIND_FORWARD = new BooleanSetting("revanced_miniplayer_hide_rewind_forward", FALSE, true, MINIPLAYER_TYPE.availability(MODERN_1)); + public static final BooleanSetting MINIPLAYER_HIDE_REWIND_FORWARD = new BooleanSetting("revanced_miniplayer_hide_rewind_forward", TRUE, true, MINIPLAYER_TYPE.availability(MODERN_1)); public static final BooleanSetting MINIPLAYER_ROUNDED_CORNERS = new BooleanSetting("revanced_miniplayer_rounded_corners", TRUE, true, MINIPLAYER_ANY_MODERN); public static final IntegerSetting MINIPLAYER_WIDTH_DIP = new IntegerSetting("revanced_miniplayer_width_dip", 192, true, MINIPLAYER_ANY_MODERN); public static final IntegerSetting MINIPLAYER_OPACITY = new IntegerSetting("revanced_miniplayer_opacity", 100, true, MINIPLAYER_TYPE.availability(MODERN_1));