From 3460237c0f5449d989985d4099ee06a58a383a6f Mon Sep 17 00:00:00 2001 From: Oizaro <75915943+Oizaro@users.noreply.github.com> Date: Tue, 8 Jun 2021 18:25:01 +0200 Subject: [PATCH] Fixes (#34) * General improvements - Fixed preferences not obtained properly. - Cleaned up libraries and code. - Update deps. * Update README.md --- README.md | 10 ++++++---- app/build.gradle | 17 ++++++++--------- app/src/main/AndroidManifest.xml | 8 -------- .../main/java/pl/jakubweg/InjectedPlugin.java | 1 - .../main/java/pl/jakubweg/PlayerController.java | 10 ++++++++++ app/src/main/java/pl/jakubweg/ShieldButton.java | 15 --------------- .../SponsorBlockPreferenceFragment.java | 3 ++- .../java/pl/jakubweg/SponsorBlockSettings.java | 2 +- .../java/pl/jakubweg/SponsorBlockUtils.java | 1 - .../main/java/pl/jakubweg/SponsorSegment.java | 1 - app/src/main/java/pl/jakubweg/VotingButton.java | 15 --------------- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 6 +++--- 13 files changed, 31 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 25002675..46097319 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ # SponsorBlock YouTube Vanced Implementation In order to use this in YouTube/Vanced you must first apply the smali mods applied to vanced (the patching process used for this is currently automated using our closed source tools with no plans to open source it for the time being) (if you mod vanced directly it is not required) -* First make your edits in android studio and then compile the code to a debug apk +* First make your edits in android studio +* Change the string "replaceMeWithsetMillisecondMethod" on PlayerController.java to the method name of YouTube package +* Compile debug apk * Decompile this apk using apktool https://github.com/iBotPeaches/Apktool -* Take this decompiled folder and look for a folder labeled pl in one of your dex class folders (usually the second one) -* Decompile YouTube/Vanced using apktool (you only need to decompile the base apk files(for vanced you can get these using vanced manager and looking in android/data/com.vanced.manager for black or dark.apk), if you are decompiling stock youtube you must also merge a dpi split into it (todo)) -* Copy the pl folder from earlier into the 4th dex class folder (remove any existing one completely first) +* Take this decompiled folder and look for a folder labeled pl in one of your dex class folders +* Decompile YouTube/Vanced using apktool (you only need to decompile the base apk files (for vanced you can get these using vanced manager and looking in android/data/com.vanced.manager for black or dark.apk), if you are decompiling stock youtube you must also merge a dpi split into it (todo)) +* Copy the pl folder from earlier into the dex class folder (remove any existing one completely first) * Recompile your modded YouTube/Vanced using apktool and sign it + all splits required for your device using the same key diff --git a/app/build.gradle b/app/build.gradle index f6eb4abc..a08ece6e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 30 - buildToolsVersion "30.0.1" + buildToolsVersion "30.0.2" defaultConfig { applicationId "pl.jakubweg" @@ -10,8 +10,7 @@ android { targetSdkVersion 30 versionCode 1 versionName "1.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + multiDexEnabled false } buildTypes { @@ -20,13 +19,13 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } dependencies { - implementation fileTree(dir: "libs", include: ["*.jar"]) - implementation 'androidx.appcompat:appcompat:1.2.0' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test.ext:junit:1.1.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + implementation 'androidx.annotation:annotation:1.2.0' +} -} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 80c110cd..430ba65c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,12 +1,4 @@ - - - \ No newline at end of file diff --git a/app/src/main/java/pl/jakubweg/InjectedPlugin.java b/app/src/main/java/pl/jakubweg/InjectedPlugin.java index 021038f6..bc6519a7 100644 --- a/app/src/main/java/pl/jakubweg/InjectedPlugin.java +++ b/app/src/main/java/pl/jakubweg/InjectedPlugin.java @@ -92,7 +92,6 @@ public class InjectedPlugin { Log.i(TAG, spacesStr + "Normal view: " + view); } } - } diff --git a/app/src/main/java/pl/jakubweg/PlayerController.java b/app/src/main/java/pl/jakubweg/PlayerController.java index d20efc5d..c06d0e58 100644 --- a/app/src/main/java/pl/jakubweg/PlayerController.java +++ b/app/src/main/java/pl/jakubweg/PlayerController.java @@ -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; @@ -10,6 +11,8 @@ import android.util.Log; import android.view.View; import android.view.ViewGroup; +import com.google.android.apps.youtube.app.YouTubeTikTokRoot_Application; + import java.lang.ref.WeakReference; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -59,6 +62,13 @@ public class PlayerController { VideoInformation.currentVideoId = videoId; + Context context = YouTubeTikTokRoot_Application.getAppContext(); + if(context == null){ + Log.e(TAG, "context is null"); + return; + } + SponsorBlockSettings.update(context); + if (!SponsorBlockSettings.isSponsorBlockEnabled) { currentVideoId = null; return; diff --git a/app/src/main/java/pl/jakubweg/ShieldButton.java b/app/src/main/java/pl/jakubweg/ShieldButton.java index 670174c7..0acaf4f3 100644 --- a/app/src/main/java/pl/jakubweg/ShieldButton.java +++ b/app/src/main/java/pl/jakubweg/ShieldButton.java @@ -34,7 +34,6 @@ public class ShieldButton { } _youtubeControlsLayout = (RelativeLayout) viewStub; - initButtonVisibilitySettings(); ImageView imageView = (ImageView)_youtubeControlsLayout .findViewById(getIdentifier("sponsorblock_button", "id")); @@ -107,20 +106,6 @@ public class ShieldButton { 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 private static int getIdentifier(String name, String defType) { Context context = YouTubeTikTokRoot_Application.getAppContext(); diff --git a/app/src/main/java/pl/jakubweg/SponsorBlockPreferenceFragment.java b/app/src/main/java/pl/jakubweg/SponsorBlockPreferenceFragment.java index 8e44e38b..e29c651b 100644 --- a/app/src/main/java/pl/jakubweg/SponsorBlockPreferenceFragment.java +++ b/app/src/main/java/pl/jakubweg/SponsorBlockPreferenceFragment.java @@ -36,7 +36,6 @@ 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 { @@ -54,6 +53,8 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(context); setPreferenceScreen(preferenceScreen); + SponsorBlockSettings.update(context); + { SwitchPreference preference = new SwitchPreference(context); preferenceScreen.addPreference(preference); diff --git a/app/src/main/java/pl/jakubweg/SponsorBlockSettings.java b/app/src/main/java/pl/jakubweg/SponsorBlockSettings.java index 12821f00..d2a0f12e 100644 --- a/app/src/main/java/pl/jakubweg/SponsorBlockSettings.java +++ b/app/src/main/java/pl/jakubweg/SponsorBlockSettings.java @@ -86,7 +86,7 @@ public class SponsorBlockSettings { SponsorBlockUtils.hideShieldButton(); SponsorBlockUtils.hideVoteButton(); PlayerController.sponsorSegmentsOfCurrentVideo = null; - } else if (/*isAddNewSegmentEnabled*/false) { + } else { /*isAddNewSegmentEnabled*/ SponsorBlockUtils.showShieldButton(); } diff --git a/app/src/main/java/pl/jakubweg/SponsorBlockUtils.java b/app/src/main/java/pl/jakubweg/SponsorBlockUtils.java index 41e73be8..11757297 100644 --- a/app/src/main/java/pl/jakubweg/SponsorBlockUtils.java +++ b/app/src/main/java/pl/jakubweg/SponsorBlockUtils.java @@ -602,5 +602,4 @@ public abstract class SponsorBlockUtils { } } } - } diff --git a/app/src/main/java/pl/jakubweg/SponsorSegment.java b/app/src/main/java/pl/jakubweg/SponsorSegment.java index f96117d0..b6ea2d48 100644 --- a/app/src/main/java/pl/jakubweg/SponsorSegment.java +++ b/app/src/main/java/pl/jakubweg/SponsorSegment.java @@ -26,5 +26,4 @@ public class SponsorSegment implements Comparable { public int compareTo(SponsorSegment o) { return (int) (this.start - o.start); } - } diff --git a/app/src/main/java/pl/jakubweg/VotingButton.java b/app/src/main/java/pl/jakubweg/VotingButton.java index b0bd09e6..9b9f558b 100644 --- a/app/src/main/java/pl/jakubweg/VotingButton.java +++ b/app/src/main/java/pl/jakubweg/VotingButton.java @@ -34,7 +34,6 @@ public class VotingButton { } _youtubeControlsLayout = (RelativeLayout) viewStub; - initButtonVisibilitySettings(); ImageView imageView = (ImageView)_youtubeControlsLayout .findViewById(getIdentifier("voting_button", "id")); @@ -107,20 +106,6 @@ public class VotingButton { 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 private static int getIdentifier(String name, String defType) { Context context = YouTubeTikTokRoot_Application.getAppContext(); diff --git a/build.gradle b/build.gradle index 6754c23d..996b567e 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath "com.android.tools.build:gradle:4.0.1" + classpath 'com.android.tools.build:gradle:4.2.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 66f8458b..e7c8788f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Aug 18 22:56:28 EEST 2020 +#Mon Jun 07 19:51:48 CEST 2021 distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip +zipStoreBase=GRADLE_USER_HOME