mirror of
https://github.com/ReVanced/revanced-patches.git
synced 2026-01-11 13:46:17 +00: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();
|
SegmentCategory[] categories = SegmentCategory.categoriesWithoutHighlights();
|
||||||
CharSequence[] titles = new CharSequence[categories.length];
|
CharSequence[] titles = new CharSequence[categories.length];
|
||||||
for (int i = 0, length = categories.length; i < length; i++) {
|
for (int i = 0, length = categories.length; i < length; i++) {
|
||||||
titles[i] = categories[i].getTitle().toString();
|
titles[i] = categories[i].getTitleWithColorDot();
|
||||||
}
|
}
|
||||||
|
|
||||||
newUserCreatedSegmentCategory = null;
|
newUserCreatedSegmentCategory = null;
|
||||||
@@ -336,8 +336,8 @@ public class SponsorBlockUtils {
|
|||||||
Utils.verifyOnMainThread();
|
Utils.verifyOnMainThread();
|
||||||
final SegmentCategory[] values = SegmentCategory.categoriesWithoutHighlights();
|
final SegmentCategory[] values = SegmentCategory.categoriesWithoutHighlights();
|
||||||
CharSequence[] titles = new CharSequence[values.length];
|
CharSequence[] titles = new CharSequence[values.length];
|
||||||
for (int i = 0, length = values.length; i < length; i++) {
|
for (int i = 0; i < values.length; i++) {
|
||||||
titles[i] = values[i].getTitle().toString();
|
titles[i] = values[i].getTitleWithColorDot();
|
||||||
}
|
}
|
||||||
|
|
||||||
new AlertDialog.Builder(context)
|
new AlertDialog.Builder(context)
|
||||||
|
|||||||
@@ -5,8 +5,12 @@ import static app.revanced.extension.youtube.settings.Settings.*;
|
|||||||
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
import android.text.Spannable;
|
||||||
|
import android.text.SpannableString;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import android.text.style.ForegroundColorSpan;
|
||||||
|
import android.text.style.RelativeSizeSpan;
|
||||||
import androidx.annotation.ColorInt;
|
import androidx.annotation.ColorInt;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -83,6 +87,8 @@ public enum SegmentCategory {
|
|||||||
MUSIC_OFFTOPIC,
|
MUSIC_OFFTOPIC,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static final String COLOR_DOT_STRING = "⬤";
|
||||||
|
|
||||||
public static final float CATEGORY_DEFAULT_OPACITY = 0.7f;
|
public static final float CATEGORY_DEFAULT_OPACITY = 0.7f;
|
||||||
|
|
||||||
private static final Map<String, SegmentCategory> mValuesMap = new HashMap<>(2 * categoriesWithoutUnsubmitted.length);
|
private static final Map<String, SegmentCategory> mValuesMap = new HashMap<>(2 * categoriesWithoutUnsubmitted.length);
|
||||||
@@ -324,6 +330,32 @@ public enum SegmentCategory {
|
|||||||
return title;
|
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.
|
* Gets the skip button text based on segment position.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user