* General improvements

- Fixed preferences not obtained properly.
- Cleaned up libraries and code.
- Update deps.

* Update README.md
This commit is contained in:
Oizaro 2021-06-08 18:25:01 +02:00 committed by GitHub
parent 55a30a608c
commit b381e3373e
9 changed files with 13 additions and 43 deletions

View File

@ -1,12 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
package="pl.jakubweg"> package="pl.jakubweg">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
tools:ignore="AllowBackup" />
</manifest> </manifest>

View File

@ -92,7 +92,6 @@ public class InjectedPlugin {
Log.i(TAG, spacesStr + "Normal view: " + view); Log.i(TAG, spacesStr + "Normal view: " + view);
} }
} }
} }

View File

@ -2,6 +2,7 @@ package pl.jakubweg;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Handler; import android.os.Handler;
@ -10,6 +11,8 @@ import android.util.Log;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.google.android.apps.youtube.app.YouTubeTikTokRoot_Application;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -59,6 +62,13 @@ public class PlayerController {
VideoInformation.currentVideoId = videoId; VideoInformation.currentVideoId = videoId;
Context context = YouTubeTikTokRoot_Application.getAppContext();
if(context == null){
Log.e(TAG, "context is null");
return;
}
SponsorBlockSettings.update(context);
if (!SponsorBlockSettings.isSponsorBlockEnabled) { if (!SponsorBlockSettings.isSponsorBlockEnabled) {
currentVideoId = null; currentVideoId = null;
return; return;

View File

@ -34,7 +34,6 @@ public class ShieldButton {
} }
_youtubeControlsLayout = (RelativeLayout) viewStub; _youtubeControlsLayout = (RelativeLayout) viewStub;
initButtonVisibilitySettings();
ImageView imageView = (ImageView)_youtubeControlsLayout ImageView imageView = (ImageView)_youtubeControlsLayout
.findViewById(getIdentifier("sponsorblock_button", "id")); .findViewById(getIdentifier("sponsorblock_button", "id"));
@ -107,20 +106,6 @@ public class ShieldButton {
return SponsorBlockSettings.isSponsorBlockEnabled && SponsorBlockSettings.isAddNewSegmentEnabled; return SponsorBlockSettings.isSponsorBlockEnabled && SponsorBlockSettings.isAddNewSegmentEnabled;
} }
private static void initButtonVisibilitySettings() {
Context context = YouTubeTikTokRoot_Application.getAppContext();
if(context == null){
Log.e(TAG, "context is null");
SponsorBlockSettings.isSponsorBlockEnabled = false;
SponsorBlockSettings.isAddNewSegmentEnabled = false;
return;
}
SharedPreferences sharedPreferences = context.getSharedPreferences(SponsorBlockSettings.PREFERENCES_NAME, Context.MODE_PRIVATE);
SponsorBlockSettings.isSponsorBlockEnabled = sharedPreferences.getBoolean(SponsorBlockSettings.PREFERENCES_KEY_SPONSOR_BLOCK_ENABLED, false);
SponsorBlockSettings.isAddNewSegmentEnabled = sharedPreferences.getBoolean(SponsorBlockSettings.PREFERENCES_KEY_NEW_SEGMENT_ENABLED, false);
}
//region Helpers //region Helpers
private static int getIdentifier(String name, String defType) { private static int getIdentifier(String name, String defType) {
Context context = YouTubeTikTokRoot_Application.getAppContext(); Context context = YouTubeTikTokRoot_Application.getAppContext();

View File

@ -36,7 +36,6 @@ import static pl.jakubweg.SponsorBlockSettings.showToastWhenSkippedAutomatically
import static pl.jakubweg.SponsorBlockSettings.uuid; import static pl.jakubweg.SponsorBlockSettings.uuid;
import static pl.jakubweg.StringRef.str; import static pl.jakubweg.StringRef.str;
@SuppressWarnings({"unused", "deprecation"}) // injected @SuppressWarnings({"unused", "deprecation"}) // injected
public class SponsorBlockPreferenceFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener { public class SponsorBlockPreferenceFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
@ -54,6 +53,8 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(context); PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(context);
setPreferenceScreen(preferenceScreen); setPreferenceScreen(preferenceScreen);
SponsorBlockSettings.update(context);
{ {
SwitchPreference preference = new SwitchPreference(context); SwitchPreference preference = new SwitchPreference(context);
preferenceScreen.addPreference(preference); preferenceScreen.addPreference(preference);

View File

@ -86,7 +86,7 @@ public class SponsorBlockSettings {
SponsorBlockUtils.hideShieldButton(); SponsorBlockUtils.hideShieldButton();
SponsorBlockUtils.hideVoteButton(); SponsorBlockUtils.hideVoteButton();
PlayerController.sponsorSegmentsOfCurrentVideo = null; PlayerController.sponsorSegmentsOfCurrentVideo = null;
} else if (/*isAddNewSegmentEnabled*/false) { } else { /*isAddNewSegmentEnabled*/
SponsorBlockUtils.showShieldButton(); SponsorBlockUtils.showShieldButton();
} }

View File

@ -602,5 +602,4 @@ public abstract class SponsorBlockUtils {
} }
} }
} }
} }

View File

@ -26,5 +26,4 @@ public class SponsorSegment implements Comparable<SponsorSegment> {
public int compareTo(SponsorSegment o) { public int compareTo(SponsorSegment o) {
return (int) (this.start - o.start); return (int) (this.start - o.start);
} }
} }

View File

@ -34,7 +34,6 @@ public class VotingButton {
} }
_youtubeControlsLayout = (RelativeLayout) viewStub; _youtubeControlsLayout = (RelativeLayout) viewStub;
initButtonVisibilitySettings();
ImageView imageView = (ImageView)_youtubeControlsLayout ImageView imageView = (ImageView)_youtubeControlsLayout
.findViewById(getIdentifier("voting_button", "id")); .findViewById(getIdentifier("voting_button", "id"));
@ -107,20 +106,6 @@ public class VotingButton {
return SponsorBlockSettings.isVotingEnabled && SponsorBlockSettings.isSponsorBlockEnabled; return SponsorBlockSettings.isVotingEnabled && SponsorBlockSettings.isSponsorBlockEnabled;
} }
private static void initButtonVisibilitySettings() {
Context context = YouTubeTikTokRoot_Application.getAppContext();
if(context == null){
Log.e(TAG, "context is null");
SponsorBlockSettings.isSponsorBlockEnabled = false;
SponsorBlockSettings.isVotingEnabled = false;
return;
}
SharedPreferences sharedPreferences = context.getSharedPreferences(SponsorBlockSettings.PREFERENCES_NAME, Context.MODE_PRIVATE);
SponsorBlockSettings.isSponsorBlockEnabled = sharedPreferences.getBoolean(SponsorBlockSettings.PREFERENCES_KEY_SPONSOR_BLOCK_ENABLED, false);
SponsorBlockSettings.isVotingEnabled = sharedPreferences.getBoolean(SponsorBlockSettings.PREFERENCES_KEY_VOTING_ENABLED, false);
}
//region Helpers //region Helpers
private static int getIdentifier(String name, String defType) { private static int getIdentifier(String name, String defType) {
Context context = YouTubeTikTokRoot_Application.getAppContext(); Context context = YouTubeTikTokRoot_Application.getAppContext();