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

Commit

Permalink
Fix vertical alignment issues.
Browse files Browse the repository at this point in the history
Fix clipping of dislikes text.
  • Loading branch information
LisoUseInAIKyrios committed Nov 15, 2023
1 parent 309e45e commit 030301d
Showing 1 changed file with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,27 +305,41 @@ public static String onRollingNumberLoaded(@NonNull Object conversionContext,
/**
* Injection point.
*/
public static CharSequence updateRollingNumber(CharSequence text) {
public static void updateRollingNumber(TextView view, CharSequence text) {
try {
// When displaying dislikes, the rolling animation is not visually correct
// and the dislikes always animate (even though the dislike count has not changed).
// The animation is caused by an image span attached to the span,
// and setting only the modified segmented span prevents the animation from showing.
if (SettingsEnum.RYD_ENABLED.getBoolean()) {
// Called for all instances of RollingNumber, so must check if text is for a dislikes.
// Text will already have the correct content, but it's missing the separators and Span styling.
if (!ReturnYouTubeDislike.isPreviouslyCreatedSegmentedSpan(text.toString())) {
return text; // Text is the video view count, upload time, or some other text.
}
CharSequence replacement = rollingNumberText;
if (replacement == null) {
// Text will already have the correct content but it's missing the drawable separators.
if (ReturnYouTubeDislike.isPreviouslyCreatedSegmentedSpan(text.toString())) {
CharSequence replacement = rollingNumberText;
if (replacement != null) {
// The TextView width is set by YouTube based on the underlying text,
// and ignores the size of the drawable separator spans.
// Because of this, the replacement styled span is sometimes slightly larger
// than the measured underlying text, causing the dislikes to be clipped and not shown.
// This is most common on devices with strange system fonts or when using a small system font.
// Setting the TextView to auto size fixes any width issue and dislikes are never clipped.
if (view.getAutoSizeTextType() != TextView.AUTO_SIZE_TEXT_TYPE_UNIFORM) {
view.setAutoSizeTextTypeWithDefaults(TextView.AUTO_SIZE_TEXT_TYPE_UNIFORM);
}
view.setText(replacement);
return;
}
// User enabled RYD while a video was open,
// or user opened/closed a Short while a regular video was opened.
LogHelper.printDebug(() -> "Cannot update rolling number (field is null");
return text;
}
return rollingNumberText;
} // else, the text is the video view count, upload time, or some other text.
}

// Use the original unmodified text.
view.setText(text);
} catch (Exception ex) {
LogHelper.printException(() -> "updateRollingNumber failure", ex);
}
return text;
}

//
Expand Down

0 comments on commit 030301d

Please sign in to comment.