mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-13 05:37:40 +02:00
fix(YouTube Music - Return YouTube Dislike): Length of the separator is different in the new action bar
This commit is contained in:
@ -20,6 +20,7 @@ import app.revanced.extension.shared.utils.Logger;
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class ReturnYouTubeDislikePatch {
|
||||
private static volatile boolean isNewActionBar = false;
|
||||
|
||||
/**
|
||||
* Injection point.
|
||||
@ -52,7 +53,7 @@ public class ReturnYouTubeDislikePatch {
|
||||
if (!(original instanceof Spanned)) {
|
||||
original = new SpannableString(original);
|
||||
}
|
||||
return videoData.getDislikesSpan((Spanned) original, true);
|
||||
return videoData.getDislikesSpan((Spanned) original, true, isNewActionBar);
|
||||
} catch (Exception ex) {
|
||||
Logger.printException(() -> "onLithoTextLoaded failure", ex);
|
||||
}
|
||||
@ -90,13 +91,21 @@ public class ReturnYouTubeDislikePatch {
|
||||
if (videoData == null) {
|
||||
return original; // User enabled RYD while a video was on screen.
|
||||
}
|
||||
return videoData.getDislikesSpan(original, false);
|
||||
return videoData.getDislikesSpan(original, false, false);
|
||||
} catch (Exception ex) {
|
||||
Logger.printException(() -> "onSpannedCreated failure", ex);
|
||||
}
|
||||
return original;
|
||||
}
|
||||
|
||||
/**
|
||||
* Injection point.
|
||||
*/
|
||||
public static boolean actionBarFeatureFlagLoaded(boolean original) {
|
||||
isNewActionBar = original;
|
||||
return original;
|
||||
}
|
||||
|
||||
/**
|
||||
* Injection point.
|
||||
*/
|
||||
|
@ -159,7 +159,8 @@ public class ReturnYouTubeDislike {
|
||||
@NonNull
|
||||
private static SpannableString createDislikeSpan(@NonNull Spanned oldSpannable,
|
||||
@NonNull RYDVoteData voteData,
|
||||
boolean isLithoText) {
|
||||
boolean isLithoText,
|
||||
boolean isNewActionBar) {
|
||||
CharSequence oldLikes = oldSpannable;
|
||||
|
||||
// YouTube creators can hide the like count on a video,
|
||||
@ -191,9 +192,17 @@ public class ReturnYouTubeDislike {
|
||||
|
||||
if (middleSeparatorBounds == null) {
|
||||
final DisplayMetrics dp = Utils.getResources().getDisplayMetrics();
|
||||
final int unit;
|
||||
if (isNewActionBar) {
|
||||
unit = 15;
|
||||
} else if (isLithoText) {
|
||||
unit = 23;
|
||||
} else {
|
||||
unit = 25;
|
||||
}
|
||||
leftSeparatorBounds = new Rect(0, 0,
|
||||
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1.2f, dp),
|
||||
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, isLithoText ? 23 : 25, dp));
|
||||
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, unit, dp));
|
||||
final int middleSeparatorSize =
|
||||
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3.7f, dp);
|
||||
middleSeparatorBounds = new Rect(0, 0, middleSeparatorSize, middleSeparatorSize);
|
||||
@ -439,12 +448,12 @@ public class ReturnYouTubeDislike {
|
||||
* @return the replacement span containing dislikes, or the original span if RYD is not available.
|
||||
*/
|
||||
@NonNull
|
||||
public synchronized Spanned getDislikesSpan(@NonNull Spanned original, boolean isLithoText) {
|
||||
return waitForFetchAndUpdateReplacementSpan(original, isLithoText);
|
||||
public synchronized Spanned getDislikesSpan(@NonNull Spanned original, boolean isLithoText, boolean isNewActionBar) {
|
||||
return waitForFetchAndUpdateReplacementSpan(original, isLithoText, isNewActionBar);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Spanned waitForFetchAndUpdateReplacementSpan(@NonNull Spanned original, boolean isLithoText) {
|
||||
private Spanned waitForFetchAndUpdateReplacementSpan(@NonNull Spanned original, boolean isLithoText, boolean isNewActionBar) {
|
||||
try {
|
||||
RYDVoteData votingData = getFetchData(MAX_MILLISECONDS_TO_BLOCK_UI_WAITING_FOR_FETCH);
|
||||
if (votingData == null) {
|
||||
@ -479,7 +488,7 @@ public class ReturnYouTubeDislike {
|
||||
votingData.updateUsingVote(userVote);
|
||||
}
|
||||
originalDislikeSpan = original;
|
||||
replacementLikeDislikeSpan = createDislikeSpan(original, votingData, isLithoText);
|
||||
replacementLikeDislikeSpan = createDislikeSpan(original, votingData, isLithoText, isNewActionBar);
|
||||
Logger.printDebug(() -> "Replaced: '" + originalDislikeSpan + "' with: '"
|
||||
+ replacementLikeDislikeSpan + "'" + " using video: " + videoId);
|
||||
|
||||
|
Reference in New Issue
Block a user