@@ -74,8 +74,6 @@ public class ReturnYouTubeDislike {
74
74
*/
75
75
private static final char MIDDLE_SEPARATOR_CHARACTER = '◎' ; // 'bullseye'
76
76
77
- private static final int SEPARATOR_COLOR = 872415231 ;
78
-
79
77
/**
80
78
* Cached lookup of all video ids.
81
79
*/
@@ -99,19 +97,11 @@ public class ReturnYouTubeDislike {
99
97
@ GuardedBy ("ReturnYouTubeDislike.class" )
100
98
private static NumberFormat dislikePercentageFormatter ;
101
99
102
- public static final Rect leftSeparatorBounds ;
103
- private static final Rect middleSeparatorBounds ;
104
-
105
- static {
106
- DisplayMetrics dp = Objects .requireNonNull (Utils .getContext ()).getResources ().getDisplayMetrics ();
100
+ public static Rect leftSeparatorBounds ;
101
+ private static Rect middleSeparatorBounds ;
107
102
108
- leftSeparatorBounds = new Rect (0 , 0 ,
109
- (int ) TypedValue .applyDimension (TypedValue .COMPLEX_UNIT_DIP , 1.2f , dp ),
110
- (int ) TypedValue .applyDimension (TypedValue .COMPLEX_UNIT_DIP , 25 , dp ));
111
- final int middleSeparatorSize =
112
- (int ) TypedValue .applyDimension (TypedValue .COMPLEX_UNIT_DIP , 3.7f , dp );
113
- middleSeparatorBounds = new Rect (0 , 0 , middleSeparatorSize , middleSeparatorSize );
114
103
104
+ static {
115
105
ReturnYouTubeDislikeApi .toastOnConnectionError = Settings .RYD_TOAST_ON_CONNECTION_ERROR .get ();
116
106
}
117
107
@@ -150,9 +140,26 @@ public class ReturnYouTubeDislike {
150
140
@ GuardedBy ("this" )
151
141
private SpannableString replacementLikeDislikeSpan ;
152
142
143
+
144
+ /**
145
+ * Color of the left and middle separator, based on the color of the right separator.
146
+ * It's unknown where YT gets the color from, and the values here are approximated by hand.
147
+ * Ideally, this would be the actual color YT uses at runtime.
148
+ * <p>
149
+ * Older versions before the 'Me' library tab use a slightly different color.
150
+ * If spoofing was previously used and is now turned off,
151
+ * or an old version was recently upgraded then the old colors are sometimes still used.
152
+ */
153
+ private static int getSeparatorColor (boolean isLithoText ) {
154
+ return isLithoText
155
+ ? 0x29AAAAAA
156
+ : 0x33FFFFFF ;
157
+ }
158
+
153
159
@ NonNull
154
160
private static SpannableString createDislikeSpan (@ NonNull Spanned oldSpannable ,
155
- @ NonNull RYDVoteData voteData ) {
161
+ @ NonNull RYDVoteData voteData ,
162
+ boolean isLithoText ) {
156
163
CharSequence oldLikes = oldSpannable ;
157
164
158
165
// YouTube creators can hide the like count on a video,
@@ -176,14 +183,27 @@ private static SpannableString createDislikeSpan(@NonNull Spanned oldSpannable,
176
183
}
177
184
}
178
185
179
- SpannableStringBuilder builder = new SpannableStringBuilder ("\u2009 \u2009 " );
186
+ SpannableStringBuilder builder = new SpannableStringBuilder ("\u2009 " );
187
+ if (!isLithoText ) {
188
+ builder .append ("\u2009 " );
189
+ }
180
190
final boolean compactLayout = Settings .RYD_COMPACT_LAYOUT .get ();
181
191
192
+ if (middleSeparatorBounds == null ) {
193
+ final DisplayMetrics dp = Utils .getResources ().getDisplayMetrics ();
194
+ leftSeparatorBounds = new Rect (0 , 0 ,
195
+ (int ) TypedValue .applyDimension (TypedValue .COMPLEX_UNIT_DIP , 1.2f , dp ),
196
+ (int ) TypedValue .applyDimension (TypedValue .COMPLEX_UNIT_DIP , isLithoText ? 23 : 25 , dp ));
197
+ final int middleSeparatorSize =
198
+ (int ) TypedValue .applyDimension (TypedValue .COMPLEX_UNIT_DIP , 3.7f , dp );
199
+ middleSeparatorBounds = new Rect (0 , 0 , middleSeparatorSize , middleSeparatorSize );
200
+ }
201
+
182
202
if (!compactLayout ) {
183
203
String leftSeparatorString = "\u200E " ; // u200E = left to right character
184
204
Spannable leftSeparatorSpan = new SpannableString (leftSeparatorString );
185
205
ShapeDrawable shapeDrawable = new ShapeDrawable (new RectShape ());
186
- shapeDrawable .getPaint ().setColor (SEPARATOR_COLOR );
206
+ shapeDrawable .getPaint ().setColor (getSeparatorColor ( isLithoText ) );
187
207
shapeDrawable .setBounds (leftSeparatorBounds );
188
208
leftSeparatorSpan .setSpan (new VerticallyCenteredImageSpan (shapeDrawable ), 1 , 2 ,
189
209
Spannable .SPAN_INCLUSIVE_EXCLUSIVE ); // drawable cannot overwrite RTL or LTR character
@@ -200,7 +220,7 @@ private static SpannableString createDislikeSpan(@NonNull Spanned oldSpannable,
200
220
final int shapeInsertionIndex = middleSeparatorString .length () / 2 ;
201
221
Spannable middleSeparatorSpan = new SpannableString (middleSeparatorString );
202
222
ShapeDrawable shapeDrawable = new ShapeDrawable (new OvalShape ());
203
- shapeDrawable .getPaint ().setColor (SEPARATOR_COLOR );
223
+ shapeDrawable .getPaint ().setColor (getSeparatorColor ( isLithoText ) );
204
224
shapeDrawable .setBounds (middleSeparatorBounds );
205
225
// Use original text width if using Rolling Number,
206
226
// to ensure the replacement styled span has the same width as the measured String,
@@ -416,12 +436,12 @@ public String getVideoId() {
416
436
* @return the replacement span containing dislikes, or the original span if RYD is not available.
417
437
*/
418
438
@ NonNull
419
- public synchronized Spanned getDislikesSpan (@ NonNull Spanned original ) {
420
- return waitForFetchAndUpdateReplacementSpan (original );
439
+ public synchronized Spanned getDislikesSpan (@ NonNull Spanned original , boolean isLithoText ) {
440
+ return waitForFetchAndUpdateReplacementSpan (original , isLithoText );
421
441
}
422
442
423
443
@ NonNull
424
- private Spanned waitForFetchAndUpdateReplacementSpan (@ NonNull Spanned original ) {
444
+ private Spanned waitForFetchAndUpdateReplacementSpan (@ NonNull Spanned original , boolean isLithoText ) {
425
445
try {
426
446
RYDVoteData votingData = getFetchData (MAX_MILLISECONDS_TO_BLOCK_UI_WAITING_FOR_FETCH );
427
447
if (votingData == null ) {
@@ -456,7 +476,7 @@ private Spanned waitForFetchAndUpdateReplacementSpan(@NonNull Spanned original)
456
476
votingData .updateUsingVote (userVote );
457
477
}
458
478
originalDislikeSpan = original ;
459
- replacementLikeDislikeSpan = createDislikeSpan (original , votingData );
479
+ replacementLikeDislikeSpan = createDislikeSpan (original , votingData , isLithoText );
460
480
Logger .printDebug (() -> "Replaced: '" + originalDislikeSpan + "' with: '"
461
481
+ replacementLikeDislikeSpan + "'" + " using video: " + videoId );
462
482
0 commit comments