mirror of
https://github.com/revanced/revanced-integrations.git
synced 2025-01-21 09:17:33 +01:00
Merge pull request #21 from caneleex/feature/configurable-colors
add support for changing segments' color
This commit is contained in:
commit
b607e72ea7
@ -153,7 +153,9 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
|||||||
entryValues[i] = behaviour.key;
|
entryValues[i] = behaviour.key;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (SponsorBlockSettings.SegmentInfo segmentInfo : SponsorBlockSettings.SegmentInfo.valuesWithoutUnsubmitted()) {
|
SponsorBlockSettings.SegmentInfo[] categories = SponsorBlockSettings.SegmentInfo.valuesWithoutUnsubmitted();
|
||||||
|
|
||||||
|
for (SponsorBlockSettings.SegmentInfo segmentInfo : categories) {
|
||||||
ListPreference preference = new ListPreference(context);
|
ListPreference preference = new ListPreference(context);
|
||||||
preference.setTitle(segmentInfo.getTitleWithDot());
|
preference.setTitle(segmentInfo.getTitleWithDot());
|
||||||
preference.setSummary(segmentInfo.description.toString());
|
preference.setSummary(segmentInfo.description.toString());
|
||||||
@ -161,9 +163,27 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
|||||||
preference.setDefaultValue(defaultValue);
|
preference.setDefaultValue(defaultValue);
|
||||||
preference.setEntries(entries);
|
preference.setEntries(entries);
|
||||||
preference.setEntryValues(entryValues);
|
preference.setEntryValues(entryValues);
|
||||||
|
|
||||||
category.addPreference(preference);
|
category.addPreference(preference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Preference colorPreference = new Preference(context);
|
||||||
|
screen.addPreference(colorPreference);
|
||||||
|
colorPreference.setTitle(str("color_change"));
|
||||||
|
|
||||||
|
colorPreference.setOnPreferenceClickListener(preference1 -> {
|
||||||
|
CharSequence[] items = new CharSequence[categories.length];
|
||||||
|
for (int i = 0; i < items.length; i++) {
|
||||||
|
items[i] = categories[i].getTitleWithDot();
|
||||||
|
}
|
||||||
|
|
||||||
|
new AlertDialog.Builder(context)
|
||||||
|
.setTitle(str("color_choose_category"))
|
||||||
|
.setItems(items, SponsorBlockUtils.categoryColorChangeClickListener)
|
||||||
|
.show();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
preferencesToDisableWhenSBDisabled.add(colorPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addStatsCategory(Context context, PreferenceScreen screen) {
|
private void addStatsCategory(Context context, PreferenceScreen screen) {
|
||||||
|
@ -2,6 +2,7 @@ package pl.jakubweg;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@ -28,6 +29,7 @@ public class SponsorBlockSettings {
|
|||||||
public static final String PREFERENCES_KEY_SKIPPED_SEGMENTS = "sb-skipped-segments";
|
public static final String PREFERENCES_KEY_SKIPPED_SEGMENTS = "sb-skipped-segments";
|
||||||
public static final String PREFERENCES_KEY_SKIPPED_SEGMENTS_TIME = "sb-skipped-segments-time";
|
public static final String PREFERENCES_KEY_SKIPPED_SEGMENTS_TIME = "sb-skipped-segments-time";
|
||||||
public static final String PREFERENCES_KEY_SHOW_TIME_WITHOUT_SEGMENTS = "sb-length-without-segments";
|
public static final String PREFERENCES_KEY_SHOW_TIME_WITHOUT_SEGMENTS = "sb-length-without-segments";
|
||||||
|
public static final String PREFERENCES_KEY_CATEGORY_COLOR_SUFFIX = "_color";
|
||||||
|
|
||||||
public static final SegmentBehaviour DefaultBehaviour = SegmentBehaviour.SKIP_AUTOMATICALLY;
|
public static final SegmentBehaviour DefaultBehaviour = SegmentBehaviour.SKIP_AUTOMATICALLY;
|
||||||
|
|
||||||
@ -93,6 +95,9 @@ public class SponsorBlockSettings {
|
|||||||
SegmentBehaviour[] possibleBehaviours = SegmentBehaviour.values();
|
SegmentBehaviour[] possibleBehaviours = SegmentBehaviour.values();
|
||||||
final ArrayList<String> enabledCategories = new ArrayList<>(possibleBehaviours.length);
|
final ArrayList<String> enabledCategories = new ArrayList<>(possibleBehaviours.length);
|
||||||
for (SegmentInfo segment : SegmentInfo.valuesWithoutUnsubmitted()) {
|
for (SegmentInfo segment : SegmentInfo.valuesWithoutUnsubmitted()) {
|
||||||
|
String categoryColor = preferences.getString(segment.key + PREFERENCES_KEY_CATEGORY_COLOR_SUFFIX, SponsorBlockUtils.formatColorString(segment.defaultColor));
|
||||||
|
segment.setColor(Color.parseColor(categoryColor));
|
||||||
|
|
||||||
SegmentBehaviour behaviour = null;
|
SegmentBehaviour behaviour = null;
|
||||||
String value = preferences.getString(segment.key, null);
|
String value = preferences.getString(segment.key, null);
|
||||||
if (value == null)
|
if (value == null)
|
||||||
@ -191,26 +196,26 @@ public class SponsorBlockSettings {
|
|||||||
public final StringRef title;
|
public final StringRef title;
|
||||||
public final StringRef skipMessage;
|
public final StringRef skipMessage;
|
||||||
public final StringRef description;
|
public final StringRef description;
|
||||||
public final int color;
|
|
||||||
public final Paint paint;
|
public final Paint paint;
|
||||||
|
public final int defaultColor;
|
||||||
|
public int color;
|
||||||
public SegmentBehaviour behaviour;
|
public SegmentBehaviour behaviour;
|
||||||
private CharSequence lazyTitleWithDot;
|
|
||||||
|
|
||||||
SegmentInfo(String key,
|
SegmentInfo(String key,
|
||||||
StringRef title,
|
StringRef title,
|
||||||
StringRef skipMessage,
|
StringRef skipMessage,
|
||||||
StringRef description,
|
StringRef description,
|
||||||
SegmentBehaviour behaviour,
|
SegmentBehaviour behaviour,
|
||||||
int color) {
|
int defaultColor) {
|
||||||
|
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.skipMessage = skipMessage;
|
this.skipMessage = skipMessage;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.behaviour = behaviour;
|
this.behaviour = behaviour;
|
||||||
this.color = color & 0xFFFFFF;
|
this.defaultColor = defaultColor;
|
||||||
paint = new Paint();
|
this.color = defaultColor;
|
||||||
paint.setColor(color);
|
this.paint = new Paint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SegmentInfo[] valuesWithoutUnsubmitted() {
|
public static SegmentInfo[] valuesWithoutUnsubmitted() {
|
||||||
@ -221,10 +226,15 @@ public class SponsorBlockSettings {
|
|||||||
return mValuesMap.get(key);
|
return mValuesMap.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setColor(int color) {
|
||||||
|
color = color & 0xFFFFFF;
|
||||||
|
this.color = color;
|
||||||
|
paint.setColor(color);
|
||||||
|
paint.setAlpha(255);
|
||||||
|
}
|
||||||
|
|
||||||
public CharSequence getTitleWithDot() {
|
public CharSequence getTitleWithDot() {
|
||||||
return (lazyTitleWithDot == null) ?
|
return Html.fromHtml(String.format("<font color=\"#%06X\">⬤</font> %s", color, title));
|
||||||
lazyTitleWithDot = Html.fromHtml(String.format("<font color=\"#%06X\">⬤</font> %s", color, title))
|
|
||||||
: lazyTitleWithDot;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,14 @@ import android.app.AlertDialog;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceCategory;
|
import android.preference.PreferenceCategory;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
|
import android.text.InputType;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -41,6 +44,7 @@ import static pl.jakubweg.PlayerController.getLastKnownVideoTime;
|
|||||||
import static pl.jakubweg.PlayerController.sponsorSegmentsOfCurrentVideo;
|
import static pl.jakubweg.PlayerController.sponsorSegmentsOfCurrentVideo;
|
||||||
import static pl.jakubweg.SponsorBlockPreferenceFragment.FORMATTER;
|
import static pl.jakubweg.SponsorBlockPreferenceFragment.FORMATTER;
|
||||||
import static pl.jakubweg.SponsorBlockPreferenceFragment.SAVED_TEMPLATE;
|
import static pl.jakubweg.SponsorBlockPreferenceFragment.SAVED_TEMPLATE;
|
||||||
|
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_CATEGORY_COLOR_SUFFIX;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.isSponsorBlockEnabled;
|
import static pl.jakubweg.SponsorBlockSettings.isSponsorBlockEnabled;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.showTimeWithoutSegments;
|
import static pl.jakubweg.SponsorBlockSettings.showTimeWithoutSegments;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.skippedSegments;
|
import static pl.jakubweg.SponsorBlockSettings.skippedSegments;
|
||||||
@ -220,6 +224,40 @@ public abstract class SponsorBlockUtils {
|
|||||||
})
|
})
|
||||||
.show();
|
.show();
|
||||||
};
|
};
|
||||||
|
public static final DialogInterface.OnClickListener categoryColorChangeClickListener = (dialog, which) -> {
|
||||||
|
SponsorBlockSettings.SegmentInfo segmentInfo = SponsorBlockSettings.SegmentInfo.valuesWithoutUnsubmitted()[which];
|
||||||
|
String key = segmentInfo.key + PREFERENCES_KEY_CATEGORY_COLOR_SUFFIX;
|
||||||
|
|
||||||
|
Context context = ((AlertDialog) dialog).getContext();
|
||||||
|
EditText editText = new EditText(context);
|
||||||
|
editText.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||||
|
editText.setText(formatColorString(segmentInfo.color));
|
||||||
|
|
||||||
|
Context applicationContext = context.getApplicationContext();
|
||||||
|
SharedPreferences preferences = SponsorBlockSettings.getPreferences(context);
|
||||||
|
|
||||||
|
new AlertDialog.Builder(context)
|
||||||
|
.setView(editText)
|
||||||
|
.setPositiveButton(str("change"), (dialog1, which1) -> {
|
||||||
|
try {
|
||||||
|
int color = Color.parseColor(editText.getText().toString());
|
||||||
|
segmentInfo.setColor(color);
|
||||||
|
Toast.makeText(applicationContext, str("color_changed"), Toast.LENGTH_SHORT).show();
|
||||||
|
preferences.edit().putString(key, formatColorString(color)).apply();
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
Toast.makeText(applicationContext, str("color_invalid"), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNeutralButton(str("reset"), (dialog1, which1) -> {
|
||||||
|
int defaultColor = segmentInfo.defaultColor;
|
||||||
|
segmentInfo.setColor(defaultColor);
|
||||||
|
Toast.makeText(applicationContext, str("color_reset"), Toast.LENGTH_SHORT).show();
|
||||||
|
preferences.edit().putString(key, formatColorString(defaultColor)).apply();
|
||||||
|
})
|
||||||
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
|
.show();
|
||||||
|
};
|
||||||
private static final Runnable submitRunnable = () -> {
|
private static final Runnable submitRunnable = () -> {
|
||||||
messageToToast = null;
|
messageToToast = null;
|
||||||
final String uuid = SponsorBlockSettings.uuid;
|
final String uuid = SponsorBlockSettings.uuid;
|
||||||
@ -445,6 +483,10 @@ public abstract class SponsorBlockUtils {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String formatColorString(int color) {
|
||||||
|
return String.format("#%06X", color);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static void addUserStats(PreferenceCategory category, Preference loadingPreference, UserStats stats) {
|
public static void addUserStats(PreferenceCategory category, Preference loadingPreference, UserStats stats) {
|
||||||
category.removePreference(loadingPreference);
|
category.removePreference(loadingPreference);
|
||||||
|
@ -183,6 +183,14 @@
|
|||||||
<string name="skip_showbutton">Show a skip button</string>
|
<string name="skip_showbutton">Show a skip button</string>
|
||||||
<string name="skip_ignore">Don\'t do anything</string>
|
<string name="skip_ignore">Don\'t do anything</string>
|
||||||
|
|
||||||
|
<string name="color_change">Change colors</string>
|
||||||
|
<string name="color_choose_category">Choose the category</string>
|
||||||
|
<string name="color_changed">Color changed</string>
|
||||||
|
<string name="color_reset">Color reset</string>
|
||||||
|
<string name="color_invalid">Invalid hex code</string>
|
||||||
|
<string name="change">Change</string>
|
||||||
|
<string name="reset">Reset</string>
|
||||||
|
|
||||||
<string name="stats">Stats</string>
|
<string name="stats">Stats</string>
|
||||||
<string name="stats_loading">Loading..</string>
|
<string name="stats_loading">Loading..</string>
|
||||||
<string name="stats_sb_disabled">SponsorBlock is disabled</string>
|
<string name="stats_sb_disabled">SponsorBlock is disabled</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user