From 7842c3038fd5aa8af693d89863c3036295a28b5b Mon Sep 17 00:00:00 2001 From: Brian Kennish Date: Mon, 25 Mar 2024 18:27:51 -0400 Subject: [PATCH] Preventing re-initialization. --- android/app/build.gradle | 4 +- .../adblockfast/AdblockFastApplication.java | 66 ++++++++++--------- .../adblockfast/MainActivity.java | 9 ++- 3 files changed, 44 insertions(+), 35 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index ab31b7e..109a374 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -59,12 +59,12 @@ dependencies { implementation 'androidx.preference:preference:1.2.1' implementation 'org.apache.maven:maven-artifact:3.8.1' implementation 'com.github.kittinunf.fuel:fuel:1.6.0' - implementation 'com.massive:sdk:0.7.0' implementation 'io.github.inflationx:calligraphy3:3.1.1' implementation 'io.github.inflationx:viewpump:2.0.3' implementation 'com.dtx12:actions:0.1.4' - implementation 'com.wbrawner.plausible:plausible-android:0.1.0-SNAPSHOT' + implementation 'com.massive:sdk:0.7.0' implementation 'com.google.firebase:firebase-functions:20.4.0' implementation 'com.onesignal:OneSignal:5.1.6' + implementation 'com.wbrawner.plausible:plausible-android:0.1.0-SNAPSHOT' testImplementation 'junit:junit:4.12' } diff --git a/android/app/src/main/java/com/rocketshipapps/adblockfast/AdblockFastApplication.java b/android/app/src/main/java/com/rocketshipapps/adblockfast/AdblockFastApplication.java index b4db5fb..8295272 100644 --- a/android/app/src/main/java/com/rocketshipapps/adblockfast/AdblockFastApplication.java +++ b/android/app/src/main/java/com/rocketshipapps/adblockfast/AdblockFastApplication.java @@ -23,10 +23,10 @@ import com.massive.sdk.MassiveServiceType; import com.massive.sdk.State; -import com.wbrawner.plausible.android.Plausible; - import com.onesignal.OneSignal; +import com.wbrawner.plausible.android.Plausible; + import com.rocketshipapps.adblockfast.utils.Ruleset; public class AdblockFastApplication extends Application { @@ -140,36 +140,40 @@ public static void dumpPrefs() { } public static void initMassive(Context context) { - MassiveClient.Companion.getInstance(context, (client) -> { - massiveClient = client; - - if (client.getState() == State.NotInitialized) { - client.initAsync( - BuildConfig.MASSIVE_API_TOKEN, - new MassiveOptions( - MassiveServiceType.Foreground, - new MassiveNotificationOptions( - context.getString(R.string.name), - context.getString(R.string.foreground_text), - R.drawable.icon - ) - ), - new InitCallback() { - @Override - public void onSuccess() { - if (Ruleset.isUpgraded()) client.start(); - Plausible.INSTANCE.event("Succeed", "/massive", "", null); + if (massiveClient == null) { + MassiveClient.Companion.getInstance(context, (client) -> { + massiveClient = client; + + if (client.getState() == State.NotInitialized) { + client.initAsync( + BuildConfig.MASSIVE_API_TOKEN, + new MassiveOptions( + MassiveServiceType.Foreground, + new MassiveNotificationOptions( + context.getString(R.string.name), + context.getString(R.string.foreground_text), + R.drawable.icon + ) + ), + new InitCallback() { + @Override + public void onSuccess() { + if (Ruleset.isUpgraded()) client.start(); + Plausible.INSTANCE.event("Succeed", "/massive", "", null); + } + + @Override + public void onFailure(@NonNull String message) { + Plausible.INSTANCE.event("Fail", "/massive", "", null); + } } + ); + } - @Override - public void onFailure(@NonNull String message) { - Plausible.INSTANCE.event("Fail", "/massive", "", null); - } - } - ); - } - - return Unit.INSTANCE; - }); + return Unit.INSTANCE; + }); + } else if (massiveClient.getState() != State.NotInitialized && Ruleset.isUpgraded()) { + massiveClient.start(); + } } } diff --git a/android/app/src/main/java/com/rocketshipapps/adblockfast/MainActivity.java b/android/app/src/main/java/com/rocketshipapps/adblockfast/MainActivity.java index ee7f3d2..77b69f1 100644 --- a/android/app/src/main/java/com/rocketshipapps/adblockfast/MainActivity.java +++ b/android/app/src/main/java/com/rocketshipapps/adblockfast/MainActivity.java @@ -54,11 +54,13 @@ import io.github.inflationx.viewpump.ViewPump; import io.github.inflationx.viewpump.ViewPumpContextWrapper; -import com.wbrawner.plausible.android.Plausible; +import com.massive.sdk.State; import com.onesignal.Continue; import com.onesignal.OneSignal; +import com.wbrawner.plausible.android.Plausible; + import com.rocketshipapps.adblockfast.utils.Ruleset; public class MainActivity extends AppCompatActivity { @@ -114,7 +116,10 @@ protected void onResume() { if (AdblockFastApplication.massiveClient == null) { AdblockFastApplication.initMassive(this); - } else if (Ruleset.isUpgraded()) { + } else if ( + AdblockFastApplication.massiveClient.getState() != State.NotInitialized && + Ruleset.isUpgraded() + ) { AdblockFastApplication.massiveClient.start(); }