mirror of
https://github.com/revanced/revanced-patches.git
synced 2025-12-07 01:51:27 +01:00
fix(YouTube - SponsorBlock): Show category color in create new segment menu (#5987)
This commit is contained in:
@@ -96,7 +96,7 @@ public class SponsorBlockUtils {
|
||||
SegmentCategory[] categories = SegmentCategory.categoriesWithoutHighlights();
|
||||
CharSequence[] titles = new CharSequence[categories.length];
|
||||
for (int i = 0, length = categories.length; i < length; i++) {
|
||||
titles[i] = categories[i].getTitle().toString();
|
||||
titles[i] = categories[i].getTitleWithColorDot();
|
||||
}
|
||||
|
||||
newUserCreatedSegmentCategory = null;
|
||||
@@ -336,8 +336,8 @@ public class SponsorBlockUtils {
|
||||
Utils.verifyOnMainThread();
|
||||
final SegmentCategory[] values = SegmentCategory.categoriesWithoutHighlights();
|
||||
CharSequence[] titles = new CharSequence[values.length];
|
||||
for (int i = 0, length = values.length; i < length; i++) {
|
||||
titles[i] = values[i].getTitle().toString();
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
titles[i] = values[i].getTitleWithColorDot();
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
|
||||
@@ -5,8 +5,12 @@ import static app.revanced.extension.youtube.settings.Settings.*;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.style.RelativeSizeSpan;
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -83,6 +87,8 @@ public enum SegmentCategory {
|
||||
MUSIC_OFFTOPIC,
|
||||
};
|
||||
|
||||
public static final String COLOR_DOT_STRING = "⬤";
|
||||
|
||||
public static final float CATEGORY_DEFAULT_OPACITY = 0.7f;
|
||||
|
||||
private static final Map<String, SegmentCategory> mValuesMap = new HashMap<>(2 * categoriesWithoutUnsubmitted.length);
|
||||
@@ -324,6 +330,32 @@ public enum SegmentCategory {
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link SpannableString} that starts with a colored dot followed by the provided text.
|
||||
*/
|
||||
private static SpannableString getCategoryColorDotSpan(String text, @ColorInt int color) {
|
||||
SpannableString dotSpan = new SpannableString(COLOR_DOT_STRING + text);
|
||||
dotSpan.setSpan(new ForegroundColorSpan(color), 0, 1,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
dotSpan.setSpan(new RelativeSizeSpan(1.5f), 0, 1,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
return dotSpan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the category title with a colored dot.
|
||||
*/
|
||||
public SpannableString getTitleWithColorDot(@ColorInt int categoryColor) {
|
||||
return getCategoryColorDotSpan(" " + title, categoryColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the category title with a colored dot.
|
||||
*/
|
||||
public SpannableString getTitleWithColorDot() {
|
||||
return getTitleWithColorDot(color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the skip button text based on segment position.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user