From 3f8655fa3becefd74d8881cf3af10cb85b5515e1 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Thu, 16 Nov 2023 11:57:23 +0200 Subject: [PATCH] Work around layout bug in RollingNumber, if a better solution is not found. --- .../patches/HideBreakingNewsPatch.java | 11 ++++----- .../patches/ReturnYouTubeDislikePatch.java | 6 ++--- .../patches/spoof/SpoofAppVersionPatch.java | 15 ++++++++++-- .../ReturnYouTubeDislike.java | 23 ++++++++++++++----- .../ReturnYouTubeDislikeSettingsFragment.java | 4 ++-- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/patches/HideBreakingNewsPatch.java b/app/src/main/java/app/revanced/integrations/patches/HideBreakingNewsPatch.java index 465c28367d..bb2d76b2f9 100644 --- a/app/src/main/java/app/revanced/integrations/patches/HideBreakingNewsPatch.java +++ b/app/src/main/java/app/revanced/integrations/patches/HideBreakingNewsPatch.java @@ -2,28 +2,27 @@ import android.view.View; +import app.revanced.integrations.patches.spoof.SpoofAppVersionPatch; import app.revanced.integrations.settings.SettingsEnum; import app.revanced.integrations.utils.ReVancedUtils; public class HideBreakingNewsPatch { /** - * When spoofing to app versions older than 17.30.35, the watch history preview bar uses + * When spoofing to app versions 17.31.00 and older, the watch history preview bar uses * the same layout components as the breaking news shelf. * * Breaking news does not appear to be present in these older versions anyways. */ - private static boolean isSpoofingOldVersionWithHorizontalCardListWatchHistory() { - return SettingsEnum.SPOOF_APP_VERSION.getBoolean() - && SettingsEnum.SPOOF_APP_VERSION_TARGET.getString().compareTo("17.30.35") < 0; - } + private static final boolean isSpoofingOldVersionWithHorizontalCardListWatchHistory = + SpoofAppVersionPatch.isSpoofingToEqualOrLessThan("17.31.00"); /** * Injection point. */ public static void hideBreakingNews(View view) { if (!SettingsEnum.HIDE_BREAKING_NEWS.getBoolean() - || isSpoofingOldVersionWithHorizontalCardListWatchHistory()) return; + || isSpoofingOldVersionWithHorizontalCardListWatchHistory) return; ReVancedUtils.hideViewByLayoutParams(view); } } diff --git a/app/src/main/java/app/revanced/integrations/patches/ReturnYouTubeDislikePatch.java b/app/src/main/java/app/revanced/integrations/patches/ReturnYouTubeDislikePatch.java index b1b5c155d3..9d2f79cb0c 100644 --- a/app/src/main/java/app/revanced/integrations/patches/ReturnYouTubeDislikePatch.java +++ b/app/src/main/java/app/revanced/integrations/patches/ReturnYouTubeDislikePatch.java @@ -281,7 +281,7 @@ public static CharSequence onLithoTextLoaded(@NonNull Object conversionContext, * This is saved to a field as it's used in every draw() call. */ @Nullable - private static volatile CharSequence rollingNumberText; + private static volatile CharSequence rollingNumberSpan; /** * Injection point. @@ -292,7 +292,7 @@ public static String onRollingNumberLoaded(@NonNull Object conversionContext, if (SettingsEnum.RYD_ENABLED.getBoolean()) { CharSequence replacement = onLithoTextLoaded(conversionContext, null, original); if (!replacement.toString().equals(original)) { - rollingNumberText = replacement; + rollingNumberSpan = replacement; return replacement.toString(); } // Else, the text was not a likes count but instead the view count or something else. } @@ -317,7 +317,7 @@ public static CharSequence updateRollingNumber(TextView view, CharSequence origi return original; } - CharSequence replacement = rollingNumberText; + CharSequence replacement = rollingNumberSpan; if (replacement == null) { // User enabled RYD while a video was open, // or user opened/closed a Short while a regular video was opened. diff --git a/app/src/main/java/app/revanced/integrations/patches/spoof/SpoofAppVersionPatch.java b/app/src/main/java/app/revanced/integrations/patches/spoof/SpoofAppVersionPatch.java index c43d603127..8f74b580aa 100644 --- a/app/src/main/java/app/revanced/integrations/patches/spoof/SpoofAppVersionPatch.java +++ b/app/src/main/java/app/revanced/integrations/patches/spoof/SpoofAppVersionPatch.java @@ -4,10 +4,21 @@ public class SpoofAppVersionPatch { + private static final boolean SPOOF_APP_VERSION_ENABLED = SettingsEnum.SPOOF_APP_VERSION.getBoolean(); + private static final String SPOOF_APP_VERSION_TARGET = SettingsEnum.SPOOF_APP_VERSION_TARGET.getString(); + + /** + * Injection point + */ public static String getYouTubeVersionOverride(String version) { - if (SettingsEnum.SPOOF_APP_VERSION.getBoolean()) { - return SettingsEnum.SPOOF_APP_VERSION_TARGET.getString(); + if (SPOOF_APP_VERSION_ENABLED) { + return SPOOF_APP_VERSION_TARGET; } return version; } + + public static boolean isSpoofingToEqualOrLessThan(String version) { + return SPOOF_APP_VERSION_ENABLED && SPOOF_APP_VERSION_TARGET.compareTo(version) <= 0; + } + } diff --git a/app/src/main/java/app/revanced/integrations/returnyoutubedislike/ReturnYouTubeDislike.java b/app/src/main/java/app/revanced/integrations/returnyoutubedislike/ReturnYouTubeDislike.java index ac28109b89..c2e685bbde 100644 --- a/app/src/main/java/app/revanced/integrations/returnyoutubedislike/ReturnYouTubeDislike.java +++ b/app/src/main/java/app/revanced/integrations/returnyoutubedislike/ReturnYouTubeDislike.java @@ -36,6 +36,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import app.revanced.integrations.patches.spoof.SpoofAppVersionPatch; import app.revanced.integrations.returnyoutubedislike.requests.RYDVoteData; import app.revanced.integrations.returnyoutubedislike.requests.ReturnYouTubeDislikeApi; import app.revanced.integrations.settings.SettingsEnum; @@ -121,11 +122,21 @@ public enum Vote { static { DisplayMetrics dp = Objects.requireNonNull(ReVancedUtils.getContext()).getResources().getDisplayMetrics(); + // DIP is the correct type to use so the separators are always the same size on screen + // (regardless of the device font settings). + // But due to weird behavior of the underlying TextView used for Rolling Number, + // DIP does not appear as device independent and does not vertically align correct. + // SIP has vertical alignment correct, but the separator sizes are then based on the device font (not ideal). + // Until a correct fix is found, use SIP for Rolling Number + // so at least it's vertical alignment is correct (but separators are still the wrong size for Rolling Number). + final int typeToUse = SpoofAppVersionPatch.isSpoofingToEqualOrLessThan("18.40.34") + ? TypedValue.COMPLEX_UNIT_DIP // Using regular litho and not Rolling Number + : TypedValue.COMPLEX_UNIT_SP; // Using buggy Rolling Number Litho leftSeparatorBounds = new Rect(0, 0, - (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 1.2f, dp), - (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 18, dp)); + (int) TypedValue.applyDimension(typeToUse, 1.2f, dp), + (int) TypedValue.applyDimension(typeToUse, 18, dp)); final int middleSeparatorSize = - (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 3.7f, dp); + (int) TypedValue.applyDimension(typeToUse, 3.7f, dp); middleSeparatorBounds = new Rect(0, 0, middleSeparatorSize, middleSeparatorSize); } @@ -575,7 +586,6 @@ public void setUserVote(@NonNull Vote vote) { class VerticallyCenteredImageSpan extends ImageSpan { public VerticallyCenteredImageSpan(Drawable drawable) { super(drawable); -// super(drawable, DynamicDrawableSpan.ALIGN_CENTER); } @Override @@ -587,11 +597,12 @@ public int getSize(@NonNull Paint paint, @NonNull CharSequence text, Paint.FontMetricsInt paintMetrics = paint.getFontMetricsInt(); final int fontHeight = paintMetrics.descent - paintMetrics.ascent; final int drawHeight = bounds.bottom - bounds.top; + final int halfDrawHeight = drawHeight / 2; final int yCenter = paintMetrics.ascent + fontHeight / 2; - fontMetrics.ascent = yCenter - drawHeight / 2; + fontMetrics.ascent = yCenter - halfDrawHeight; fontMetrics.top = fontMetrics.ascent; - fontMetrics.bottom = yCenter + drawHeight / 2; + fontMetrics.bottom = yCenter + halfDrawHeight; fontMetrics.descent = fontMetrics.bottom; } return bounds.right; diff --git a/app/src/main/java/app/revanced/integrations/settingsmenu/ReturnYouTubeDislikeSettingsFragment.java b/app/src/main/java/app/revanced/integrations/settingsmenu/ReturnYouTubeDislikeSettingsFragment.java index 45fffc2cef..e269c9328b 100644 --- a/app/src/main/java/app/revanced/integrations/settingsmenu/ReturnYouTubeDislikeSettingsFragment.java +++ b/app/src/main/java/app/revanced/integrations/settingsmenu/ReturnYouTubeDislikeSettingsFragment.java @@ -13,6 +13,7 @@ import android.preference.SwitchPreference; import app.revanced.integrations.patches.ReturnYouTubeDislikePatch; +import app.revanced.integrations.patches.spoof.SpoofAppVersionPatch; import app.revanced.integrations.returnyoutubedislike.ReturnYouTubeDislike; import app.revanced.integrations.returnyoutubedislike.requests.ReturnYouTubeDislikeApi; import app.revanced.integrations.settings.SettingsEnum; @@ -21,8 +22,7 @@ public class ReturnYouTubeDislikeSettingsFragment extends PreferenceFragment { private static final boolean IS_SPOOFING_TO_NON_LITHO_SHORTS_PLAYER = - SettingsEnum.SPOOF_APP_VERSION.getBoolean() - && SettingsEnum.SPOOF_APP_VERSION_TARGET.getString().compareTo("18.33.40") <= 0; + SpoofAppVersionPatch.isSpoofingToEqualOrLessThan("18.33.40"); /** * If dislikes are shown on Shorts.