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

Commit

Permalink
Work around layout bug in RollingNumber, if a better solution is not …
Browse files Browse the repository at this point in the history
…found.
  • Loading branch information
LisoUseInAIKyrios committed Nov 16, 2023
1 parent a3b9436 commit 3f8655f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
}
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down

0 comments on commit 3f8655f

Please sign in to comment.