chore: Merge branch dev to main (#518)

This commit is contained in:
oSumAtrIX 2023-11-19 04:59:59 +01:00 committed by GitHub
commit 7dd826ad71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 52 deletions

View File

@ -1,3 +1,17 @@
## [0.122.1-dev.2](https://github.com/ReVanced/revanced-integrations/compare/v0.122.1-dev.1...v0.122.1-dev.2) (2023-11-18)
### Bug Fixes
* **YouTube - ReturnYouTubeDislike:** Improve layout padding ([#517](https://github.com/ReVanced/revanced-integrations/issues/517)) ([ba15aba](https://github.com/ReVanced/revanced-integrations/commit/ba15aba063d95116d8f028cf9c3b72aa2737fc30))
## [0.122.1-dev.1](https://github.com/ReVanced/revanced-integrations/compare/v0.122.0...v0.122.1-dev.1) (2023-11-18)
### Bug Fixes
* **YouTube:** Check if `protobufBuffer` can be filtered ([b078f0c](https://github.com/ReVanced/revanced-integrations/commit/b078f0ca37020b1aefdbe34724370f6b08c7d600))
# [0.122.0](https://github.com/ReVanced/revanced-integrations/compare/v0.121.0...v0.122.0) (2023-11-18) # [0.122.0](https://github.com/ReVanced/revanced-integrations/compare/v0.121.0...v0.122.0) (2023-11-18)

View File

@ -4,7 +4,6 @@ import android.graphics.Rect;
import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.ShapeDrawable;
import android.os.Build; import android.os.Build;
import android.text.*; import android.text.*;
import android.view.Gravity;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -310,42 +309,50 @@ public class ReturnYouTubeDislikePatch {
} }
/** /**
* Remove Rolling Number text view modifications made by this patch. * Injection point.
* Required as it appears text views can be reused for other rolling numbers (view count, upload time, etc). *
* Called for all usage of Rolling Number.
* Modifies the measured String text width to include the left separator and padding, if needed.
*/ */
private static void removeRollingNumberPatchChanges(TextView view) { public static float onRollingNumberMeasured(String text, float measuredTextWidth) {
if (view.getCompoundDrawablePadding() != 0) { try {
LogHelper.printDebug(() -> "Removing rolling number styling from TextView"); if (SettingsEnum.RYD_ENABLED.getBoolean() && !SettingsEnum.RYD_COMPACT_LAYOUT.getBoolean()) {
view.setCompoundDrawablePadding(0); if (ReturnYouTubeDislike.isPreviouslyCreatedSegmentedSpan(text)) {
view.setCompoundDrawables(null, null, null, null); return measuredTextWidth + ReturnYouTubeDislike.leftSeparatorBounds.right
view.setGravity(Gravity.NO_GRAVITY); + ReturnYouTubeDislike.leftSeparatorShapePaddingPixels;
view.setTextAlignment(View.TEXT_ALIGNMENT_INHERIT); }
view.setSingleLine(false); }
} catch (Exception ex) {
LogHelper.printException(() -> "onRollingNumberMeasured failure", ex);
} }
return measuredTextWidth;
} }
/** /**
* Add Rolling Number text view modifications. * Add Rolling Number text view modifications.
*/ */
private static void addRollingNumberPatchChanges(TextView view) { private static void addRollingNumberPatchChanges(TextView view) {
// YouTube Rolling Numbers do not use compound drawables or drawable padding.
if (view.getCompoundDrawablePadding() == 0) { if (view.getCompoundDrawablePadding() == 0) {
LogHelper.printDebug(() -> "Adding rolling number styling to TextView"); LogHelper.printDebug(() -> "Adding rolling number TextView changes");
// YouTube Rolling Numbers do not use compound drawables or drawable padding. ShapeDrawable leftSeparator = ReturnYouTubeDislike.getLeftSeparatorDrawable();
// view.setCompoundDrawables(leftSeparator, null, null, null);
// Single line mode prevents entire words from being entirely clipped,
// and instead only clips the portion of text that runs off.
// The text should not clip due to the empty end padding,
// but use the feature just in case.
view.setSingleLine(true);
// Center align to distribute the horizontal padding.
view.setGravity(Gravity.CENTER);
view.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
ShapeDrawable shapeDrawable = ReturnYouTubeDislike.getLeftSeparatorDrawable();
view.setCompoundDrawables(shapeDrawable, null, null, null);
view.setCompoundDrawablePadding(ReturnYouTubeDislike.leftSeparatorShapePaddingPixels); view.setCompoundDrawablePadding(ReturnYouTubeDislike.leftSeparatorShapePaddingPixels);
} }
} }
/**
* Remove Rolling Number text view modifications made by this patch.
* Required as it appears text views can be reused for other rolling numbers (view count, upload time, etc).
*/
private static void removeRollingNumberPatchChanges(TextView view) {
if (view.getCompoundDrawablePadding() != 0) {
LogHelper.printDebug(() -> "Removing rolling number TextView changes");
view.setCompoundDrawablePadding(0);
view.setCompoundDrawables(null, null, null, null);
}
}
/** /**
* Injection point. * Injection point.
*/ */
@ -372,14 +379,7 @@ public class ReturnYouTubeDislikePatch {
return original; return original;
} }
// TextView does not display the tall left separator correctly,
// as it goes outside the height bounds and messes up the layout.
// Fix this by applying the left separator as a text view compound drawable.
// This creates a new issue as the compound drawable is not taken into the
// layout width sizing, but that is fixed in the span itself where it uses a blank
// padding string that adds to the layout width but is later ignored during UI drawing.
if (SettingsEnum.RYD_COMPACT_LAYOUT.getBoolean()) { if (SettingsEnum.RYD_COMPACT_LAYOUT.getBoolean()) {
// Do not apply any TextView changes, and text should always fit without clipping.
removeRollingNumberPatchChanges(view); removeRollingNumberPatchChanges(view);
} else { } else {
addRollingNumberPatchChanges(view); addRollingNumberPatchChanges(view);

View File

@ -490,9 +490,15 @@ public final class LithoFilterPatch {
ByteBuffer protobufBuffer = bufferThreadLocal.get(); ByteBuffer protobufBuffer = bufferThreadLocal.get();
if (protobufBuffer == null) { if (protobufBuffer == null) {
LogHelper.printException(() -> "Proto buffer is null"); // Should never happen LogHelper.printException(() -> "Proto buffer is null"); // Should never happen.
return false; return false;
} }
if (!protobufBuffer.hasArray()) {
LogHelper.printDebug(() -> "Proto buffer does not have an array");
return false;
}
LithoFilterParameters parameter = new LithoFilterParameters(lithoIdentifier, pathBuilder, protobufBuffer); LithoFilterParameters parameter = new LithoFilterParameters(lithoIdentifier, pathBuilder, protobufBuffer);
LogHelper.printDebug(() -> "Searching " + parameter); LogHelper.printDebug(() -> "Searching " + parameter);

View File

@ -113,7 +113,7 @@ public class ReturnYouTubeDislike {
private static NumberFormat dislikePercentageFormatter; private static NumberFormat dislikePercentageFormatter;
// Used for segmented dislike spans in Litho regular player. // Used for segmented dislike spans in Litho regular player.
private static final Rect leftSeparatorBounds; public static final Rect leftSeparatorBounds;
private static final Rect middleSeparatorBounds; private static final Rect middleSeparatorBounds;
/** /**
@ -260,31 +260,17 @@ public class ReturnYouTubeDislike {
ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape()); ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
shapeDrawable.getPaint().setColor(getSeparatorColor()); shapeDrawable.getPaint().setColor(getSeparatorColor());
shapeDrawable.setBounds(middleSeparatorBounds); shapeDrawable.setBounds(middleSeparatorBounds);
// Use original text width if using compact layout with Rolling Number, // Use original text width if using Rolling Number,
// as there is no empty padding to allow any layout width differences. // to ensure the replacement styled span has the same width as the measured String,
// otherwise layout can be broken (especially on devices with small system font sizes).
middleSeparatorSpan.setSpan( middleSeparatorSpan.setSpan(
new VerticallyCenteredImageSpan(shapeDrawable, isRollingNumber && compactLayout), new VerticallyCenteredImageSpan(shapeDrawable, isRollingNumber),
shapeInsertionIndex, shapeInsertionIndex + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); shapeInsertionIndex, shapeInsertionIndex + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
builder.append(middleSeparatorSpan); builder.append(middleSeparatorSpan);
// dislikes // dislikes
builder.append(newSpannableWithDislikes(oldSpannable, voteData)); builder.append(newSpannableWithDislikes(oldSpannable, voteData));
// Add some padding for Rolling Number segmented span.
// Use an empty width span, as the layout uses the measured text width and not the
// actual span width. So adding padding and then removing it while drawing gives some
// extra wiggle room for the left separator drawable (which is not included in layout width).
if (isRollingNumber && !compactLayout) {
// To test this, set the device system font to the smallest available.
// If text clipping still occurs, then increase the number of padding spaces below.
// Any extra width will be padded around the like/dislike string
// as it's set to center text alignment.
Spannable rightPaddingString = new SpannableString(" ");
rightPaddingString.setSpan(new FixedWidthEmptySpan(0), 0,
rightPaddingString.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
builder.append(rightPaddingString);
}
return new SpannableString(builder); return new SpannableString(builder);
} }

View File

@ -1,4 +1,4 @@
org.gradle.parallel = true org.gradle.parallel = true
org.gradle.caching = true org.gradle.caching = true
android.useAndroidX = true android.useAndroidX = true
version = 0.122.0 version = 0.122.1-dev.2