Skip to content

Commit ffd933c

Browse files
authored
fix(YouTube - SponsorBlock): Show category color in create new segment menu (#5987)
1 parent 6988353 commit ffd933c

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

extensions/youtube/src/main/java/app/revanced/extension/youtube/sponsorblock/SponsorBlockUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void onClick(DialogInterface dialog, int which) {
9696
SegmentCategory[] categories = SegmentCategory.categoriesWithoutHighlights();
9797
CharSequence[] titles = new CharSequence[categories.length];
9898
for (int i = 0, length = categories.length; i < length; i++) {
99-
titles[i] = categories[i].getTitle().toString();
99+
titles[i] = categories[i].getTitleWithColorDot();
100100
}
101101

102102
newUserCreatedSegmentCategory = null;
@@ -336,8 +336,8 @@ private static void onNewCategorySelect(SponsorSegment segment, Context context)
336336
Utils.verifyOnMainThread();
337337
final SegmentCategory[] values = SegmentCategory.categoriesWithoutHighlights();
338338
CharSequence[] titles = new CharSequence[values.length];
339-
for (int i = 0, length = values.length; i < length; i++) {
340-
titles[i] = values[i].getTitle().toString();
339+
for (int i = 0; i < values.length; i++) {
340+
titles[i] = values[i].getTitleWithColorDot();
341341
}
342342

343343
new AlertDialog.Builder(context)

extensions/youtube/src/main/java/app/revanced/extension/youtube/sponsorblock/objects/SegmentCategory.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55

66
import android.graphics.Color;
77
import android.graphics.Paint;
8+
import android.text.Spannable;
9+
import android.text.SpannableString;
810
import android.text.TextUtils;
911

12+
import android.text.style.ForegroundColorSpan;
13+
import android.text.style.RelativeSizeSpan;
1014
import androidx.annotation.ColorInt;
1115
import androidx.annotation.NonNull;
1216
import androidx.annotation.Nullable;
@@ -83,6 +87,8 @@ public enum SegmentCategory {
8387
MUSIC_OFFTOPIC,
8488
};
8589

90+
public static final String COLOR_DOT_STRING = "⬤";
91+
8692
public static final float CATEGORY_DEFAULT_OPACITY = 0.7f;
8793

8894
private static final Map<String, SegmentCategory> mValuesMap = new HashMap<>(2 * categoriesWithoutUnsubmitted.length);
@@ -324,6 +330,32 @@ public StringRef getTitle() {
324330
return title;
325331
}
326332

333+
/**
334+
* Creates a {@link SpannableString} that starts with a colored dot followed by the provided text.
335+
*/
336+
private static SpannableString getCategoryColorDotSpan(String text, @ColorInt int color) {
337+
SpannableString dotSpan = new SpannableString(COLOR_DOT_STRING + text);
338+
dotSpan.setSpan(new ForegroundColorSpan(color), 0, 1,
339+
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
340+
dotSpan.setSpan(new RelativeSizeSpan(1.5f), 0, 1,
341+
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
342+
return dotSpan;
343+
}
344+
345+
/**
346+
* Returns the category title with a colored dot.
347+
*/
348+
public SpannableString getTitleWithColorDot(@ColorInt int categoryColor) {
349+
return getCategoryColorDotSpan(" " + title, categoryColor);
350+
}
351+
352+
/**
353+
* Returns the category title with a colored dot.
354+
*/
355+
public SpannableString getTitleWithColorDot() {
356+
return getTitleWithColorDot(color);
357+
}
358+
327359
/**
328360
* Gets the skip button text based on segment position.
329361
*

0 commit comments

Comments
 (0)