mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-12-11 21:17:47 +01:00
final touches
This commit is contained in:
parent
a5c7212db6
commit
64b656f997
@ -5,7 +5,6 @@ import android.app.AlertDialog;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
@ -16,7 +15,6 @@ import android.preference.PreferenceFragment;
|
|||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.preference.SwitchPreference;
|
import android.preference.SwitchPreference;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
@ -26,7 +24,6 @@ import pl.jakubweg.requests.Requester;
|
|||||||
|
|
||||||
import static pl.jakubweg.SponsorBlockSettings.DefaultBehaviour;
|
import static pl.jakubweg.SponsorBlockSettings.DefaultBehaviour;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_ADJUST_NEW_SEGMENT_STEP;
|
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_ADJUST_NEW_SEGMENT_STEP;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_CATEGORY_COLOR_SUFFIX;
|
|
||||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_COUNT_SKIPS;
|
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_COUNT_SKIPS;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_NEW_SEGMENT_ENABLED;
|
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_NEW_SEGMENT_ENABLED;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_SHOW_TIME_WITHOUT_SEGMENTS;
|
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_SHOW_TIME_WITHOUT_SEGMENTS;
|
||||||
@ -41,7 +38,6 @@ import static pl.jakubweg.SponsorBlockSettings.setSeenGuidelines;
|
|||||||
import static pl.jakubweg.SponsorBlockSettings.showTimeWithoutSegments;
|
import static pl.jakubweg.SponsorBlockSettings.showTimeWithoutSegments;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.showToastWhenSkippedAutomatically;
|
import static pl.jakubweg.SponsorBlockSettings.showToastWhenSkippedAutomatically;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.uuid;
|
import static pl.jakubweg.SponsorBlockSettings.uuid;
|
||||||
import static pl.jakubweg.SponsorBlockUtils.formatColorString;
|
|
||||||
import static pl.jakubweg.StringRef.str;
|
import static pl.jakubweg.StringRef.str;
|
||||||
|
|
||||||
@SuppressWarnings({"unused", "deprecation"}) // injected
|
@SuppressWarnings({"unused", "deprecation"}) // injected
|
||||||
@ -157,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());
|
||||||
@ -166,45 +164,26 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
|||||||
preference.setEntries(entries);
|
preference.setEntries(entries);
|
||||||
preference.setEntryValues(entryValues);
|
preference.setEntryValues(entryValues);
|
||||||
|
|
||||||
String key = segmentInfo.key + PREFERENCES_KEY_CATEGORY_COLOR_SUFFIX;
|
category.addPreference(preference);
|
||||||
|
}
|
||||||
|
|
||||||
Preference colorPreference = new Preference(context);
|
Preference colorPreference = new Preference(context);
|
||||||
|
screen.addPreference(colorPreference);
|
||||||
colorPreference.setTitle(str("color_change"));
|
colorPreference.setTitle(str("color_change"));
|
||||||
|
|
||||||
colorPreference.setOnPreferenceClickListener(preference1 -> {
|
colorPreference.setOnPreferenceClickListener(preference1 -> {
|
||||||
EditText editText = new EditText(context);
|
CharSequence[] items = new CharSequence[categories.length];
|
||||||
editText.setInputType(InputType.TYPE_CLASS_TEXT);
|
for (int i = 0; i < items.length; i++) {
|
||||||
editText.setText(formatColorString(segmentInfo.color));
|
items[i] = categories[i].getTitleWithDot();
|
||||||
|
}
|
||||||
Context applicationContext = context.getApplicationContext();
|
|
||||||
SharedPreferences preferences = SponsorBlockSettings.getPreferences(context);
|
|
||||||
|
|
||||||
new AlertDialog.Builder(context)
|
new AlertDialog.Builder(context)
|
||||||
.setView(editText)
|
.setTitle(str("color_choose_category"))
|
||||||
.setPositiveButton(str("change"), (dialog, which) -> {
|
.setItems(items, SponsorBlockUtils.categoryColorChangeClickListener)
|
||||||
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"), (dialog, which) -> {
|
|
||||||
int defaultColor = segmentInfo.defaultColor;
|
|
||||||
segmentInfo.setColor(defaultColor);
|
|
||||||
Toast.makeText(applicationContext, str("color_reset"), Toast.LENGTH_SHORT).show();
|
|
||||||
preferences.edit().putString(key, formatColorString(defaultColor)).apply();
|
|
||||||
})
|
|
||||||
.show();
|
.show();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
preferencesToDisableWhenSBDisabled.add(colorPreference);
|
preferencesToDisableWhenSBDisabled.add(colorPreference);
|
||||||
|
|
||||||
category.addPreference(preference);
|
|
||||||
category.addPreference(colorPreference);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addStatsCategory(Context context, PreferenceScreen screen) {
|
private void addStatsCategory(Context context, PreferenceScreen screen) {
|
||||||
|
@ -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;
|
||||||
@ -40,6 +43,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;
|
||||||
@ -219,6 +223,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;
|
||||||
|
@ -183,12 +183,13 @@
|
|||||||
<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 color</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_changed">Color changed</string>
|
||||||
<string name="color_reset">Color reset</string>
|
<string name="color_reset">Color reset</string>
|
||||||
<string name="color_invalid">Invalid hex code</string>
|
<string name="color_invalid">Invalid hex code</string>
|
||||||
<string name="reset">Reset</string>
|
|
||||||
<string name="change">Change</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>
|
||||||
|
Loading…
Reference in New Issue
Block a user