add basic support

This commit is contained in:
caneleex 2021-04-16 19:43:03 +02:00
parent c6930e68b5
commit 3e5e99929b
2 changed files with 22 additions and 7 deletions

View File

@ -18,7 +18,6 @@ import android.preference.SwitchPreference;
import android.text.InputType;
import android.widget.Toast;
import java.io.File;
import java.util.ArrayList;
import static pl.jakubweg.SponsorBlockSettings.DefaultBehaviour;
@ -31,10 +30,10 @@ import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_UUID;
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_NAME;
import static pl.jakubweg.SponsorBlockSettings.adjustNewSegmentMillis;
import static pl.jakubweg.SponsorBlockSettings.countSkips;
import static pl.jakubweg.SponsorBlockSettings.getPreferences;
import static pl.jakubweg.SponsorBlockSettings.setSeenGuidelines;
import static pl.jakubweg.SponsorBlockSettings.showToastWhenSkippedAutomatically;
import static pl.jakubweg.SponsorBlockSettings.uuid;
import static pl.jakubweg.StringRef.sf;
import static pl.jakubweg.StringRef.str;
@ -155,7 +154,16 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
preference.setDefaultValue(defaultValue);
preference.setEntries(entries);
preference.setEntryValues(entryValues);
EditTextPreference colorPreference = new EditTextPreference(context);
colorPreference.setTitle("Set " + segmentInfo.title + " color");
colorPreference.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
colorPreference.setKey(segmentInfo.key + "_color");
colorPreference.setDefaultValue(segmentInfo.color);
preferencesToDisableWhenSBDisabled.add(colorPreference);
category.addPreference(preference);
category.addPreference(colorPreference);
}
}

View File

@ -7,7 +7,6 @@ import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@ -108,6 +107,9 @@ public class SponsorBlockSettings {
segment.behaviour = behaviour;
if (behaviour.showOnTimeBar)
enabledCategories.add(segment.key);
String tmp = preferences.getString(segment.key + "_color", String.valueOf(segment.color));
segment.setColor(Integer.parseInt(tmp));
}
//"[%22sponsor%22,%22outro%22,%22music_offtopic%22,%22intro%22,%22selfpromo%22,%22interaction%22]";
@ -183,8 +185,8 @@ public class SponsorBlockSettings {
public final StringRef title;
public final StringRef skipMessage;
public final StringRef description;
public final int color;
public final Paint paint;
public int color;
public SegmentBehaviour behaviour;
private CharSequence lazyTitleWithDot;
@ -201,8 +203,7 @@ public class SponsorBlockSettings {
this.description = description;
this.behaviour = behaviour;
this.color = color & 0xFFFFFF;
paint = new Paint();
paint.setColor(color);
this.paint = new Paint();
}
public static SegmentInfo[] valuesWithoutPreview() {
@ -213,9 +214,15 @@ public class SponsorBlockSettings {
return mValuesMap.get(key);
}
public void setColor(int color) {
this.color = color;
paint.setColor(color);
paint.setAlpha(255);
}
public CharSequence getTitleWithDot() {
return (lazyTitleWithDot == null) ?
lazyTitleWithDot = Html.fromHtml(String.format("<font color=\"#%06X\">⬤</font> %s", color, title))
lazyTitleWithDot = Html.fromHtml(String.format("<font color=\"#%06X\">⬤</font> %s", this.color, title))
: lazyTitleWithDot;
}
}