Panagiotis Triantafyllou

crash fixes

......@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'ly.warp'
PUBLISH_VERSION = '4.5.4.6rc33'
PUBLISH_VERSION = '4.5.4.6rc34'
PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
}
......
......@@ -100,7 +100,7 @@ public enum Warply {
public static Map<WarpConstants.LocationSetting, Integer> LOCATION_SETTINGS_MAP;
private static final int MINIMUM_REQUESTS_FOR_SENDING = 10;
public WeakReference<Context> mContext;
public Context mContext;
private CallbackReceiver<ServiceRegistrationCallback> mRegistrationListener;
private RequestQueue mRequestQueue;
......@@ -130,7 +130,7 @@ public enum Warply {
@Override
public void onInit(Context context) {
if (context != null) {
INSTANCE.mContext = new WeakReference<>(context.getApplicationContext());
INSTANCE.mContext = context.getApplicationContext();
}
initInternal(context);
}
......@@ -144,14 +144,14 @@ public enum Warply {
}
if (INSTANCE.mRequestQueue == null)
INSTANCE.mRequestQueue = Volley.newRequestQueue(context);
INSTANCE.mContext = new WeakReference<>(context.getApplicationContext());
WarpConstants.DEBUG = WarplyProperty.isDebugMode(INSTANCE.mContext.get());
INSTANCE.mContext = context.getApplicationContext();
WarpConstants.DEBUG = WarplyProperty.isDebugMode(INSTANCE.mContext);
INSTANCE.isInitializedOrThrow();
WarpConstants.GCM_SENDER_ID = WarpUtils.getLastGCMSenderId(INSTANCE.mContext.get());
WarpConstants.GCM_SENDER_ID = WarpUtils.getLastGCMSenderId(INSTANCE.mContext);
if (!WarpUtils.getLastApplicationUUID(context).equals(WarplyProperty.getAppUuid(context))) {
resetWarplyWebId();
}
WarplyServerPreferencesManager.initiateMicroAppStatusesMap();
WarplyServerPreferencesManager.initiateMicroAppStatusesMap(context);
}
/**
......@@ -163,13 +163,13 @@ public enum Warply {
WarpUtils.log("Warply has not been initialized, call init(Context) first");
// return;
}
if (mContext != null && mContext.get() == null) {
if (mContext != null) {
WarpUtils.log("Warply has not been initialized, call init(Context) first");
// return;
}
if (mContext != null && mContext.get() != null) {
String apiKey = WarplyProperty.getAppUuid(mContext.get());
if (mContext != null) {
String apiKey = WarplyProperty.getAppUuid(mContext);
if (TextUtils.isEmpty(apiKey)) {
WarpUtils.log("Warply application UUID has not been set in the Manifest");
// return;
......@@ -268,7 +268,7 @@ public enum Warply {
}
private void getContextInternal(CallbackReceiver<JSONObject> receiver) {
if (!WarpUtils.isRegisteredWarply(mContext.get())) {
if (!WarpUtils.isRegisteredWarply(mContext)) {
if (receiver != null)
receiver.onFailure(WarpConstants.RESULT_CODE_NOT_REGISTERED);
return;
......@@ -291,7 +291,7 @@ public enum Warply {
private void getMicroappDataInternal(String microappName,
CallbackReceiver<JSONObject> receiver) {
if (!WarpUtils.isRegisteredWarply(mContext.get())) {
if (!WarpUtils.isRegisteredWarply(mContext)) {
if (receiver != null)
receiver.onFailure(WarpConstants.RESULT_CODE_NOT_REGISTERED);
return;
......@@ -328,7 +328,7 @@ public enum Warply {
private void postReceiveMicroappDataInternal(String microappName,
JSONObject jObj, CallbackReceiver<JSONObject> receiver) {
if (!WarpUtils.isRegisteredWarply(mContext.get())) {
if (!WarpUtils.isRegisteredWarply(mContext)) {
if (receiver != null)
receiver.onFailure(WarpConstants.RESULT_CODE_NOT_REGISTERED);
return;
......@@ -346,7 +346,7 @@ public enum Warply {
private void postReceiveMicroappDataInternal(boolean hasAuthHeaders, String path, JSONObject jObj,
CallbackReceiver<JSONObject> receiver) {
if (!WarpUtils.isRegisteredWarply(mContext.get())) {
if (!WarpUtils.isRegisteredWarply(mContext)) {
if (receiver != null)
receiver.onFailure(WarpConstants.RESULT_CODE_NOT_REGISTERED);
return;
......@@ -362,7 +362,7 @@ public enum Warply {
private void postReceiveMicroappDataInternal(String microappName, boolean hasAuthHeaders, String path,
JSONObject jObj, CallbackReceiver<JSONObject> receiver) {
if (!WarpUtils.isRegisteredWarply(mContext.get())) {
if (!WarpUtils.isRegisteredWarply(mContext)) {
if (receiver != null)
receiver.onFailure(WarpConstants.RESULT_CODE_NOT_REGISTERED);
return;
......@@ -410,11 +410,26 @@ public enum Warply {
INSTANCE.postMicroappDataInternal(microappName, jObj, force);
}
public static void postMicroappData(Context context, String microappName, JSONObject jObj, boolean force) {
INSTANCE.isInitializedOrThrow();
INSTANCE.postMicroappDataInternal(context, microappName, jObj, force);
}
private void postMicroappDataInternal(String microappName, JSONObject jObj, boolean force) {
isInitializedOrThrow();
long requestsInQueueCount = 0;
if (jObj != null) {
requestsInQueueCount = WarplyDBHelper.getInstance(mContext.get()).addRequest(
if (jObj != null && mContext != null) {
requestsInQueueCount = WarplyDBHelper.getInstance(mContext).addRequest(
microappName, jObj.toString(), force);
}
tryWakingSendingTaskInternal(requestsInQueueCount);
}
private void postMicroappDataInternal(Context context, String microappName, JSONObject jObj, boolean force) {
isInitializedOrThrow();
long requestsInQueueCount = 0;
if (jObj != null && context != null) {
requestsInQueueCount = WarplyDBHelper.getInstance(context).addRequest(
microappName, jObj.toString(), force);
}
tryWakingSendingTaskInternal(requestsInQueueCount);
......@@ -429,7 +444,7 @@ public enum Warply {
isInitializedOrThrow();
long requestsInQueueCount = 0;
if (jObj != null) {
requestsInQueueCount = WarplyDBHelper.getInstance(mContext.get()).addPushRequest(
requestsInQueueCount = WarplyDBHelper.getInstance(mContext).addPushRequest(
microappName, jObj.toString(), force);
}
tryWakingSendingPushTaskInternal(requestsInQueueCount, false);
......@@ -444,7 +459,7 @@ public enum Warply {
isInitializedOrThrow();
long requestsInQueueCount = 0;
if (jObj != null) {
requestsInQueueCount = WarplyDBHelper.getInstance(mContext.get()).addPushAckRequest(
requestsInQueueCount = WarplyDBHelper.getInstance(mContext).addPushAckRequest(
microappName, jObj.toString(), force);
}
tryWakingSendingPushAckTaskInternal(requestsInQueueCount, false);
......@@ -468,7 +483,7 @@ public enum Warply {
}
final String requestSignature = request.getSignature();
final WarplyPreferences warplyPreferences = new WarplyPreferences(INSTANCE.mContext.get());
final WarplyPreferences warplyPreferences = new WarplyPreferences(INSTANCE.mContext);
long elapsedTimeAfterLastUpdate = System.currentTimeMillis() - warplyPreferences.getInboxLastCachedTimeStamp(requestSignature);
long updateInterval = request.getCacheUpdateInterval();
boolean isNeedUpdateCampaignsByTimeStamp = elapsedTimeAfterLastUpdate > updateInterval;
......@@ -478,7 +493,7 @@ public enum Warply {
|| INSTANCE.mLastReceivedCampaigns.size() == 0
|| !INSTANCE.mLastReceivedCampaigns.getRequestSignature().equals(requestSignature)) {
final ObjectSerializer objectSerializer = new ObjectSerializer(INSTANCE.mContext.get());
final ObjectSerializer objectSerializer = new ObjectSerializer(INSTANCE.mContext);
CampaignList campaignsCache = (CampaignList) objectSerializer.deserialize(File.separator + requestSignature);
if (isNeedUpdateCampaignsByTimeStamp
|| campaignsCache == null
......@@ -671,7 +686,7 @@ public enum Warply {
final SimpleCallbackReceiver<Boolean> callback) {
INSTANCE.isInitializedOrThrow();
final WarplyPreferences warplyPreferences = new WarplyPreferences(INSTANCE.mContext.get());
final WarplyPreferences warplyPreferences = new WarplyPreferences(INSTANCE.mContext);
if (warplyPreferences.getBoolean(WarpConstants.KEY_APP_VAR_UPDATE_HAS, false)
&& warplyPreferences.getInt(WarpConstants.KEY_APP_VAR_UPDATE_VERSION_CODE, 0) >
WarplyProperty.getAppVersionCode(Warply.getWarplyContext())) {
......@@ -756,7 +771,7 @@ public enum Warply {
private void registerWarplyInternal() {
isInitializedOrThrow();
if (!WarpUtils.isRegisteredWarply(mContext.get()))
if (!WarpUtils.isRegisteredWarply(mContext))
wakeRegistrationTask();
}
......@@ -773,7 +788,7 @@ public enum Warply {
private void resetWarplyWebIdInternal() {
isInitializedOrThrow();
WarpUtils.setWebId(mContext.get(), "");
WarpUtils.setWebId(mContext, "");
if (mRegistrationListener != null)
mRegistrationListener
.onSuccess(ServiceRegistrationCallback.UNREGISTERED_WARPLY);
......@@ -790,7 +805,7 @@ public enum Warply {
}
private void setGCMEnabledInternal(boolean enabled) {
WarpUtils.setGCMEnabled(mContext.get(), enabled);
WarpUtils.setGCMEnabled(mContext, enabled);
}
/**
......@@ -809,7 +824,7 @@ public enum Warply {
}
private Context getWarplyContextInternal() {
return mContext.get();
return mContext;
}
/**
......@@ -830,20 +845,20 @@ public enum Warply {
WarpUtils.log("**************************************************");
final WarplyDeviceInfoCollector deviceInfoCollector = new WarplyDeviceInfoCollector(mContext.get());
final WarplyDeviceInfoCollector deviceInfoCollector = new WarplyDeviceInfoCollector(mContext);
deviceInfoCollector.collectToJson(new SimpleCallbackReceiver<JSONObject>() {
@Override
public void onResult(JSONObject json, int errorCode) {
super.onResult(json, errorCode);
if (json != null) {
if (!WarpUtils.getIsDeviceInfoSaved(mContext.get())) {
WarpUtils.setIsDeviceInfoSaved(mContext.get(), true);
WarpUtils.setDeviceInfoObject(mContext.get(), json);
if (!WarpUtils.getIsDeviceInfoSaved(mContext)) {
WarpUtils.setIsDeviceInfoSaved(mContext, true);
WarpUtils.setDeviceInfoObject(mContext, json);
postMicroappData(WarpConstants.MICROAPP_DEVICE_INFO, json, true);
} else {
if (hasDeviceInfoDifference(WarpUtils.getDeviceInfoObject(mContext.get()), json)) {
WarpUtils.setDeviceInfoObject(mContext.get(), json);
if (hasDeviceInfoDifference(WarpUtils.getDeviceInfoObject(mContext), json)) {
WarpUtils.setDeviceInfoObject(mContext, json);
postMicroappData(WarpConstants.MICROAPP_DEVICE_INFO, json, true);
}
}
......@@ -894,21 +909,21 @@ public enum Warply {
WarpUtils.log("**************************************************");
JSONObject object = new JSONObject();
try {
PackageInfo info = mContext.get().getPackageManager().getPackageInfo(mContext.get().getApplicationContext().getPackageName(), 0);
PackageInfo info = mContext.getPackageManager().getPackageInfo(mContext.getApplicationContext().getPackageName(), 0);
if (WarpUtils.getTrackersEnabled(mContext.get())) {
if (WarpUtils.getTrackersEnabled(mContext)) {
object.putOpt("app_version", info.versionName);
object.putOpt("sdk_version", WarpConstants.SDK_VERSION);
object.putOpt("app_build", info.versionCode);
}
// object.putOpt("bundle_identifier", mContext.get().getApplicationContext().getPackageName());
if (!WarpUtils.getHasApplicationInfo(mContext.get())) {
WarpUtils.setHasApplicationInfo(mContext.get(), true);
WarpUtils.setAppDataObject(mContext.get(), object);
if (!WarpUtils.getHasApplicationInfo(mContext)) {
WarpUtils.setHasApplicationInfo(mContext, true);
WarpUtils.setAppDataObject(mContext, object);
postMicroappData(WarpConstants.MICROAPP_APPLICATION_DATA, object, force);
} else {
if (hasApplicationDataDifference(WarpUtils.getAppDataObject(mContext.get()), object)) {
WarpUtils.setAppDataObject(mContext.get(), object);
if (hasApplicationDataDifference(WarpUtils.getAppDataObject(mContext), object)) {
WarpUtils.setAppDataObject(mContext, object);
postMicroappData(WarpConstants.MICROAPP_APPLICATION_DATA, object, force);
}
}
......@@ -949,8 +964,8 @@ public enum Warply {
WarpUtils.log("************* WARPLY Info ********************");
WarpUtils.log("[WARP Trace] Resetting application info");
WarpUtils.log("**********************************************");
WarpUtils.setLastApplicationData(mContext.get(), "");
if (WarpUtils.getIsAPPDATAENABLED(mContext.get()))
WarpUtils.setLastApplicationData(mContext, "");
if (WarpUtils.getIsAPPDATAENABLED(mContext))
postApplicationData(true);
}
......@@ -960,7 +975,7 @@ public enum Warply {
}
private void resetDeviceInfoInternal() {
WarpUtils.setLastDeviceInfo(mContext.get(), "");
WarpUtils.setLastDeviceInfo(mContext, "");
// postDeviceInfoData();
}
......@@ -970,7 +985,7 @@ public enum Warply {
}
private void resetIsWarpedInternal() {
String lastGCMSenderId = WarpUtils.getLastGCMSenderId(mContext.get());
String lastGCMSenderId = WarpUtils.getLastGCMSenderId(mContext);
if (lastGCMSenderId == null)
return;
if (lastGCMSenderId.equals(""))
......@@ -999,15 +1014,15 @@ public enum Warply {
if (mContext == null) {
return;
}
if (!WarpUtils.isRegisteredWarply(mContext.get())) {
if (!WarpUtils.isRegisteredWarply(mContext)) {
registerWarply();
return;
}
if (WarpUtils.getIsDEVICEINFOENABLED(mContext.get()))
if (WarpUtils.getIsDEVICEINFOENABLED(mContext))
postDeviceInfoData();
if (WarpUtils.getIsAPPDATAENABLED(mContext.get()))
if (WarpUtils.getIsAPPDATAENABLED(mContext))
postApplicationData(true);
tryWakingSendingTaskInternal(WarplyDBHelper.getInstance(mContext.get())
tryWakingSendingTaskInternal(WarplyDBHelper.getInstance(mContext)
.getRequestsInQueueCount());
}
......@@ -1018,7 +1033,7 @@ public enum Warply {
ArrayList<Long> ids = new ArrayList<>();
JSONArray jArray = new JSONArray();
Cursor c = WarplyDBHelper.getInstance(mContext.get()).getAllRequests();
Cursor c = WarplyDBHelper.getInstance(mContext).getAllRequests();
while (c.moveToNext()) {
JSONObject jObj = new JSONObject();
try {
......@@ -1053,7 +1068,7 @@ public enum Warply {
ArrayList<Long> ids = new ArrayList<>();
JSONArray jArray = new JSONArray();
Cursor c = WarplyDBHelper.getInstance(mContext.get()).getAllPushRequests();
Cursor c = WarplyDBHelper.getInstance(mContext).getAllPushRequests();
while (c.moveToNext()) {
JSONObject jObj = new JSONObject();
try {
......@@ -1084,7 +1099,7 @@ public enum Warply {
ArrayList<Long> ids = new ArrayList<>();
JSONArray jArray = new JSONArray();
Cursor c = WarplyDBHelper.getInstance(mContext.get()).getAllPushAckRequests();
Cursor c = WarplyDBHelper.getInstance(mContext).getAllPushAckRequests();
while (c.moveToNext()) {
JSONObject jObj = new JSONObject();
try {
......@@ -1115,11 +1130,11 @@ public enum Warply {
public static void tryWakingSendingTask() {
INSTANCE.isInitializedOrThrow();
INSTANCE.tryWakingSendingTaskInternal(WarplyDBHelper.getInstance(
INSTANCE.mContext.get()).getRequestsInQueueCount());
INSTANCE.mContext).getRequestsInQueueCount());
}
private void tryWakingSendingTaskInternal(long requestsInQueue) {
if (!WarpUtils.isRegisteredWarply(mContext.get())) {
if (!WarpUtils.isRegisteredWarply(mContext)) {
WarpUtils
.log("************* WARPLY Registration ********************");
WarpUtils
......@@ -1132,7 +1147,7 @@ public enum Warply {
// if (WarplyDBHelper.getInstance(mContext.get()).isForceRequestsExist()
// || (requestsInQueue >= MINIMUM_REQUESTS_FOR_SENDING)) {
if (WarplyDBHelper.getInstance(mContext.get()).isForceRequestsExist()
if (WarplyDBHelper.getInstance(mContext).isForceRequestsExist()
|| (requestsInQueue > 0)) {
WarpUtils.log("Waking post task!");
......@@ -1145,11 +1160,11 @@ public enum Warply {
public static void tryWakingSendingPushTask(boolean force) {
INSTANCE.isInitializedOrThrow();
INSTANCE.tryWakingSendingPushTaskInternal(WarplyDBHelper.getInstance(
INSTANCE.mContext.get()).getPushRequestsInQueueCount(), force);
INSTANCE.mContext).getPushRequestsInQueueCount(), force);
}
private void tryWakingSendingPushTaskInternal(long requestsInQueue, boolean force) {
if (!WarpUtils.isRegisteredWarply(mContext.get())) {
if (!WarpUtils.isRegisteredWarply(mContext)) {
WarpUtils
.log("************* WARPLY Registration ********************");
WarpUtils
......@@ -1170,11 +1185,11 @@ public enum Warply {
public static void tryWakingSendingPushAckTask(boolean force) {
INSTANCE.isInitializedOrThrow();
INSTANCE.tryWakingSendingPushAckTaskInternal(WarplyDBHelper.getInstance(
INSTANCE.mContext.get()).getPushAckRequestsInQueueCount(), force);
INSTANCE.mContext).getPushAckRequestsInQueueCount(), force);
}
private void tryWakingSendingPushAckTaskInternal(long requestsInQueue, boolean force) {
if (!WarpUtils.isRegisteredWarply(mContext.get())) {
if (!WarpUtils.isRegisteredWarply(mContext)) {
WarpUtils
.log("************* WARPLY Registration ********************");
WarpUtils
......@@ -1312,8 +1327,8 @@ public enum Warply {
}
WarpUtils.log("************* WARPLY " + methodName + " Context ********************");
WarpUtils.log("[WARP Trace] HTTP Web Id: " + WarpUtils.getWebId(mContext.get()));
WarpUtils.log("[WARP Trace] HTTP API Key: " + WarplyProperty.getAppUuid(mContext.get()));
WarpUtils.log("[WARP Trace] HTTP Web Id: " + WarpUtils.getWebId(mContext));
WarpUtils.log("[WARP Trace] HTTP API Key: " + WarplyProperty.getAppUuid(mContext));
WarpUtils.verbose("[WARP Trace] HTTP " + methodName + " Request URL: " + url);
if (data != null) {
try {
......@@ -1389,8 +1404,8 @@ public enum Warply {
}
WarpUtils.log("************* WARPLY " + methodName + " Context ********************");
WarpUtils.log("[WARP Trace] HTTP Web Id: " + WarpUtils.getWebId(mContext.get()));
WarpUtils.log("[WARP Trace] HTTP API Key: " + WarplyProperty.getAppUuid(mContext.get()));
WarpUtils.log("[WARP Trace] HTTP Web Id: " + WarpUtils.getWebId(mContext));
WarpUtils.log("[WARP Trace] HTTP API Key: " + WarplyProperty.getAppUuid(mContext));
WarpUtils.verbose("[WARP Trace] HTTP " + methodName + " Request URL: " + url);
if (data != null) {
try {
......@@ -1436,8 +1451,8 @@ public enum Warply {
}
WarpUtils.log("************* WARPLY " + methodName + " Context ********************");
WarpUtils.log("[WARP Trace] HTTP Web Id: " + WarpUtils.getWebId(mContext.get()));
WarpUtils.log("[WARP Trace] HTTP API Key: " + WarplyProperty.getAppUuid(mContext.get()));
WarpUtils.log("[WARP Trace] HTTP Web Id: " + WarpUtils.getWebId(mContext));
WarpUtils.log("[WARP Trace] HTTP API Key: " + WarplyProperty.getAppUuid(mContext));
WarpUtils.verbose("[WARP Trace] HTTP " + methodName + " Request URL: " + url);
if (data != null) {
try {
......@@ -1469,13 +1484,13 @@ public enum Warply {
}
if (tempAnalytics != null && tempAnalytics.length() > 0) {
String urlAnalytics = WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_ANALYTICS + WarplyProperty.getAppUuid(mContext.get()) + "/";
String urlAnalytics = WarplyProperty.getBaseUrl(mContext) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_ANALYTICS + WarplyProperty.getAppUuid(mContext) + "/";
WarplyJsonArrayRequest requestAnalytics = new WarplyJsonArrayRequest(method, urlAnalytics, tempAnalytics, vt, vt);
requestAnalytics.setTag(tag);
mRequestQueue.add(requestAnalytics);
}
if (tempDeviceInfo != null && tempDeviceInfo.length() > 0) {
String urlDeviceInfo = WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_DEVICE_INFO + WarplyProperty.getAppUuid(mContext.get()) + "/";
String urlDeviceInfo = WarplyProperty.getBaseUrl(mContext) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_DEVICE_INFO + WarplyProperty.getAppUuid(mContext) + "/";
WarplyJsonArrayRequest requestDeviceInfo = new WarplyJsonArrayRequest(method, urlDeviceInfo, tempDeviceInfo, vt, vt);
requestDeviceInfo.setTag(tag);
mRequestQueue.add(requestDeviceInfo);
......@@ -1539,10 +1554,10 @@ public enum Warply {
}
if (tempAnalytics != null && tempAnalytics.length() > 0) {
url = WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_ANALYTICS + WarplyProperty.getAppUuid(mContext.get()) + "/";
url = WarplyProperty.getBaseUrl(mContext) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_ANALYTICS + WarplyProperty.getAppUuid(mContext) + "/";
}
if (tempDeviceInfo != null && tempDeviceInfo.length() > 0) {
url = WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_DEVICE_INFO + WarplyProperty.getAppUuid(mContext.get()) + "/";
url = WarplyProperty.getBaseUrl(mContext) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_DEVICE_INFO + WarplyProperty.getAppUuid(mContext) + "/";
}
if (tempOther != null && tempOther.length() > 0) {
url = buildWarplyRequestUrl(warplyPath);
......@@ -1554,8 +1569,8 @@ public enum Warply {
private void getFromServerInternal(JSONObject data, String warplyPath,
CallbackReceiver<JSONObject> listener, Object tag) {
String url = buildWarplyRequestUrl(warplyPath);
if (WarpUtils.getCurrentTimeMillis(mContext.get()) == 0 || (WarpUtils.getCurrentTimeMillis(mContext.get()) > 0) && (System.currentTimeMillis() > WarpUtils.getCurrentTimeMillis(mContext.get()) + (3600000))) {
WarpUtils.setCurrentTimeMillis(mContext.get(), System.currentTimeMillis());
if (WarpUtils.getCurrentTimeMillis(mContext) == 0 || (WarpUtils.getCurrentTimeMillis(mContext) > 0) && (System.currentTimeMillis() > WarpUtils.getCurrentTimeMillis(mContext) + (3600000))) {
WarpUtils.setCurrentTimeMillis(mContext, System.currentTimeMillis());
requestToServerInternal(Method.GET, url, data, listener, tag);
}
}
......@@ -1566,10 +1581,10 @@ public enum Warply {
}
private void registerToServerInternal() {
final String url = WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.BASE_URL_MOBILE + WarplyProperty.getAppUuid(mContext.get())
final String url = WarplyProperty.getBaseUrl(mContext) + WarpConstants.BASE_URL_MOBILE + WarplyProperty.getAppUuid(mContext)
+ "/" + WarpConstants.PATH_REGISTER + "/";
new WarplyDeviceInfoCollector(mContext.get()).getRegistrationParams(new SimpleCallbackReceiver<JSONObject>() {
new WarplyDeviceInfoCollector(mContext).getRegistrationParams(new SimpleCallbackReceiver<JSONObject>() {
@Override
public void onResult(JSONObject result, int errorCode) {
super.onResult(result, errorCode);
......@@ -1579,8 +1594,8 @@ public enum Warply {
}
private String buildWarplyRequestUrl(String warplyPath) {
StringBuilder sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.BASE_URL_MOBILE);
sb.append(WarplyProperty.getAppUuid(mContext.get())).append("/")
StringBuilder sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext) + WarpConstants.BASE_URL_MOBILE);
sb.append(WarplyProperty.getAppUuid(mContext)).append("/")
.append(WarpConstants.PATH_CONTEXT).append("/");
if (warplyPath != null)
sb.append("?path=").append(warplyPath);
......@@ -1588,8 +1603,8 @@ public enum Warply {
}
private String buildWarplyRequestUrl(String warplyPath, boolean personalized) {
StringBuilder sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.BASE_URL_AUTH);
sb.append(WarplyProperty.getAppUuid(mContext.get())).append("/")
StringBuilder sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext) + WarpConstants.BASE_URL_AUTH);
sb.append(WarplyProperty.getAppUuid(mContext)).append("/")
.append(WarpConstants.PATH_CONTEXT);
if (warplyPath != null)
sb.append("?path=").append(warplyPath);
......@@ -1599,16 +1614,16 @@ public enum Warply {
private String buildWarplyAuthRequestUrl(String warplyPath, boolean isUserPath) {
StringBuilder sb;
if (isUserPath)
sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.BASE_URL_USER_AUTH);
sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext) + WarpConstants.BASE_URL_USER_AUTH);
else {
if (warplyPath.equals("handle_image"))
sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.BASE_URL_API);
sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext) + WarpConstants.BASE_URL_API);
else if (warplyPath.equals("verify"))
sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext.get()) + WarplyProperty.getVerifyUrl(mContext.get()));
sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext) + WarplyProperty.getVerifyUrl(mContext));
else if (warplyPath.equals("cosuser"))
sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext.get()) + "/partners/oauth/" + WarplyProperty.getAppUuid(mContext.get()) + "/token");
sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext) + "/partners/oauth/" + WarplyProperty.getAppUuid(mContext) + "/token");
else
sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.BASE_URL_AUTH);
sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext) + WarpConstants.BASE_URL_AUTH);
}
if (warplyPath != null) {
......@@ -1616,7 +1631,7 @@ public enum Warply {
if (warplyPath.equals("cosuser")) {
return sb.toString();
}
sb.append(WarplyProperty.getAppUuid(mContext.get())).append("/");
sb.append(WarplyProperty.getAppUuid(mContext)).append("/");
if (warplyPath.equals("generate")) {
sb.append(WarpConstants.BASE_URL_OTP);
}
......@@ -1670,18 +1685,18 @@ public enum Warply {
public void onSuccess(JSONObject result) {
result = result.optJSONObject("context");
if (result != null) {
WarpUtils.setLastDeviceInfo(mContext.get(), "");
WarpUtils.setLastApplicationData(mContext.get(), "");
WarpUtils.setLastApplicationUUID(mContext.get(), WarplyProperty.getAppUuid(mContext.get()));
WarplyDBHelper.getInstance(mContext.get()).deleteAllRequests();
WarplyDBHelper.getInstance(mContext.get()).deleteAllPushRequests();
WarplyDBHelper.getInstance(mContext.get()).deleteAllPushAckRequests();
WarpUtils.setLastDeviceInfo(mContext, "");
WarpUtils.setLastApplicationData(mContext, "");
WarpUtils.setLastApplicationUUID(mContext, WarplyProperty.getAppUuid(mContext));
WarplyDBHelper.getInstance(mContext).deleteAllRequests();
WarplyDBHelper.getInstance(mContext).deleteAllPushRequests();
WarplyDBHelper.getInstance(mContext).deleteAllPushAckRequests();
String webId = result.optString("web_id", "");
WarpUtils.setWebId(mContext.get(), webId);
WarpUtils.setWebId(mContext, webId);
String apiKey = result.optString("api_key", "");
WarpUtils.setApiKey(mContext.get(), apiKey);
WarpUtils.setApiKey(mContext, apiKey);
WarpUtils.log("************* WARPLY Registration ********************");
WarpUtils.log("[WARPLY Registration] URL: " + WarplyProperty.getBaseUrl(mContext.get()));
WarpUtils.log("[WARPLY Registration] URL: " + WarplyProperty.getBaseUrl(mContext));
WarpUtils.log("[WARPLY Registration] WEB_ID: " + webId);
try {
WarpUtils.log("[WARPLY Registration] Response: " + result.toString(2));
......@@ -1706,7 +1721,7 @@ public enum Warply {
mRegistrationListener.onFailure(errorCode);
if (errorCode == 3) {
final String url = WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.BASE_URL_MOBILE + WarplyProperty.getAppUuid(mContext.get())
final String url = WarplyProperty.getBaseUrl(mContext) + WarpConstants.BASE_URL_MOBILE + WarplyProperty.getAppUuid(mContext)
+ "/" + WarpConstants.PATH_REGISTER + "/";
requestToServerInternal(Method.GET, url, (JSONObject) null, mRegistrationCallBackReceiver, null);
} else
......
......@@ -254,8 +254,8 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener, Vie
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1000) {
if (resultCode == RESULT_OK) {
if (!TextUtils.isEmpty(WarplyManagerHelper.getUserTag())) {
mTvUserBadge.setText(WarplyManagerHelper.getUserTag());
if (!TextUtils.isEmpty(WarplyManagerHelper.getUserTag(LoyaltyWallet.this))) {
mTvUserBadge.setText(WarplyManagerHelper.getUserTag(LoyaltyWallet.this));
mLlQuestionnaire.setVisibility(View.GONE);
mLlUserBadge.setVisibility(View.VISIBLE);
} else {
......@@ -489,8 +489,8 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener, Vie
.into(mIvProfilePhoto);
}
if (!TextUtils.isEmpty(WarplyManagerHelper.getUserTag())) {
mTvUserBadge.setText(WarplyManagerHelper.getUserTag());
if (!TextUtils.isEmpty(WarplyManagerHelper.getUserTag(this))) {
mTvUserBadge.setText(WarplyManagerHelper.getUserTag(this));
mLlQuestionnaire.setVisibility(View.GONE);
mLlUserBadge.setVisibility(View.VISIBLE);
} else {
......
......@@ -113,9 +113,9 @@ public class VolleyTransformer implements Listener<JSONObject>, ErrorListener {
return;
WarpUtils.log("**************** WARPLY Response *****************");
WarpUtils.verbose("[WARP Trace] HTTP Web Id: "
+ WarpUtils.getWebId(Warply.INSTANCE.mContext.get()));
+ WarpUtils.getWebId(Warply.INSTANCE.mContext));
WarpUtils.verbose("[WARP Trace] HTTP API Key: "
+ WarplyProperty.getAppUuid(Warply.INSTANCE.mContext.get()));
+ WarplyProperty.getAppUuid(Warply.INSTANCE.mContext));
if (response != null) {
try {
// WarpUtils.log("[WARP Trace] Request: " + response.toString(2));
......
......@@ -61,7 +61,7 @@ public class PrefsUtils {
);
return encryptedSharedPreferences;
} catch (GeneralSecurityException | IOException e) {
} catch (Exception e) {
WarpUtils.log("PrefUtils Get Encrypted Shared Preferences Error", e);
return PreferenceManager.getDefaultSharedPreferences(context);
}
......
......@@ -256,7 +256,7 @@ public class WarpUtils {
);
_prefs = encryptedSharedPreferences;
} catch (GeneralSecurityException | IOException e) {
} catch (Exception e) {
WarpUtils.log("WarpUtils Get Encrypted Shared Preferences Error", e);
_prefs = context.getSharedPreferences(PREFERENCES_NAME,
Context.MODE_PRIVATE);
......
......@@ -1065,8 +1065,8 @@ public class WarplyManagerHelper {
/**
* Get user badge tag
*/
public static String getUserTag() {
return WarpUtils.getUserTag(Warply.getWarplyContext());
public static String getUserTag(Context context) {
return WarpUtils.getUserTag(context);
}
/**
......
......@@ -39,7 +39,7 @@ public class WarplyPreferences {
);
this.warplySharedPrefs = encryptedSharedPreferences;
} catch (GeneralSecurityException | IOException e) {
} catch (Exception e) {
WarpUtils.log("WarplyPreferences Encrypted Shared Preferences Error", e);
this.warplySharedPrefs = context.
getSharedPreferences(WARPLY_SHARED_PREFS, Activity.MODE_PRIVATE);
......
......@@ -27,12 +27,12 @@ public class WarplyProvider extends ContentProvider {
new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/pf_square_sans_pro_regular.ttf")
.setFontAttrId(R.attr.fontPath)
.setFontMapper(new FontMapper() {
@Override
public String map(String font) {
return font;
}
})
// .setFontMapper(new FontMapper() {
// @Override
// public String map(String font) {
// return font;
// }
// })
.build()))
.build());
......
......@@ -187,7 +187,7 @@ public class WarplyAnalyticsManager {
if (metadata != null) {
jObj.putOpt("action_metadata", metadata);
}
Warply.postMicroappData(WarpConstants.MICROAPP_INAPP_ANALYTICS, jObj, force);
Warply.postMicroappData(context, WarpConstants.MICROAPP_INAPP_ANALYTICS, jObj, force);
} catch (JSONException e) {
if (WarpConstants.DEBUG) {
e.printStackTrace();
......