mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-11-13 23:49:26 +01:00
Fixed string loading, replaced hardcoded strings into string resources
This commit is contained in:
parent
814d7e3f86
commit
0ec26c9a16
@ -1,19 +0,0 @@
|
||||
package pl.jakubweg;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.util.Log;
|
||||
|
||||
public class Helper {
|
||||
|
||||
public static String getStringByName(Context context, String name) {
|
||||
try {
|
||||
Resources res = context.getResources();
|
||||
return res.getString(res.getIdentifier(name, "string", context.getPackageName()));
|
||||
} catch (Throwable exception) {
|
||||
Log.e("XGlobals", "Resource not found.", exception);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,7 @@ package pl.jakubweg;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Handler;
|
||||
@ -9,6 +10,7 @@ import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.Method;
|
||||
@ -19,9 +21,9 @@ import java.util.TimerTask;
|
||||
@SuppressLint({"LongLogTag"})
|
||||
public class PlayerController {
|
||||
public static final String TAG = "jakubweg.PlayerController";
|
||||
public static final boolean VERBOSE = true;
|
||||
public static final boolean VERBOSE = false;
|
||||
@SuppressWarnings("PointlessBooleanExpression")
|
||||
public static final boolean VERBOSE_DRAW_OPTIONS = true && VERBOSE;
|
||||
public static final boolean VERBOSE_DRAW_OPTIONS = false && VERBOSE;
|
||||
|
||||
private static final Timer sponsorTimer = new Timer("sponsor-skip-timer");
|
||||
public static WeakReference<Activity> playerActivity = new WeakReference<>(null);
|
||||
|
@ -12,10 +12,10 @@ import android.widget.Toast;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import static pl.jakubweg.Helper.getStringByName;
|
||||
import static pl.jakubweg.PlayerController.VERBOSE;
|
||||
import static pl.jakubweg.StringRef.str;
|
||||
|
||||
@SuppressLint({"RtlHardcoded", "SetTextI18n", "LongLogTag"})
|
||||
@SuppressLint({"RtlHardcoded", "SetTextI18n", "LongLogTag", "AppCompatCustomView"})
|
||||
public class SkipSegmentView extends TextView implements View.OnClickListener {
|
||||
public static final String TAG = "jakubweg.SkipSegmentView";
|
||||
private static boolean isVisible = false;
|
||||
@ -40,7 +40,7 @@ public class SkipSegmentView extends TextView implements View.OnClickListener {
|
||||
int padding = (int) convertDpToPixel(4, context);
|
||||
setPadding(padding, padding, padding, padding);
|
||||
|
||||
this.setText("▶ " + getStringByName(context, "tap_skip"));
|
||||
this.setText("▶ " + str("tap_skip"));
|
||||
|
||||
setOnClickListener(this);
|
||||
}
|
||||
@ -76,7 +76,7 @@ public class SkipSegmentView extends TextView implements View.OnClickListener {
|
||||
return;
|
||||
}
|
||||
lastNotifiedSegment = segment;
|
||||
String skipMessage = segment.category.skipMessage;
|
||||
String skipMessage = segment.category.skipMessage.toString();
|
||||
SkipSegmentView view = SkipSegmentView.view.get();
|
||||
if (VERBOSE)
|
||||
Log.d(TAG, String.format("notifySkipped; view=%s, message=%s", view, skipMessage));
|
||||
|
@ -19,7 +19,6 @@ import android.widget.Toast;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static pl.jakubweg.Helper.getStringByName;
|
||||
import static pl.jakubweg.SponsorBlockSettings.DefaultBehaviour;
|
||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_ADJUST_NEW_SEGMENT_STEP;
|
||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_CACHE_SEGMENTS;
|
||||
@ -34,7 +33,10 @@ import static pl.jakubweg.SponsorBlockSettings.cacheEnabled;
|
||||
import static pl.jakubweg.SponsorBlockSettings.countSkips;
|
||||
import static pl.jakubweg.SponsorBlockSettings.showToastWhenSkippedAutomatically;
|
||||
import static pl.jakubweg.SponsorBlockSettings.uuid;
|
||||
import static pl.jakubweg.StringRef.str;
|
||||
|
||||
|
||||
@SuppressWarnings({"unused", "deprecation"}) // injected
|
||||
public class SponsorBlockPreferenceFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
private ArrayList<Preference> preferencesToDisableWhenSBDisabled = new ArrayList<>();
|
||||
@ -57,8 +59,8 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
||||
preference.setKey(PREFERENCES_KEY_SPONSOR_BLOCK_ENABLED);
|
||||
preference.setDefaultValue(SponsorBlockSettings.isSponsorBlockEnabled);
|
||||
preference.setChecked(SponsorBlockSettings.isSponsorBlockEnabled);
|
||||
preference.setTitle(getStringByName(context, "enable_sb"));
|
||||
preference.setSummary(getStringByName(context, "enable_sb_sum"));
|
||||
preference.setTitle(str("enable_sb"));
|
||||
preference.setSummary(str("enable_sb_sum"));
|
||||
preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
@ -74,8 +76,8 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
||||
preference.setKey(PREFERENCES_KEY_NEW_SEGMENT_ENABLED);
|
||||
preference.setDefaultValue(SponsorBlockSettings.isAddNewSegmentEnabled);
|
||||
preference.setChecked(SponsorBlockSettings.isAddNewSegmentEnabled);
|
||||
preference.setTitle(getStringByName(context, "enable_segmadding"));
|
||||
preference.setSummary(getStringByName(context, "enable_segmadding_sum"));
|
||||
preference.setTitle(str("enable_segmadding"));
|
||||
preference.setSummary(str("enable_segmadding_sum"));
|
||||
preferencesToDisableWhenSBDisabled.add(preference);
|
||||
}
|
||||
|
||||
@ -101,7 +103,7 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
||||
PreferenceCategory category = new PreferenceCategory(context);
|
||||
screen.addPreference(category);
|
||||
preferencesToDisableWhenSBDisabled.add(category);
|
||||
category.setTitle(getStringByName(context, "diff_segments"));
|
||||
category.setTitle(str("diff_segments"));
|
||||
|
||||
String defaultValue = DefaultBehaviour.key;
|
||||
SponsorBlockSettings.SegmentBehaviour[] segmentBehaviours = SponsorBlockSettings.SegmentBehaviour.values();
|
||||
@ -109,14 +111,14 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
||||
String[] entryValues = new String[segmentBehaviours.length];
|
||||
for (int i = 0, segmentBehavioursLength = segmentBehaviours.length; i < segmentBehavioursLength; i++) {
|
||||
SponsorBlockSettings.SegmentBehaviour behaviour = segmentBehaviours[i];
|
||||
entries[i] = behaviour.name;
|
||||
entries[i] = behaviour.name.toString();
|
||||
entryValues[i] = behaviour.key;
|
||||
}
|
||||
|
||||
for (SponsorBlockSettings.SegmentInfo segmentInfo : SponsorBlockSettings.SegmentInfo.valuesWithoutPreview()) {
|
||||
ListPreference preference = new ListPreference(context);
|
||||
preference.setTitle(segmentInfo.getTitleWithDot());
|
||||
preference.setSummary(segmentInfo.description);
|
||||
preference.setSummary(segmentInfo.description.toString());
|
||||
preference.setKey(segmentInfo.key);
|
||||
preference.setDefaultValue(defaultValue);
|
||||
preference.setEntries(entries);
|
||||
@ -134,8 +136,8 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
||||
{
|
||||
Preference preference = new Preference(context);
|
||||
screen.addPreference(preference);
|
||||
preference.setTitle(getStringByName(context, "about_api"));
|
||||
preference.setSummary(getStringByName(context, "about_api_sum"));
|
||||
preference.setTitle(str("about_api"));
|
||||
preference.setSummary(str("about_api_sum"));
|
||||
preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
@ -150,7 +152,7 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
||||
{
|
||||
Preference preference = new Preference(context);
|
||||
screen.addPreference(preference);
|
||||
preference.setTitle(getStringByName(context, "about_madeby"));
|
||||
preference.setTitle(str("about_madeby"));
|
||||
}
|
||||
|
||||
}
|
||||
@ -159,18 +161,18 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
||||
final PreferenceCategory category = new PreferenceCategory(context);
|
||||
preferencesToDisableWhenSBDisabled.add(category);
|
||||
screen.addPreference(category);
|
||||
category.setTitle(getStringByName(context, "general"));
|
||||
category.setTitle(str("general"));
|
||||
|
||||
{
|
||||
Preference preference = new SwitchPreference(context);
|
||||
preference.setTitle(getStringByName(context, "general_skiptoast"));
|
||||
preference.setSummary(getStringByName(context, "general_skiptoast_sum"));
|
||||
preference.setTitle(str("general_skiptoast"));
|
||||
preference.setSummary(str("general_skiptoast_sum"));
|
||||
preference.setKey(PREFERENCES_KEY_SHOW_TOAST_WHEN_SKIP);
|
||||
preference.setDefaultValue(showToastWhenSkippedAutomatically);
|
||||
preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Toast.makeText(preference.getContext(), getStringByName(context, "skipped_segment"), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(preference.getContext(), str("skipped_segment"), Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
@ -180,8 +182,8 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
||||
|
||||
{
|
||||
Preference preference = new SwitchPreference(context);
|
||||
preference.setTitle(getStringByName(context, "general_skipcount"));
|
||||
preference.setSummary(getStringByName(context, "general_skipcount_sum"));
|
||||
preference.setTitle(str("general_skipcount"));
|
||||
preference.setSummary(str("general_skipcount_sum"));
|
||||
preference.setKey(PREFERENCES_KEY_COUNT_SKIPS);
|
||||
preference.setDefaultValue(countSkips);
|
||||
preferencesToDisableWhenSBDisabled.add(preference);
|
||||
@ -191,8 +193,8 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
||||
{
|
||||
EditTextPreference preference = new EditTextPreference(context);
|
||||
preference.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
|
||||
preference.setTitle(getStringByName(context, "general_adjusting"));
|
||||
preference.setSummary(getStringByName(context, "general_adjusting_sum"));
|
||||
preference.setTitle(str("general_adjusting"));
|
||||
preference.setSummary(str("general_adjusting_sum"));
|
||||
preference.setKey(PREFERENCES_KEY_ADJUST_NEW_SEGMENT_STEP);
|
||||
preference.setDefaultValue(String.valueOf(adjustNewSegmentMillis));
|
||||
screen.addPreference(preference);
|
||||
@ -201,8 +203,8 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
||||
|
||||
{
|
||||
Preference preference = new EditTextPreference(context);
|
||||
preference.setTitle(getStringByName(context, "general_uuid"));
|
||||
preference.setSummary(getStringByName(context, "general_uuid_sum"));
|
||||
preference.setTitle(str("general_uuid"));
|
||||
preference.setSummary(str("general_uuid_sum"));
|
||||
preference.setKey(PREFERENCES_KEY_UUID);
|
||||
preference.setDefaultValue(uuid);
|
||||
screen.addPreference(preference);
|
||||
@ -211,8 +213,8 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
||||
|
||||
{
|
||||
Preference preference = new SwitchPreference(context);
|
||||
preference.setTitle(getStringByName(context, "general_cache"));
|
||||
preference.setSummary(getStringByName(context, "general_cache_sum"));
|
||||
preference.setTitle(str("general_cache"));
|
||||
preference.setSummary(str("general_cache_sum"));
|
||||
preference.setKey(PREFERENCES_KEY_CACHE_SEGMENTS);
|
||||
preference.setDefaultValue(cacheEnabled);
|
||||
screen.addPreference(preference);
|
||||
@ -221,7 +223,7 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
||||
|
||||
{
|
||||
Preference preference = new Preference(context);
|
||||
preference.setTitle(getStringByName(context, "general_cache_clear"));
|
||||
preference.setTitle(str("general_cache_clear"));
|
||||
preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
@ -231,7 +233,7 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
||||
if (!file.delete())
|
||||
return false;
|
||||
}
|
||||
Toast.makeText(getActivity(), getStringByName(context, "done"), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(getActivity(), str("done"), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static pl.jakubweg.Helper.getStringByName;
|
||||
import static pl.jakubweg.StringRef.sf;
|
||||
|
||||
public class SponsorBlockSettings {
|
||||
|
||||
@ -28,7 +28,10 @@ public class SponsorBlockSettings {
|
||||
public static final String PREFERENCES_KEY_NEW_SEGMENT_ENABLED = "sb-new-segment-enabled";
|
||||
public static final String sponsorBlockSkipSegmentsUrl = "https://sponsor.ajay.app/api/skipSegments";
|
||||
public static final String sponsorBlockViewedUrl = "https://sponsor.ajay.app/api/viewedVideoSponsorTime";
|
||||
|
||||
|
||||
public static final SegmentBehaviour DefaultBehaviour = SegmentBehaviour.SkipAutomatically;
|
||||
|
||||
public static boolean isSponsorBlockEnabled = false;
|
||||
public static boolean isAddNewSegmentEnabled = false;
|
||||
public static boolean showToastWhenSkippedAutomatically = true;
|
||||
@ -39,10 +42,10 @@ public class SponsorBlockSettings {
|
||||
public static File cacheDirectory;
|
||||
private static String sponsorBlockUrlCategories = "[]";
|
||||
|
||||
static Context context;
|
||||
|
||||
public SponsorBlockSettings(Context context) {
|
||||
SponsorBlockSettings.context = context;
|
||||
@SuppressWarnings("unused")
|
||||
@Deprecated
|
||||
public SponsorBlockSettings(Context ignored) {
|
||||
Log.e("jakubweg.Settings", "Do not call SponsorBlockSettings constructor!");
|
||||
}
|
||||
|
||||
public static String getSponsorBlockUrlWithCategories(String videoId) {
|
||||
@ -128,17 +131,17 @@ public class SponsorBlockSettings {
|
||||
}
|
||||
|
||||
public enum SegmentBehaviour {
|
||||
SkipAutomatically("skip", getStringByName(context, "skip_automatically"), true, true),
|
||||
ManualSkip("manual-skip", getStringByName(context, "skip_showbutton"), false, true),
|
||||
Ignore("ignore", getStringByName(context, "skip_ignore"), false, false);
|
||||
SkipAutomatically("skip", sf("skip_automatically"), true, true),
|
||||
ManualSkip("manual-skip", sf("skip_showbutton"), false, true),
|
||||
Ignore("ignore", sf("skip_ignore"), false, false);
|
||||
|
||||
public final String key;
|
||||
public final String name;
|
||||
public final StringRef name;
|
||||
public final boolean skip;
|
||||
public final boolean showOnTimeBar;
|
||||
|
||||
SegmentBehaviour(String key,
|
||||
String name,
|
||||
StringRef name,
|
||||
boolean skip,
|
||||
boolean showOnTimeBar) {
|
||||
this.key = key;
|
||||
@ -149,13 +152,13 @@ public class SponsorBlockSettings {
|
||||
}
|
||||
|
||||
public enum SegmentInfo {
|
||||
Sponsor("sponsor", getStringByName(context, "segments_sponsor"), getStringByName(context, "skipped_sponsor"), getStringByName(context, "segments_sponsor_sum"), null, 0xFF00d400),
|
||||
Intro("intro", getStringByName(context, "segments_intermission"), getStringByName(context, "skipped_intermission"), getStringByName(context, "segments_intermission_sum"), null, 0xFF00ffff),
|
||||
Outro("outro", getStringByName(context, "segments_endcard"), getStringByName(context, "skipped_endcard"), getStringByName(context, "segments_endcards_sum"), null, 0xFF0202ed),
|
||||
Interaction("interaction", getStringByName(context, "segments_subscribe"), getStringByName(context, "skipped_subscribe"), getStringByName(context, "segments_subscribe_sum"), null, 0xFFcc00ff),
|
||||
SelfPromo("selfpromo", getStringByName(context, "segments_selfpromo"), getStringByName(context, "skipped_selfpromo"), getStringByName(context, "segments_selfpromo_sum"), null, 0xFFffff00),
|
||||
MusicOfftopic("music_offtopic", getStringByName(context, "segments_music"), getStringByName(context, "skipped_music"), getStringByName(context, "segments_music_sum"), null, 0xFFff9900),
|
||||
Preview("preview", "", getStringByName(context, "skipped_preview"), "", SegmentBehaviour.SkipAutomatically, 0xFF000000),
|
||||
Sponsor("sponsor", sf("segments_sponsor"), sf("skipped_sponsor"), sf("segments_sponsor_sum"), null, 0xFF00d400),
|
||||
Intro("intro", sf("segments_intermission"), sf("skipped_intermission"), sf("segments_intermission_sum"), null, 0xFF00ffff),
|
||||
Outro("outro", sf("segments_endcard"), sf("skipped_endcard"), sf("segments_endcards_sum"), null, 0xFF0202ed),
|
||||
Interaction("interaction", sf("segments_subscribe"), sf("skipped_subscribe"), sf("segments_subscribe_sum"), null, 0xFFcc00ff),
|
||||
SelfPromo("selfpromo", sf("segments_selfpromo"), sf("skipped_selfpromo"), sf("segments_selfpromo_sum"), null, 0xFFffff00),
|
||||
MusicOfftopic("music_offtopic", sf("segments_nomusic"), sf("skipped_nomusic"), sf("segments_nomusic_sum"), null, 0xFFff9900),
|
||||
Preview("preview", StringRef.empty, sf("skipped_preview"), StringRef.empty, SegmentBehaviour.SkipAutomatically, 0xFF000000),
|
||||
;
|
||||
|
||||
private static SegmentInfo[] mValuesWithoutPreview = new SegmentInfo[]{
|
||||
@ -174,18 +177,18 @@ public class SponsorBlockSettings {
|
||||
}
|
||||
|
||||
public final String key;
|
||||
public final String title;
|
||||
public final String skipMessage;
|
||||
public final String description;
|
||||
public final StringRef title;
|
||||
public final StringRef skipMessage;
|
||||
public final StringRef description;
|
||||
public final int color;
|
||||
public final Paint paint;
|
||||
public SegmentBehaviour behaviour;
|
||||
private CharSequence lazyTitleWithDot;
|
||||
|
||||
SegmentInfo(String key,
|
||||
String title,
|
||||
String skipMessage,
|
||||
String description,
|
||||
StringRef title,
|
||||
StringRef skipMessage,
|
||||
StringRef description,
|
||||
SegmentBehaviour behaviour,
|
||||
int color) {
|
||||
|
||||
|
@ -51,6 +51,8 @@ import static pl.jakubweg.PlayerController.getCurrentVideoId;
|
||||
import static pl.jakubweg.PlayerController.getLastKnownVideoTime;
|
||||
import static pl.jakubweg.PlayerController.sponsorSegmentsOfCurrentVideo;
|
||||
import static pl.jakubweg.SponsorBlockSettings.sponsorBlockSkipSegmentsUrl;
|
||||
import static pl.jakubweg.StringRef.sf;
|
||||
import static pl.jakubweg.StringRef.str;
|
||||
|
||||
@SuppressWarnings({"LongLogTag"})
|
||||
public abstract class SponsorBlockUtils {
|
||||
@ -78,12 +80,12 @@ public abstract class SponsorBlockUtils {
|
||||
case DialogInterface.BUTTON_NEGATIVE:
|
||||
// start
|
||||
newSponsorSegmentStartMillis = newSponsorSegmentDialogShownMillis;
|
||||
Toast.makeText(context.getApplicationContext(), "Start of the segment set", Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(context.getApplicationContext(), str("new_segment_time_start_set"), Toast.LENGTH_LONG).show();
|
||||
break;
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
// end
|
||||
newSponsorSegmentEndMillis = newSponsorSegmentDialogShownMillis;
|
||||
Toast.makeText(context.getApplicationContext(), "End of the segment set", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(context.getApplicationContext(), str("new_segment_time_end_set"), Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
}
|
||||
dialog.dismiss();
|
||||
@ -98,13 +100,13 @@ public abstract class SponsorBlockUtils {
|
||||
if (!segmentType.behaviour.showOnTimeBar) {
|
||||
Toast.makeText(
|
||||
((AlertDialog) dialog).getContext().getApplicationContext(),
|
||||
"You've disabled this category in the settings, so can't submit it",
|
||||
str("new_segment_disabled_category"),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
enableButton = false;
|
||||
} else {
|
||||
Toast.makeText(
|
||||
((AlertDialog) dialog).getContext().getApplicationContext(),
|
||||
segmentType.description,
|
||||
segmentType.description.toString(),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
newSponsorBlockSegmentType = segmentType;
|
||||
enableButton = true;
|
||||
@ -132,7 +134,7 @@ public abstract class SponsorBlockUtils {
|
||||
|
||||
newSponsorBlockSegmentType = null;
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle("Choose the segment category")
|
||||
.setTitle(str("new_segment_choose_category"))
|
||||
.setSingleChoiceItems(titles, -1, segmentTypeListener)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(android.R.string.ok, segmentCategorySelectedDialogListener)
|
||||
@ -148,7 +150,7 @@ public abstract class SponsorBlockUtils {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
Context context = ((AlertDialog) dialog).getContext().getApplicationContext();
|
||||
Toast.makeText(context, "Submitting segment...", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(context, str("submit_started"), Toast.LENGTH_SHORT).show();
|
||||
|
||||
appContext = new WeakReference<>(context);
|
||||
new Thread(submitRunnable).start();
|
||||
@ -179,10 +181,10 @@ public abstract class SponsorBlockUtils {
|
||||
editByHandSaveDialogListener.settingStart = isStart;
|
||||
editByHandSaveDialogListener.editText = new WeakReference<>(textView);
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle("Time of the " + (isStart ? "start" : "end") + " of the segment")
|
||||
.setTitle(str(isStart ? "new_segment_time_start" : "new_segment_time_end"))
|
||||
.setView(textView)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setNeutralButton("now", editByHandSaveDialogListener)
|
||||
.setNeutralButton(str("new_segment_now"), editByHandSaveDialogListener)
|
||||
.setPositiveButton(android.R.string.ok, editByHandSaveDialogListener)
|
||||
.show();
|
||||
|
||||
@ -221,19 +223,19 @@ public abstract class SponsorBlockUtils {
|
||||
connection.setRequestMethod("POST");
|
||||
switch (connection.getResponseCode()) {
|
||||
default:
|
||||
messageToToast = "Unable to submit segments: Status: " + connection.getResponseCode() + " " + connection.getResponseMessage();
|
||||
messageToToast = String.format(str("submit_failed_unknown_error"), connection.getResponseCode(), connection.getResponseMessage());
|
||||
break;
|
||||
case 429:
|
||||
messageToToast = "Can't submit the segment.\nRate Limit (Too many for the same user or IP)";
|
||||
messageToToast = str("submit_failed_rate_limit");
|
||||
break;
|
||||
case 403:
|
||||
messageToToast = "Can't submit the segment.\nRejected by auto moderator";
|
||||
messageToToast = str("submit_failed_forbidden");
|
||||
break;
|
||||
case 409:
|
||||
messageToToast = "Duplicate";
|
||||
messageToToast = str("submit_failed_duplicate");
|
||||
break;
|
||||
case 200:
|
||||
messageToToast = "Segment submitted successfully";
|
||||
messageToToast = str("submit_succeeded");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -379,14 +381,14 @@ public abstract class SponsorBlockUtils {
|
||||
newSponsorSegmentDialogShownMillis = PlayerController.getLastKnownVideoTime();
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle("New Sponsor Block segment")
|
||||
.setMessage(String.format("Set %02d:%02d:%04d as a start or end of new segment?",
|
||||
.setTitle(str("new_segment_title"))
|
||||
.setMessage(String.format(str("new_segment_mark_time_as_question"),
|
||||
newSponsorSegmentDialogShownMillis / 60000,
|
||||
newSponsorSegmentDialogShownMillis / 1000 % 60,
|
||||
newSponsorSegmentDialogShownMillis % 1000))
|
||||
.setNeutralButton("Cancel", null)
|
||||
.setNegativeButton("Start", newSponsorSegmentDialogListener)
|
||||
.setPositiveButton("End", newSponsorSegmentDialogListener)
|
||||
.setNeutralButton(android.R.string.cancel, null)
|
||||
.setNegativeButton(str("new_segment_mark_start"), newSponsorSegmentDialogListener)
|
||||
.setPositiveButton(str("new_segment_mark_end"), newSponsorSegmentDialogListener)
|
||||
.show();
|
||||
}
|
||||
|
||||
@ -397,8 +399,8 @@ public abstract class SponsorBlockUtils {
|
||||
long start = (newSponsorSegmentStartMillis) / 1000;
|
||||
long end = (newSponsorSegmentEndMillis) / 1000;
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle("Is it right?")
|
||||
.setMessage(String.format("The segment lasts from %02d:%02d to %02d:%02d (%d minutes %02d seconds)\nIs it ready to submit?",
|
||||
.setTitle(str("new_segment_confirm_title"))
|
||||
.setMessage(String.format(str("new_segment_confirm_content"),
|
||||
start / 60, start % 60,
|
||||
end / 60, end % 60,
|
||||
length / 60, length % 60))
|
||||
@ -413,9 +415,9 @@ public abstract class SponsorBlockUtils {
|
||||
@SuppressLint("DefaultLocale")
|
||||
public static void onPreviewClicked(Context context) {
|
||||
if (newSponsorSegmentStartMillis >= 0 && newSponsorSegmentStartMillis < newSponsorSegmentEndMillis) {
|
||||
Toast t = Toast.makeText(context, "Preview", Toast.LENGTH_SHORT);
|
||||
t.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP, t.getXOffset(), t.getYOffset());
|
||||
t.show();
|
||||
// Toast t = Toast.makeText(context, "Preview", Toast.LENGTH_SHORT);
|
||||
// t.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP, t.getXOffset(), t.getYOffset());
|
||||
// t.show();
|
||||
PlayerController.skipToMillisecond(newSponsorSegmentStartMillis - 3000);
|
||||
final SponsorSegment[] original = PlayerController.sponsorSegmentsOfCurrentVideo;
|
||||
final SponsorSegment[] segments = original == null ? new SponsorSegment[1] : Arrays.copyOf(original, original.length + 1);
|
||||
@ -426,18 +428,18 @@ public abstract class SponsorBlockUtils {
|
||||
Arrays.sort(segments);
|
||||
sponsorSegmentsOfCurrentVideo = segments;
|
||||
} else {
|
||||
Toast.makeText(context, "Mark two locations on the time bar first", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(context, str("new_segment_mark_locations_first"), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("DefaultLocale")
|
||||
public static void onEditByHandClicked(Context context) {
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle("Edit time of new segment by hand")
|
||||
.setMessage("Do you want to edit time of the start or the end of the segment?")
|
||||
.setTitle(str("new_segment_edit_by_hand_title"))
|
||||
.setMessage(str("new_segment_edit_by_hand_content"))
|
||||
.setNeutralButton(android.R.string.cancel, null)
|
||||
.setNegativeButton("start", editByHandDialogListener)
|
||||
.setPositiveButton("end", editByHandDialogListener)
|
||||
.setNegativeButton(str("new_segment_mark_start"), editByHandDialogListener)
|
||||
.setPositiveButton(str("new_segment_mark_end"), editByHandDialogListener)
|
||||
.show();
|
||||
}
|
||||
|
||||
@ -638,9 +640,9 @@ public abstract class SponsorBlockUtils {
|
||||
DialogInterface.BUTTON_NEGATIVE :
|
||||
DialogInterface.BUTTON_POSITIVE);
|
||||
else
|
||||
Toast.makeText(context.getApplicationContext(), "Done", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(context.getApplicationContext(), str("new_segment_edit_by_hand_saved"), Toast.LENGTH_SHORT).show();
|
||||
} catch (ParseException e) {
|
||||
Toast.makeText(context.getApplicationContext(), "Cannot parse this time 😔", Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(context.getApplicationContext(), str("new_segment_edit_by_hand_parse_error"), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
98
app/src/main/java/pl/jakubweg/StringRef.java
Normal file
98
app/src/main/java/pl/jakubweg/StringRef.java
Normal file
@ -0,0 +1,98 @@
|
||||
package pl.jakubweg;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class StringRef {
|
||||
public static final String TAG = "jakubweg.StringRef";
|
||||
|
||||
private static Resources resources;
|
||||
private static String packageName;
|
||||
|
||||
/**
|
||||
* Called in Application onCreate, should be called as soon as possible when after application startup
|
||||
* @param context Any context, it will be used to obtain string resources
|
||||
*/
|
||||
public static void setContext(Context context) {
|
||||
if (context == null) return;
|
||||
resources = context.getApplicationContext().getResources();
|
||||
packageName = context.getPackageName();
|
||||
}
|
||||
|
||||
private static HashMap<String, StringRef> strings = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Gets strings reference from shared collection or creates if not exists yet,
|
||||
* this method should be called if you want to get StringRef
|
||||
* @param id string resource name/id
|
||||
* @return String reference that'll resolve to excepted string, may be from cache
|
||||
*/
|
||||
@NonNull
|
||||
public static StringRef sf(@NonNull String id) {
|
||||
StringRef ref = strings.get(id);
|
||||
if (ref == null) {
|
||||
ref = new StringRef(id);
|
||||
strings.put(id, ref);
|
||||
}
|
||||
return ref;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets string value by string id, shorthand for <code>sf(id).toString()</code>
|
||||
* @param id string resource name/id
|
||||
* @return String value from string.xml
|
||||
*/
|
||||
@NonNull
|
||||
public static String str(@NonNull String id) {
|
||||
return sf(id).toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a StringRef object that'll not change it's value
|
||||
* @param value value which toString() method returns when invoked on returned object
|
||||
* @return Unique StringRef instance, its value will never change
|
||||
*/
|
||||
@NonNull
|
||||
public static StringRef constant(@NonNull String value) {
|
||||
final StringRef ref = new StringRef(value);
|
||||
ref.resolved = true;
|
||||
return ref;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorthand for <code>constant("")</code>
|
||||
* Its value always resolves to empty string
|
||||
*/
|
||||
@NonNull
|
||||
public static final StringRef empty = constant("");
|
||||
|
||||
@NonNull
|
||||
private String value;
|
||||
private boolean resolved;
|
||||
|
||||
public StringRef(@NonNull String resName) {
|
||||
this.value = resName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String toString() {
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
if (resources != null) {
|
||||
final int identifier = resources.getIdentifier(value, "string", packageName);
|
||||
if (identifier == 0)
|
||||
Log.e(TAG, "Resource not found: " + value);
|
||||
else
|
||||
value = resources.getString(identifier);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
@ -130,6 +130,7 @@
|
||||
<string name="bawm_summary">SponsorBlock implementation</string>
|
||||
<string name="bawm_title" translatable="false">JakubWeg</string>
|
||||
|
||||
|
||||
<string name="enable_sb">Enable Sponsor Block (Beta)</string>
|
||||
<string name="enable_sb_sum">Switch this on for very cool sponsor segments skipping</string>
|
||||
<string name="enable_segmadding">Enable new segment adding</string>
|
||||
@ -175,6 +176,33 @@
|
||||
<string name="about_api_sum">Click to learn more at: sponsor.ajay.app</string>
|
||||
<string name="about_madeby">Integration made by JakubWeg</string>
|
||||
<string name="tap_skip">Tap to skip</string>
|
||||
|
||||
<string name="submit_failed_unknown_error">Unable to submit segments: Status: %d %s</string>
|
||||
<string name="submit_failed_rate_limit">Can\'t submit the segment.\nRate Limit (Too many for the same user or IP)</string>
|
||||
<string name="submit_failed_forbidden">Can\'t submit the segment.\nRejected by auto moderator</string>
|
||||
<string name="submit_failed_duplicate">Can\'t submit the segment.\nAlready exists</string>
|
||||
<string name="submit_succeeded">Segment submitted successfully</string>
|
||||
<string name="submit_started">Submitting segment…</string>
|
||||
|
||||
<string name="new_segment_choose_category">Choose the segment category</string>
|
||||
<string name="new_segment_disabled_category">You\'ve disabled this category in the settings, so can\'t submit it</string>
|
||||
<string name="new_segment_title">New Sponsor Block segment</string>
|
||||
<string name="new_segment_mark_time_as_question">Set %02d:%02d:%04d as a start or end of new segment?</string>
|
||||
<string name="new_segment_mark_start">start</string>
|
||||
<string name="new_segment_mark_end">end</string>
|
||||
<string name="new_segment_now">now</string>
|
||||
<string name="new_segment_time_start">Time of the start of the segment</string>
|
||||
<string name="new_segment_time_end">Time of the end of the segment</string>
|
||||
<string name="new_segment_time_start_set">Start of the segment set</string>
|
||||
<string name="new_segment_time_end_set">End of the segment set</string>
|
||||
<string name="new_segment_confirm_title">Is it right?</string>
|
||||
<string name="new_segment_confirm_content">The segment lasts from %02d:%02d to %02d:%02d (%d minutes %02d seconds)\nIs it ready to submit?</string>
|
||||
<string name="new_segment_mark_locations_first">Mark two locations on the time bar first</string>
|
||||
<string name="new_segment_edit_by_hand_title">Edit time of new segment by hand</string>
|
||||
<string name="new_segment_edit_by_hand_content">Do you want to edit time of the start or the end of the segment?</string>
|
||||
<string name="new_segment_edit_by_hand_saved">Done</string>
|
||||
<string name="new_segment_edit_by_hand_parse_error">Cannot parse this time 😔</string>
|
||||
|
||||
<string name="app_name" />
|
||||
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user