Panagiotis Triantafyllou

crash fixes

......@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'ly.warp'
PUBLISH_VERSION = '4.5.5.4r31'
PUBLISH_VERSION = '4.5.5.4r32'
PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
}
......
......@@ -1248,7 +1248,7 @@ public enum Warply {
url = buildWarplyRequestUrl(warplyPath);
}
requestToServerInternal(Method.POST, url, data, listener, tag);
requestToServerInternal(context, Method.POST, url, data, listener, tag);
}
private String buildWarplyRequestUrl(Context context, String warplyPath) {
......@@ -1593,7 +1593,7 @@ public enum Warply {
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);
if(mRequestQueue == null)
if (mRequestQueue == null)
mRequestQueue = Volley.newRequestQueue(mContext);
mRequestQueue.add(requestAnalytics);
......@@ -1602,7 +1602,7 @@ public enum Warply {
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);
if(mRequestQueue == null)
if (mRequestQueue == null)
mRequestQueue = Volley.newRequestQueue(mContext);
mRequestQueue.add(requestDeviceInfo);
......@@ -1610,7 +1610,7 @@ public enum Warply {
if (tempOther != null && tempOther.length() > 0) {
WarplyJsonArrayRequest request = new WarplyJsonArrayRequest(method, url, tempOther, vt, vt);
request.setTag(tag);
if(mRequestQueue == null)
if (mRequestQueue == null)
mRequestQueue = Volley.newRequestQueue(mContext);
mRequestQueue.add(request);
......@@ -1625,6 +1625,137 @@ public enum Warply {
/*========================== OLD, REVERT IF NEED ==========================*/
}
private void requestToServerInternal(Context context, int method, String url, JSONArray data,
CallbackReceiver<JSONObject> listener, Object tag) {
VolleyTransformer vt = new VolleyTransformer(listener);
String methodName = null;
switch (method) {
case 0:
methodName = "GET";
break;
case 1:
methodName = "POST";
break;
case 2:
methodName = "PUT";
break;
case 3:
methodName = "DELETE";
break;
}
if (mContext != null) {
WarpUtils.log("************* WARPLY " + methodName + " Context ********************");
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 {
WarpUtils.verbose("[WARP Trace] Request: " + data.toString(2));
} catch (JSONException e) {
WarpUtils.warn(
"[WARP Trace] Failed conversting JSON to string", e);
}
}
} else if (context != null) {
WarpUtils.log("************* WARPLY " + methodName + " Context ********************");
WarpUtils.log("[WARP Trace] HTTP Web Id: " + WarpUtils.getWebId(context));
WarpUtils.log("[WARP Trace] HTTP API Key: " + WarplyProperty.getAppUuid(context));
WarpUtils.verbose("[WARP Trace] HTTP " + methodName + " Request URL: " + url);
if (data != null) {
try {
WarpUtils.verbose("[WARP Trace] Request: " + data.toString(2));
} catch (JSONException e) {
WarpUtils.warn(
"[WARP Trace] Failed conversting JSON to string", e);
}
}
}
/*========================== NEW, REPLACE WITH OLD IF NEED ==========================*/
if (data != null) {
JSONArray tempAnalytics = new JSONArray();
JSONArray tempDeviceInfo = new JSONArray();
JSONArray tempOther = new JSONArray();
if (data.length() > 0) {
for (int i = 0; i < data.length(); i++) {
JSONObject microappItem = data.optJSONObject(i);
if (microappItem != null) {
if (microappItem.has("inapp_analytics")) {
tempAnalytics.put(microappItem);
} else if (microappItem.has("device_info") || microappItem.has("application_data")) {
tempDeviceInfo.put(microappItem);
} else {
tempOther.put(microappItem);
}
}
}
}
if (INSTANCE.mRequestQueue == null) {
if (INSTANCE.mContext != null)
INSTANCE.mRequestQueue = Volley.newRequestQueue(INSTANCE.mContext);
else
INSTANCE.mRequestQueue = Volley.newRequestQueue(context);
}
if (tempAnalytics != null && tempAnalytics.length() > 0) {
String urlAnalytics = "";
if (mContext != null)
urlAnalytics = WarplyProperty.getBaseUrl(mContext) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_ANALYTICS + WarplyProperty.getAppUuid(mContext) + "/";
else
urlAnalytics = WarplyProperty.getBaseUrl(context) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_ANALYTICS + WarplyProperty.getAppUuid(context) + "/";
WarplyJsonArrayRequest requestAnalytics = new WarplyJsonArrayRequest(method, urlAnalytics, tempAnalytics, vt, vt);
requestAnalytics.setTag(tag);
if (mRequestQueue == null) {
if (mContext != null)
mRequestQueue = Volley.newRequestQueue(mContext);
else
mRequestQueue = Volley.newRequestQueue(context);
}
mRequestQueue.add(requestAnalytics);
}
if (tempDeviceInfo != null && tempDeviceInfo.length() > 0) {
String urlDeviceInfo = "";
if (mContext != null)
urlDeviceInfo = WarplyProperty.getBaseUrl(mContext) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_DEVICE_INFO + WarplyProperty.getAppUuid(mContext) + "/";
else
urlDeviceInfo = WarplyProperty.getBaseUrl(context) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_DEVICE_INFO + WarplyProperty.getAppUuid(context) + "/";
WarplyJsonArrayRequest requestDeviceInfo = new WarplyJsonArrayRequest(method, urlDeviceInfo, tempDeviceInfo, vt, vt);
requestDeviceInfo.setTag(tag);
if (mRequestQueue == null) {
if (mContext != null)
mRequestQueue = Volley.newRequestQueue(mContext);
else
mRequestQueue = Volley.newRequestQueue(context);
}
mRequestQueue.add(requestDeviceInfo);
}
if (tempOther != null && tempOther.length() > 0) {
WarplyJsonArrayRequest request = new WarplyJsonArrayRequest(method, url, tempOther, vt, vt);
request.setTag(tag);
if (mRequestQueue == null) {
if (mContext != null)
mRequestQueue = Volley.newRequestQueue(mContext);
else
mRequestQueue = Volley.newRequestQueue(context);
}
mRequestQueue.add(request);
}
}
/*========================== NEW, REPLACE WITH OLD IF NEED ==========================*/
/*========================== OLD, REVERT IF NEED ==========================*/
// WarplyJsonArrayRequest request = new WarplyJsonArrayRequest(method, url, data, vt, vt);
// request.setTag(tag);
// mRequestQueue.add(request);
/*========================== OLD, REVERT IF NEED ==========================*/
}
private void postToServerInternal(JSONObject data,
CallbackReceiver<JSONObject> listener, Object tag) {
String url = buildWarplyRequestUrl(null);
......
......@@ -283,8 +283,10 @@ public class ContextualActivity extends Activity implements View.OnClickListener
.setTitle(R.string.cos_dlg_activate_success_title)
.setMessage(R.string.cos_dlg_activate_success_subtitle)
.setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> {
dialogPositive.dismiss();
onBackPressed();
if (!isFinishing()) {
dialogPositive.dismiss();
onBackPressed();
}
})
.show();
}
......
......@@ -291,17 +291,17 @@ public class CouponInfoActivity extends Activity implements View.OnClickListener
mTvTermsValue.setText(HtmlCompat.fromHtml(mCoupon.getCouponsetDetails().getTerms(), HtmlCompat.FROM_HTML_MODE_COMPACT));
mTvTermsValue.setMovementMethod(LinkMovementMethod.getInstance());
}
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
Date newDate = new Date();
try {
newDate = simpleDateFormat.parse(mCoupon.getExpiration());
} catch (ParseException e) {
e.printStackTrace();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
Date newDate = new Date();
try {
newDate = simpleDateFormat.parse(mCoupon.getExpiration());
} catch (ParseException e) {
e.printStackTrace();
}
simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
mTvCouponDate.setText(String.format(getResources().getString(R.string.cos_mycoupon_date), simpleDateFormat.format(newDate != null ? newDate : "")));
}
simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
mTvCouponDate.setText(String.format(getResources().getString(R.string.cos_mycoupon_date), simpleDateFormat.format(newDate != null ? newDate : "")));
if (mIsUnified) {
mIvCouponPhoto.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
......
......@@ -162,21 +162,23 @@ public class CouponShareActivity extends Activity implements View.OnClickListene
// ===========================================================
private void initViews() {
mTvCouponTitle.setText(mCoupon.getCouponsetDetails().getName());
if (mCoupon != null && mCoupon.getCouponsetDetails() != null) {
mTvCouponTitle.setText(mCoupon.getCouponsetDetails().getName());
if (!TextUtils.isEmpty(mCoupon.getCouponsetDetails().getImgPreview())) {
Glide.with(this)
if (!TextUtils.isEmpty(mCoupon.getCouponsetDetails().getImgPreview())) {
Glide.with(this)
// .setDefaultRequestOptions(
// RequestOptions
// .placeholderOf(R.drawable.ic_default_contact_photo)
// .error(R.drawable.ic_default_contact_photo))
.load(mCoupon.getCouponsetDetails().getImgPreview())
.diskCacheStrategy(DiskCacheStrategy.DATA)
.into(mIvCouponPhoto);
} else {
Glide.with(this)
.load(R.drawable.ic_cosmote_logo_horizontal_grey)
.into(mIvCouponPhoto);
.load(mCoupon.getCouponsetDetails().getImgPreview())
.diskCacheStrategy(DiskCacheStrategy.DATA)
.into(mIvCouponPhoto);
} else {
Glide.with(this)
.load(R.drawable.ic_cosmote_logo_horizontal_grey)
.into(mIvCouponPhoto);
}
}
mIvBack.setOnClickListener(this);
mRlSenderView.setOnClickListener(this);
......
......@@ -137,11 +137,11 @@ public class CouponsetInfoActivity extends Activity implements View.OnClickListe
if (mCcms == null) {
WarplyManager.redeemCoupon(new WarplyRedeemCouponRequest()
.setCouponsetUuid(mCouponset != null ? mCouponset.getUuid() : "")
.setCommunicationUuid(mLoyalty.getSessionUUID()), mRedeemCouponCallback);
.setCommunicationUuid(mLoyalty != null ? mLoyalty.getSessionUUID() : ""), mRedeemCouponCallback);
} else {
WarplyManager.redeemCoupon(new WarplyRedeemCouponRequest()
.setCouponsetUuid(mCouponset != null ? mCouponset.getUuid() : "")
.setCommunicationUuid(mLoyalty.getSessionUUID())
.setCommunicationUuid(mLoyalty != null ? mLoyalty.getSessionUUID() : "")
.setHasContextualOffer(true)
.setSessionId(mCcms.getSessionId())
.setUserMsisdn(WarplyManagerHelper.getConsumer().getMsisdn()) //TODO: where to find the msisdn??
......
......@@ -563,7 +563,7 @@ public class MyRewardsFragment extends Fragment implements View.OnClickListener
}
private void createTiles() {
if (getContext() != null || (getActivity() != null && !getActivity().isFinishing())) {
if (getContext() != null) {
if (mSortTileList != null && mSortTileList.size() > 0) {
for (SortTileModel sortModel : mSortTileList) {
/** Deals Badge */
......@@ -814,7 +814,7 @@ public class MyRewardsFragment extends Fragment implements View.OnClickListener
/** Hide spinner and hide empty view and show vouchers and hide disabled vouchers */
mLlVouchersSpinner.setVisibility(View.GONE);
mLlEmptyWallet.setVisibility(View.GONE);
if (getContext() != null || (getActivity() != null && !getActivity().isFinishing())) {
if (getContext() != null) {
if (TextUtils.isEmpty(WarpUtils.getLanguage(getContext())) || WarpUtils.getLanguage(getContext()).equals("el")) {
mTvVouchersTitle.setText(getContext().getString(R.string.cos_vouchers_title));
mTvVouchersSubtitle.setText(getContext().getString(R.string.cos_vouchers_info_title));
......@@ -840,7 +840,7 @@ public class MyRewardsFragment extends Fragment implements View.OnClickListener
mLlVouchersSpinner.setVisibility(View.GONE);
mLlEmptyWallet.setVisibility(View.GONE);
mLlVouchers.setVisibility(View.GONE);
if (getContext() != null || (getActivity() != null && !getActivity().isFinishing())) {
if (getContext() != null) {
if (TextUtils.isEmpty(WarpUtils.getLanguage(getContext())) || WarpUtils.getLanguage(getContext()).equals("el")) {
mTvVouchersDisabledTitle.setText(getContext().getString(R.string.cos_vouchers_title));
mTvVouchersDisabledSubtitle.setText(getContext().getString(R.string.cos_vouchers_info_title_disabled));
......
......@@ -680,14 +680,16 @@ public class WarpView extends WebView implements DefaultLifecycleObserver {
private class WarplyWebChromeClient extends WebChromeClient {
@Override
public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(getContext().getString(R.string.lbl_cosmote_webview_permission_title));
builder.setMessage(getContext().getString(R.string.lbl_cosmote_webview_permission_message))
.setCancelable(false)
.setPositiveButton(getContext().getString(R.string.lbl_take_photo_accept), (dialog, id) -> checkForPermissions(origin, callback))
.setNegativeButton(getContext().getString(R.string.lbl_take_photo_decline), (dialog, id) -> callback.invoke(origin, false, false));
AlertDialog alert = builder.create();
alert.show();
if (WarpActivity != null && !WarpActivity.isFinishing()) {
AlertDialog.Builder builder = new AlertDialog.Builder(WarpActivity);
builder.setTitle(getContext().getString(R.string.lbl_cosmote_webview_permission_title));
builder.setMessage(getContext().getString(R.string.lbl_cosmote_webview_permission_message))
.setCancelable(false)
.setPositiveButton(getContext().getString(R.string.lbl_take_photo_accept), (dialog, id) -> checkForPermissions(origin, callback))
.setNegativeButton(getContext().getString(R.string.lbl_take_photo_decline), (dialog, id) -> callback.invoke(origin, false, false));
AlertDialog alert = builder.create();
alert.show();
}
}
@Override
......