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 ce3653e
Showing 1 changed file with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,27 +305,45 @@ public static String onRollingNumberLoaded(@NonNull Object conversionContext,
/**
* Injection point.
*/
public static CharSequence updateRollingNumber(CharSequence text) {
public static CharSequence updateRollingNumber(TextView view, CharSequence original) {
try {
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) {
// 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;
if (!SettingsEnum.RYD_ENABLED.getBoolean()) {
return original;
}
// 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 drawable separators.
if (!ReturnYouTubeDislike.isPreviouslyCreatedSegmentedSpan(original.toString())) {
// The text is the video view count, upload time, or some other text.
return original;
}

CharSequence replacement = rollingNumberText;
if (replacement == null) {
// 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 original;
}

// 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);
}

// 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 using only the modified segmented span prevents the animation from showing.
return replacement;
} catch (Exception ex) {
LogHelper.printException(() -> "updateRollingNumber failure", ex);
return original;
}
return text;
}

//
Expand Down

0 comments on commit ce3653e

Please sign in to comment.