Panagiotis Triantafyllou

SDK INIT changes

......@@ -237,13 +237,13 @@
<!-- </intent-filter>-->
<!-- </receiver>-->
<receiver
android:name=".receivers.BluetoothStateChangeReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
</intent-filter>
</receiver>
<!-- <receiver-->
<!-- android:name=".receivers.BluetoothStateChangeReceiver"-->
<!-- android:exported="false">-->
<!-- <intent-filter>-->
<!-- <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />-->
<!-- </intent-filter>-->
<!-- </receiver>-->
<receiver
android:name=".receivers.WarplyInAppNotificationReceiver"
......
......@@ -137,6 +137,19 @@ public enum Warply {
});
}
public static WarplyInitializer getWarplyInitializer(Context context, WarplyReadyCallback callback) {
return new WarplyInitializer(context, true, callback, new WarplyInitializer.WarplyInitCallback() {
@Override
public void onInit(Context context) {
if (context != null) {
INSTANCE.mContext = context.getApplicationContext();
}
initInternal(context);
}
});
}
private static void initInternal(Context context) {
if (/*isInitialized()*/ context == null) {
INSTANCE.check();
......@@ -1980,7 +1993,7 @@ public enum Warply {
@Override
public void onServerPreferencesReceived() {
// changeLocationSettings(true);
initBeaconsApplicationIfNeed();
// initBeaconsApplicationIfNeed();
WarplyUserManager.rewriteTags();
}
};
......
......@@ -7,4 +7,6 @@ public interface WarplyReadyCallback {
void onWarplyInitTimeOut();
void onWarplyPermissionsDenied();
default void onWarplyInitialized() {};
}
......
......@@ -16,6 +16,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import ly.warp.sdk.Warply;
import ly.warp.sdk.dexter.listener.DexterError;
import ly.warp.sdk.dexter.listener.PermissionDeniedResponse;
import ly.warp.sdk.io.callbacks.WarplyReadyCallback;
......@@ -65,6 +66,24 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ
stopThreadLock.set(true);
}
public WarplyInitializer(Context context, boolean isInternal, WarplyReadyCallback readyCallback, WarplyInitCallback initCallback) {
// this.mPermissionsResultRequested = false;
this.mContext = context;
this.mReadyCallback = readyCallback;
this.mInitCallback = initCallback;
if (mMainThreadHandler == null) {
mMainThreadHandler = new Handler(Looper.getMainLooper());
}
if (stopThreadLock == null) {
stopThreadLock = new AtomicBoolean(true);
}
stopThreadLock.set(true);
init();
}
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
......@@ -159,16 +178,40 @@ public class WarplyInitializer extends Thread /*implements ActivityCompat.OnRequ
// ===========================================================
public synchronized void init() {
stopThreadLock.set(true);
mInitCallback.onInit(mContext);
try {
super.start(); // call run()
} catch (IllegalThreadStateException e) {
if (WarpConstants.DEBUG) {
e.printStackTrace();
/* New code */
if (Warply.INSTANCE.mContext != null) {
if (mReadyCallback != null) {
mMainThreadHandler.post(new Runnable() {
@Override
public void run() {
mReadyCallback.onWarplyInitialized();
}
});
}
} else {
mInitCallback.onInit(mContext);
try {
super.start(); // call run()
} catch (IllegalThreadStateException e) {
if (WarpConstants.DEBUG) {
e.printStackTrace();
}
}
}
/* New code */
/* Old code */
// mInitCallback.onInit(mContext);
// try {
// super.start(); // call run()
// } catch (IllegalThreadStateException e) {
// if (WarpConstants.DEBUG) {
// e.printStackTrace();
// }
// }
/* Old code */
}
public synchronized void initWithPermissions(Activity activity) {
......