From 8cbd0b7104e18070b2c732b48070196eb6c74390 Mon Sep 17 00:00:00 2001 From: caneleex Date: Mon, 19 Jul 2021 17:32:06 +0200 Subject: [PATCH] cleanup more stuff --- .../java/pl/jakubweg/PlayerController.java | 4 +- .../SponsorBlockPreferenceFragment.java | 73 +++++++------------ .../pl/jakubweg/SponsorBlockSettings.java | 45 ++++++------ .../java/pl/jakubweg/SponsorBlockUtils.java | 4 +- .../main/java/pl/jakubweg/requests/Route.java | 3 +- 5 files changed, 53 insertions(+), 76 deletions(-) diff --git a/app/src/main/java/pl/jakubweg/PlayerController.java b/app/src/main/java/pl/jakubweg/PlayerController.java index 808a9643..e725f27a 100644 --- a/app/src/main/java/pl/jakubweg/PlayerController.java +++ b/app/src/main/java/pl/jakubweg/PlayerController.java @@ -266,7 +266,7 @@ public class PlayerController { private static void sendViewRequestAsync(final long millis, final SponsorSegment segment) { new Thread(() -> { if (SponsorBlockSettings.countSkips && - segment.category != SponsorBlockSettings.SegmentInfo.Unsubmitted && + segment.category != SponsorBlockSettings.SegmentInfo.UNSUBMITTED && millis - segment.start < 2000) { // Only skips from the start should count as a view Requester.sendViewCountRequest(segment); @@ -495,7 +495,7 @@ public class PlayerController { skipToMillisecond(segment.end + 2); SkipSegmentView.hide(); - if (segment.category == SponsorBlockSettings.SegmentInfo.Unsubmitted) { + if (segment.category == SponsorBlockSettings.SegmentInfo.UNSUBMITTED) { SponsorSegment[] newSegments = new SponsorSegment[sponsorSegmentsOfCurrentVideo.length - 1]; int i = 0; for (SponsorSegment sponsorSegment : sponsorSegmentsOfCurrentVideo) { diff --git a/app/src/main/java/pl/jakubweg/SponsorBlockPreferenceFragment.java b/app/src/main/java/pl/jakubweg/SponsorBlockPreferenceFragment.java index fb3f667e..e04caf7d 100644 --- a/app/src/main/java/pl/jakubweg/SponsorBlockPreferenceFragment.java +++ b/app/src/main/java/pl/jakubweg/SponsorBlockPreferenceFragment.java @@ -3,7 +3,6 @@ package pl.jakubweg; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; @@ -39,7 +38,7 @@ import static pl.jakubweg.StringRef.str; @SuppressWarnings({"unused", "deprecation"}) // injected public class SponsorBlockPreferenceFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener { - private ArrayList preferencesToDisableWhenSBDisabled = new ArrayList<>(); + private final ArrayList preferencesToDisableWhenSBDisabled = new ArrayList<>(); @Override public void onCreate(Bundle savedInstanceState) { @@ -63,13 +62,10 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement preference.setChecked(SponsorBlockSettings.isSponsorBlockEnabled); preference.setTitle(str("enable_sb")); preference.setSummary(str("enable_sb_sum")); - preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - final boolean value = (Boolean) newValue; - enableCategoriesIfNeeded(value); - return true; - } + preference.setOnPreferenceChangeListener((preference1, newValue) -> { + final boolean value = (Boolean) newValue; + enableCategoriesIfNeeded(value); + return true; }); } @@ -82,25 +78,17 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement preference.setTitle(str("enable_segmadding")); preference.setSummary(str("enable_segmadding_sum")); preferencesToDisableWhenSBDisabled.add(preference); - preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object o) { - final boolean value = (Boolean) o; - if (value && !SponsorBlockSettings.seenGuidelinesPopup) { - new AlertDialog.Builder(preference.getContext()) - .setTitle(str("sb_guidelines_popup_title")) - .setMessage(str("sb_guidelines_popup_content")) - .setNegativeButton(str("sb_guidelines_popup_already_read"), null) - .setPositiveButton(str("sb_guidelines_popup_open"), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - openGuidelines(); - } - }) - .show(); - } - return true; + preference.setOnPreferenceChangeListener((preference12, o) -> { + final boolean value = (Boolean) o; + if (value && !SponsorBlockSettings.seenGuidelinesPopup) { + new AlertDialog.Builder(preference12.getContext()) + .setTitle(str("sb_guidelines_popup_title")) + .setMessage(str("sb_guidelines_popup_content")) + .setNegativeButton(str("sb_guidelines_popup_already_read"), null) + .setPositiveButton(str("sb_guidelines_popup_open"), (dialogInterface, i) -> openGuidelines()) + .show(); } + return true; }); } @@ -181,14 +169,11 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement screen.addPreference(preference); preference.setTitle(str("about_api")); preference.setSummary(str("about_api_sum")); - preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("http://sponsor.ajay.app")); - preference.getContext().startActivity(i); - return false; - } + preference.setOnPreferenceClickListener(preference1 -> { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("http://sponsor.ajay.app")); + preference1.getContext().startActivity(i); + return false; }); } @@ -210,12 +195,9 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement Preference preference = new Preference(context); preference.setTitle(str("sb_guidelines_preference_title")); preference.setSummary(str("sb_guidelines_preference_sum")); - preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - openGuidelines(); - return false; - } + preference.setOnPreferenceClickListener(preference1 -> { + openGuidelines(); + return false; }); screen.addPreference(preference); } @@ -226,12 +208,9 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement 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(), str("skipped_sponsor"), Toast.LENGTH_SHORT).show(); - return false; - } + preference.setOnPreferenceClickListener(preference12 -> { + Toast.makeText(preference12.getContext(), str("skipped_sponsor"), Toast.LENGTH_SHORT).show(); + return false; }); preferencesToDisableWhenSBDisabled.add(preference); screen.addPreference(preference); diff --git a/app/src/main/java/pl/jakubweg/SponsorBlockSettings.java b/app/src/main/java/pl/jakubweg/SponsorBlockSettings.java index 4a290724..80e74250 100644 --- a/app/src/main/java/pl/jakubweg/SponsorBlockSettings.java +++ b/app/src/main/java/pl/jakubweg/SponsorBlockSettings.java @@ -26,7 +26,7 @@ public class SponsorBlockSettings { public static final String PREFERENCES_KEY_NEW_SEGMENT_ENABLED = "sb-new-segment-enabled"; public static final String PREFERENCES_KEY_VOTING_ENABLED = "sb-voting-enabled"; - public static final SegmentBehaviour DefaultBehaviour = SegmentBehaviour.SkipAutomatically; + public static final SegmentBehaviour DefaultBehaviour = SegmentBehaviour.SKIP_AUTOMATICALLY; public static boolean isSponsorBlockEnabled = false; public static boolean seenGuidelinesPopup = false; @@ -108,7 +108,7 @@ public class SponsorBlockSettings { } //"[%22sponsor%22,%22outro%22,%22music_offtopic%22,%22intro%22,%22selfpromo%22,%22interaction%22,%22preview%22]"; - if (enabledCategories.size() == 0) + if (enabledCategories.isEmpty()) sponsorBlockUrlCategories = "[]"; else sponsorBlockUrlCategories = "[%22" + TextUtils.join("%22,%22", enabledCategories) + "%22]"; @@ -132,9 +132,9 @@ public class SponsorBlockSettings { } public enum SegmentBehaviour { - SkipAutomatically("skip", sf("skip_automatically"), true, true), - ManualSkip("manual-skip", sf("skip_showbutton"), false, true), - Ignore("ignore", sf("skip_ignore"), false, false); + SKIP_AUTOMATICALLY("skip", sf("skip_automatically"), true, true), + MANUAL_SKIP("manual-skip", sf("skip_showbutton"), false, true), + IGNORE("ignore", sf("skip_ignore"), false, false); public final String key; public final StringRef name; @@ -153,26 +153,25 @@ public class SponsorBlockSettings { } public enum SegmentInfo { - 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_endcards"), 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", sf("segments_preview"), sf("skipped_preview"), sf("segments_preview_sum"), null, 0xFF008fd6), - Unsubmitted("unsubmitted", StringRef.empty, sf("skipped_unsubmitted"), StringRef.empty, SegmentBehaviour.SkipAutomatically, 0xFFFFFFFF), - ; + 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_endcards"), sf("skipped_endcard"), sf("segments_endcards_sum"), null, 0xFF0202ed), + INTERACTION("interaction", sf("segments_subscribe"), sf("skipped_subscribe"), sf("segments_subscribe_sum"), null, 0xFFcc00ff), + SELF_PROMO("selfpromo", sf("segments_selfpromo"), sf("skipped_selfpromo"), sf("segments_selfpromo_sum"), null, 0xFFffff00), + MUSIC_OFFTOPIC("music_offtopic", sf("segments_nomusic"), sf("skipped_nomusic"), sf("segments_nomusic_sum"), null, 0xFFff9900), + PREVIEW("preview", sf("segments_preview"), sf("skipped_preview"), sf("segments_preview_sum"), null, 0xFF008fd6), + UNSUBMITTED("unsubmitted", StringRef.empty, sf("skipped_unsubmitted"), StringRef.empty, SegmentBehaviour.SKIP_AUTOMATICALLY, 0xFFFFFFFF),; - private static SegmentInfo[] mValuesWithoutUnsubmitted = new SegmentInfo[]{ - Sponsor, - Intro, - Outro, - Interaction, - SelfPromo, - MusicOfftopic, - Preview + private static final SegmentInfo[] mValuesWithoutUnsubmitted = new SegmentInfo[]{ + SPONSOR, + INTRO, + OUTRO, + INTERACTION, + SELF_PROMO, + MUSIC_OFFTOPIC, + PREVIEW }; - private static Map mValuesMap = new HashMap<>(8); + private static final Map mValuesMap = new HashMap<>(8); static { for (SegmentInfo value : valuesWithoutUnsubmitted()) diff --git a/app/src/main/java/pl/jakubweg/SponsorBlockUtils.java b/app/src/main/java/pl/jakubweg/SponsorBlockUtils.java index 24943665..517e27ef 100644 --- a/app/src/main/java/pl/jakubweg/SponsorBlockUtils.java +++ b/app/src/main/java/pl/jakubweg/SponsorBlockUtils.java @@ -307,7 +307,7 @@ public abstract class SponsorBlockUtils { List titles = new ArrayList<>(segmentAmount); // I've replaced an array with a list to prevent null elements in the array as unsubmitted segments get filtered out for (int i = 0; i < segmentAmount; i++) { SponsorSegment segment = sponsorSegmentsOfCurrentVideo[i]; - if (segment.category == SponsorBlockSettings.SegmentInfo.Unsubmitted) { + if (segment.category == SponsorBlockSettings.SegmentInfo.UNSUBMITTED) { continue; } @@ -350,7 +350,7 @@ public abstract class SponsorBlockUtils { final SponsorSegment[] segments = original == null ? new SponsorSegment[1] : Arrays.copyOf(original, original.length + 1); segments[segments.length - 1] = new SponsorSegment(newSponsorSegmentStartMillis, newSponsorSegmentEndMillis, - SponsorBlockSettings.SegmentInfo.Unsubmitted, null); + SponsorBlockSettings.SegmentInfo.UNSUBMITTED, null); Arrays.sort(segments); sponsorSegmentsOfCurrentVideo = segments; diff --git a/app/src/main/java/pl/jakubweg/requests/Route.java b/app/src/main/java/pl/jakubweg/requests/Route.java index 5cbf44e1..2fccac49 100644 --- a/app/src/main/java/pl/jakubweg/requests/Route.java +++ b/app/src/main/java/pl/jakubweg/requests/Route.java @@ -29,8 +29,7 @@ public class Route { return method; } - public CompiledRoute compile(String... params) - { + public CompiledRoute compile(String... params) { if (params.length != paramCount) throw new IllegalArgumentException("Error Compiling Route: [" + route + "], incorrect amount of parameters provided." + "Expected: " + paramCount + ", Provided: " + params.length);