Panagiotis Triantafyllou

crash fixes

...@@ -2,7 +2,7 @@ apply plugin: 'com.android.library' ...@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
2 2
3 ext { 3 ext {
4 PUBLISH_GROUP_ID = 'ly.warp' 4 PUBLISH_GROUP_ID = 'ly.warp'
5 - PUBLISH_VERSION = '4.5.5.4r31' 5 + PUBLISH_VERSION = '4.5.5.4r32'
6 PUBLISH_ARTIFACT_ID = 'warply-android-sdk' 6 PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
7 } 7 }
8 8
......
...@@ -1248,7 +1248,7 @@ public enum Warply { ...@@ -1248,7 +1248,7 @@ public enum Warply {
1248 url = buildWarplyRequestUrl(warplyPath); 1248 url = buildWarplyRequestUrl(warplyPath);
1249 } 1249 }
1250 1250
1251 - requestToServerInternal(Method.POST, url, data, listener, tag); 1251 + requestToServerInternal(context, Method.POST, url, data, listener, tag);
1252 } 1252 }
1253 1253
1254 private String buildWarplyRequestUrl(Context context, String warplyPath) { 1254 private String buildWarplyRequestUrl(Context context, String warplyPath) {
...@@ -1593,7 +1593,7 @@ public enum Warply { ...@@ -1593,7 +1593,7 @@ public enum Warply {
1593 String urlAnalytics = WarplyProperty.getBaseUrl(mContext) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_ANALYTICS + WarplyProperty.getAppUuid(mContext) + "/"; 1593 String urlAnalytics = WarplyProperty.getBaseUrl(mContext) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_ANALYTICS + WarplyProperty.getAppUuid(mContext) + "/";
1594 WarplyJsonArrayRequest requestAnalytics = new WarplyJsonArrayRequest(method, urlAnalytics, tempAnalytics, vt, vt); 1594 WarplyJsonArrayRequest requestAnalytics = new WarplyJsonArrayRequest(method, urlAnalytics, tempAnalytics, vt, vt);
1595 requestAnalytics.setTag(tag); 1595 requestAnalytics.setTag(tag);
1596 - if(mRequestQueue == null) 1596 + if (mRequestQueue == null)
1597 mRequestQueue = Volley.newRequestQueue(mContext); 1597 mRequestQueue = Volley.newRequestQueue(mContext);
1598 1598
1599 mRequestQueue.add(requestAnalytics); 1599 mRequestQueue.add(requestAnalytics);
...@@ -1602,7 +1602,7 @@ public enum Warply { ...@@ -1602,7 +1602,7 @@ public enum Warply {
1602 String urlDeviceInfo = WarplyProperty.getBaseUrl(mContext) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_DEVICE_INFO + WarplyProperty.getAppUuid(mContext) + "/"; 1602 String urlDeviceInfo = WarplyProperty.getBaseUrl(mContext) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_DEVICE_INFO + WarplyProperty.getAppUuid(mContext) + "/";
1603 WarplyJsonArrayRequest requestDeviceInfo = new WarplyJsonArrayRequest(method, urlDeviceInfo, tempDeviceInfo, vt, vt); 1603 WarplyJsonArrayRequest requestDeviceInfo = new WarplyJsonArrayRequest(method, urlDeviceInfo, tempDeviceInfo, vt, vt);
1604 requestDeviceInfo.setTag(tag); 1604 requestDeviceInfo.setTag(tag);
1605 - if(mRequestQueue == null) 1605 + if (mRequestQueue == null)
1606 mRequestQueue = Volley.newRequestQueue(mContext); 1606 mRequestQueue = Volley.newRequestQueue(mContext);
1607 1607
1608 mRequestQueue.add(requestDeviceInfo); 1608 mRequestQueue.add(requestDeviceInfo);
...@@ -1610,7 +1610,7 @@ public enum Warply { ...@@ -1610,7 +1610,7 @@ public enum Warply {
1610 if (tempOther != null && tempOther.length() > 0) { 1610 if (tempOther != null && tempOther.length() > 0) {
1611 WarplyJsonArrayRequest request = new WarplyJsonArrayRequest(method, url, tempOther, vt, vt); 1611 WarplyJsonArrayRequest request = new WarplyJsonArrayRequest(method, url, tempOther, vt, vt);
1612 request.setTag(tag); 1612 request.setTag(tag);
1613 - if(mRequestQueue == null) 1613 + if (mRequestQueue == null)
1614 mRequestQueue = Volley.newRequestQueue(mContext); 1614 mRequestQueue = Volley.newRequestQueue(mContext);
1615 1615
1616 mRequestQueue.add(request); 1616 mRequestQueue.add(request);
...@@ -1625,6 +1625,137 @@ public enum Warply { ...@@ -1625,6 +1625,137 @@ public enum Warply {
1625 /*========================== OLD, REVERT IF NEED ==========================*/ 1625 /*========================== OLD, REVERT IF NEED ==========================*/
1626 } 1626 }
1627 1627
1628 + private void requestToServerInternal(Context context, int method, String url, JSONArray data,
1629 + CallbackReceiver<JSONObject> listener, Object tag) {
1630 +
1631 + VolleyTransformer vt = new VolleyTransformer(listener);
1632 + String methodName = null;
1633 + switch (method) {
1634 + case 0:
1635 + methodName = "GET";
1636 + break;
1637 + case 1:
1638 + methodName = "POST";
1639 + break;
1640 + case 2:
1641 + methodName = "PUT";
1642 + break;
1643 + case 3:
1644 + methodName = "DELETE";
1645 + break;
1646 + }
1647 +
1648 + if (mContext != null) {
1649 + WarpUtils.log("************* WARPLY " + methodName + " Context ********************");
1650 + WarpUtils.log("[WARP Trace] HTTP Web Id: " + WarpUtils.getWebId(mContext));
1651 + WarpUtils.log("[WARP Trace] HTTP API Key: " + WarplyProperty.getAppUuid(mContext));
1652 + WarpUtils.verbose("[WARP Trace] HTTP " + methodName + " Request URL: " + url);
1653 + if (data != null) {
1654 + try {
1655 + WarpUtils.verbose("[WARP Trace] Request: " + data.toString(2));
1656 + } catch (JSONException e) {
1657 + WarpUtils.warn(
1658 + "[WARP Trace] Failed conversting JSON to string", e);
1659 + }
1660 + }
1661 + } else if (context != null) {
1662 + WarpUtils.log("************* WARPLY " + methodName + " Context ********************");
1663 + WarpUtils.log("[WARP Trace] HTTP Web Id: " + WarpUtils.getWebId(context));
1664 + WarpUtils.log("[WARP Trace] HTTP API Key: " + WarplyProperty.getAppUuid(context));
1665 + WarpUtils.verbose("[WARP Trace] HTTP " + methodName + " Request URL: " + url);
1666 + if (data != null) {
1667 + try {
1668 + WarpUtils.verbose("[WARP Trace] Request: " + data.toString(2));
1669 + } catch (JSONException e) {
1670 + WarpUtils.warn(
1671 + "[WARP Trace] Failed conversting JSON to string", e);
1672 + }
1673 + }
1674 + }
1675 +
1676 + /*========================== NEW, REPLACE WITH OLD IF NEED ==========================*/
1677 + if (data != null) {
1678 + JSONArray tempAnalytics = new JSONArray();
1679 + JSONArray tempDeviceInfo = new JSONArray();
1680 + JSONArray tempOther = new JSONArray();
1681 + if (data.length() > 0) {
1682 + for (int i = 0; i < data.length(); i++) {
1683 + JSONObject microappItem = data.optJSONObject(i);
1684 + if (microappItem != null) {
1685 + if (microappItem.has("inapp_analytics")) {
1686 + tempAnalytics.put(microappItem);
1687 + } else if (microappItem.has("device_info") || microappItem.has("application_data")) {
1688 + tempDeviceInfo.put(microappItem);
1689 + } else {
1690 + tempOther.put(microappItem);
1691 + }
1692 + }
1693 + }
1694 + }
1695 +
1696 + if (INSTANCE.mRequestQueue == null) {
1697 + if (INSTANCE.mContext != null)
1698 + INSTANCE.mRequestQueue = Volley.newRequestQueue(INSTANCE.mContext);
1699 + else
1700 + INSTANCE.mRequestQueue = Volley.newRequestQueue(context);
1701 + }
1702 +
1703 + if (tempAnalytics != null && tempAnalytics.length() > 0) {
1704 + String urlAnalytics = "";
1705 + if (mContext != null)
1706 + urlAnalytics = WarplyProperty.getBaseUrl(mContext) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_ANALYTICS + WarplyProperty.getAppUuid(mContext) + "/";
1707 + else
1708 + urlAnalytics = WarplyProperty.getBaseUrl(context) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_ANALYTICS + WarplyProperty.getAppUuid(context) + "/";
1709 + WarplyJsonArrayRequest requestAnalytics = new WarplyJsonArrayRequest(method, urlAnalytics, tempAnalytics, vt, vt);
1710 + requestAnalytics.setTag(tag);
1711 + if (mRequestQueue == null) {
1712 + if (mContext != null)
1713 + mRequestQueue = Volley.newRequestQueue(mContext);
1714 + else
1715 + mRequestQueue = Volley.newRequestQueue(context);
1716 + }
1717 +
1718 + mRequestQueue.add(requestAnalytics);
1719 + }
1720 + if (tempDeviceInfo != null && tempDeviceInfo.length() > 0) {
1721 + String urlDeviceInfo = "";
1722 + if (mContext != null)
1723 + urlDeviceInfo = WarplyProperty.getBaseUrl(mContext) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_DEVICE_INFO + WarplyProperty.getAppUuid(mContext) + "/";
1724 + else
1725 + urlDeviceInfo = WarplyProperty.getBaseUrl(context) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_DEVICE_INFO + WarplyProperty.getAppUuid(context) + "/";
1726 + WarplyJsonArrayRequest requestDeviceInfo = new WarplyJsonArrayRequest(method, urlDeviceInfo, tempDeviceInfo, vt, vt);
1727 + requestDeviceInfo.setTag(tag);
1728 + if (mRequestQueue == null) {
1729 + if (mContext != null)
1730 + mRequestQueue = Volley.newRequestQueue(mContext);
1731 + else
1732 + mRequestQueue = Volley.newRequestQueue(context);
1733 + }
1734 +
1735 + mRequestQueue.add(requestDeviceInfo);
1736 + }
1737 + if (tempOther != null && tempOther.length() > 0) {
1738 + WarplyJsonArrayRequest request = new WarplyJsonArrayRequest(method, url, tempOther, vt, vt);
1739 + request.setTag(tag);
1740 + if (mRequestQueue == null) {
1741 + if (mContext != null)
1742 + mRequestQueue = Volley.newRequestQueue(mContext);
1743 + else
1744 + mRequestQueue = Volley.newRequestQueue(context);
1745 + }
1746 +
1747 + mRequestQueue.add(request);
1748 + }
1749 + }
1750 + /*========================== NEW, REPLACE WITH OLD IF NEED ==========================*/
1751 +
1752 + /*========================== OLD, REVERT IF NEED ==========================*/
1753 +// WarplyJsonArrayRequest request = new WarplyJsonArrayRequest(method, url, data, vt, vt);
1754 +// request.setTag(tag);
1755 +// mRequestQueue.add(request);
1756 + /*========================== OLD, REVERT IF NEED ==========================*/
1757 + }
1758 +
1628 private void postToServerInternal(JSONObject data, 1759 private void postToServerInternal(JSONObject data,
1629 CallbackReceiver<JSONObject> listener, Object tag) { 1760 CallbackReceiver<JSONObject> listener, Object tag) {
1630 String url = buildWarplyRequestUrl(null); 1761 String url = buildWarplyRequestUrl(null);
......
...@@ -283,8 +283,10 @@ public class ContextualActivity extends Activity implements View.OnClickListener ...@@ -283,8 +283,10 @@ public class ContextualActivity extends Activity implements View.OnClickListener
283 .setTitle(R.string.cos_dlg_activate_success_title) 283 .setTitle(R.string.cos_dlg_activate_success_title)
284 .setMessage(R.string.cos_dlg_activate_success_subtitle) 284 .setMessage(R.string.cos_dlg_activate_success_subtitle)
285 .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> { 285 .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> {
286 + if (!isFinishing()) {
286 dialogPositive.dismiss(); 287 dialogPositive.dismiss();
287 onBackPressed(); 288 onBackPressed();
289 + }
288 }) 290 })
289 .show(); 291 .show();
290 } 292 }
......
...@@ -291,7 +291,6 @@ public class CouponInfoActivity extends Activity implements View.OnClickListener ...@@ -291,7 +291,6 @@ public class CouponInfoActivity extends Activity implements View.OnClickListener
291 mTvTermsValue.setText(HtmlCompat.fromHtml(mCoupon.getCouponsetDetails().getTerms(), HtmlCompat.FROM_HTML_MODE_COMPACT)); 291 mTvTermsValue.setText(HtmlCompat.fromHtml(mCoupon.getCouponsetDetails().getTerms(), HtmlCompat.FROM_HTML_MODE_COMPACT));
292 mTvTermsValue.setMovementMethod(LinkMovementMethod.getInstance()); 292 mTvTermsValue.setMovementMethod(LinkMovementMethod.getInstance());
293 } 293 }
294 - }
295 294
296 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm"); 295 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
297 Date newDate = new Date(); 296 Date newDate = new Date();
...@@ -302,6 +301,7 @@ public class CouponInfoActivity extends Activity implements View.OnClickListener ...@@ -302,6 +301,7 @@ public class CouponInfoActivity extends Activity implements View.OnClickListener
302 } 301 }
303 simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); 302 simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
304 mTvCouponDate.setText(String.format(getResources().getString(R.string.cos_mycoupon_date), simpleDateFormat.format(newDate != null ? newDate : ""))); 303 mTvCouponDate.setText(String.format(getResources().getString(R.string.cos_mycoupon_date), simpleDateFormat.format(newDate != null ? newDate : "")));
304 + }
305 305
306 if (mIsUnified) { 306 if (mIsUnified) {
307 mIvCouponPhoto.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 307 mIvCouponPhoto.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
......
...@@ -162,6 +162,7 @@ public class CouponShareActivity extends Activity implements View.OnClickListene ...@@ -162,6 +162,7 @@ public class CouponShareActivity extends Activity implements View.OnClickListene
162 // =========================================================== 162 // ===========================================================
163 163
164 private void initViews() { 164 private void initViews() {
165 + if (mCoupon != null && mCoupon.getCouponsetDetails() != null) {
165 mTvCouponTitle.setText(mCoupon.getCouponsetDetails().getName()); 166 mTvCouponTitle.setText(mCoupon.getCouponsetDetails().getName());
166 167
167 if (!TextUtils.isEmpty(mCoupon.getCouponsetDetails().getImgPreview())) { 168 if (!TextUtils.isEmpty(mCoupon.getCouponsetDetails().getImgPreview())) {
...@@ -178,6 +179,7 @@ public class CouponShareActivity extends Activity implements View.OnClickListene ...@@ -178,6 +179,7 @@ public class CouponShareActivity extends Activity implements View.OnClickListene
178 .load(R.drawable.ic_cosmote_logo_horizontal_grey) 179 .load(R.drawable.ic_cosmote_logo_horizontal_grey)
179 .into(mIvCouponPhoto); 180 .into(mIvCouponPhoto);
180 } 181 }
182 + }
181 mIvBack.setOnClickListener(this); 183 mIvBack.setOnClickListener(this);
182 mRlSenderView.setOnClickListener(this); 184 mRlSenderView.setOnClickListener(this);
183 mLlShareButton.setOnClickListener(this); 185 mLlShareButton.setOnClickListener(this);
......
...@@ -137,11 +137,11 @@ public class CouponsetInfoActivity extends Activity implements View.OnClickListe ...@@ -137,11 +137,11 @@ public class CouponsetInfoActivity extends Activity implements View.OnClickListe
137 if (mCcms == null) { 137 if (mCcms == null) {
138 WarplyManager.redeemCoupon(new WarplyRedeemCouponRequest() 138 WarplyManager.redeemCoupon(new WarplyRedeemCouponRequest()
139 .setCouponsetUuid(mCouponset != null ? mCouponset.getUuid() : "") 139 .setCouponsetUuid(mCouponset != null ? mCouponset.getUuid() : "")
140 - .setCommunicationUuid(mLoyalty.getSessionUUID()), mRedeemCouponCallback); 140 + .setCommunicationUuid(mLoyalty != null ? mLoyalty.getSessionUUID() : ""), mRedeemCouponCallback);
141 } else { 141 } else {
142 WarplyManager.redeemCoupon(new WarplyRedeemCouponRequest() 142 WarplyManager.redeemCoupon(new WarplyRedeemCouponRequest()
143 .setCouponsetUuid(mCouponset != null ? mCouponset.getUuid() : "") 143 .setCouponsetUuid(mCouponset != null ? mCouponset.getUuid() : "")
144 - .setCommunicationUuid(mLoyalty.getSessionUUID()) 144 + .setCommunicationUuid(mLoyalty != null ? mLoyalty.getSessionUUID() : "")
145 .setHasContextualOffer(true) 145 .setHasContextualOffer(true)
146 .setSessionId(mCcms.getSessionId()) 146 .setSessionId(mCcms.getSessionId())
147 .setUserMsisdn(WarplyManagerHelper.getConsumer().getMsisdn()) //TODO: where to find the msisdn?? 147 .setUserMsisdn(WarplyManagerHelper.getConsumer().getMsisdn()) //TODO: where to find the msisdn??
......
...@@ -563,7 +563,7 @@ public class MyRewardsFragment extends Fragment implements View.OnClickListener ...@@ -563,7 +563,7 @@ public class MyRewardsFragment extends Fragment implements View.OnClickListener
563 } 563 }
564 564
565 private void createTiles() { 565 private void createTiles() {
566 - if (getContext() != null || (getActivity() != null && !getActivity().isFinishing())) { 566 + if (getContext() != null) {
567 if (mSortTileList != null && mSortTileList.size() > 0) { 567 if (mSortTileList != null && mSortTileList.size() > 0) {
568 for (SortTileModel sortModel : mSortTileList) { 568 for (SortTileModel sortModel : mSortTileList) {
569 /** Deals Badge */ 569 /** Deals Badge */
...@@ -814,7 +814,7 @@ public class MyRewardsFragment extends Fragment implements View.OnClickListener ...@@ -814,7 +814,7 @@ public class MyRewardsFragment extends Fragment implements View.OnClickListener
814 /** Hide spinner and hide empty view and show vouchers and hide disabled vouchers */ 814 /** Hide spinner and hide empty view and show vouchers and hide disabled vouchers */
815 mLlVouchersSpinner.setVisibility(View.GONE); 815 mLlVouchersSpinner.setVisibility(View.GONE);
816 mLlEmptyWallet.setVisibility(View.GONE); 816 mLlEmptyWallet.setVisibility(View.GONE);
817 - if (getContext() != null || (getActivity() != null && !getActivity().isFinishing())) { 817 + if (getContext() != null) {
818 if (TextUtils.isEmpty(WarpUtils.getLanguage(getContext())) || WarpUtils.getLanguage(getContext()).equals("el")) { 818 if (TextUtils.isEmpty(WarpUtils.getLanguage(getContext())) || WarpUtils.getLanguage(getContext()).equals("el")) {
819 mTvVouchersTitle.setText(getContext().getString(R.string.cos_vouchers_title)); 819 mTvVouchersTitle.setText(getContext().getString(R.string.cos_vouchers_title));
820 mTvVouchersSubtitle.setText(getContext().getString(R.string.cos_vouchers_info_title)); 820 mTvVouchersSubtitle.setText(getContext().getString(R.string.cos_vouchers_info_title));
...@@ -840,7 +840,7 @@ public class MyRewardsFragment extends Fragment implements View.OnClickListener ...@@ -840,7 +840,7 @@ public class MyRewardsFragment extends Fragment implements View.OnClickListener
840 mLlVouchersSpinner.setVisibility(View.GONE); 840 mLlVouchersSpinner.setVisibility(View.GONE);
841 mLlEmptyWallet.setVisibility(View.GONE); 841 mLlEmptyWallet.setVisibility(View.GONE);
842 mLlVouchers.setVisibility(View.GONE); 842 mLlVouchers.setVisibility(View.GONE);
843 - if (getContext() != null || (getActivity() != null && !getActivity().isFinishing())) { 843 + if (getContext() != null) {
844 if (TextUtils.isEmpty(WarpUtils.getLanguage(getContext())) || WarpUtils.getLanguage(getContext()).equals("el")) { 844 if (TextUtils.isEmpty(WarpUtils.getLanguage(getContext())) || WarpUtils.getLanguage(getContext()).equals("el")) {
845 mTvVouchersDisabledTitle.setText(getContext().getString(R.string.cos_vouchers_title)); 845 mTvVouchersDisabledTitle.setText(getContext().getString(R.string.cos_vouchers_title));
846 mTvVouchersDisabledSubtitle.setText(getContext().getString(R.string.cos_vouchers_info_title_disabled)); 846 mTvVouchersDisabledSubtitle.setText(getContext().getString(R.string.cos_vouchers_info_title_disabled));
......
...@@ -680,7 +680,8 @@ public class WarpView extends WebView implements DefaultLifecycleObserver { ...@@ -680,7 +680,8 @@ public class WarpView extends WebView implements DefaultLifecycleObserver {
680 private class WarplyWebChromeClient extends WebChromeClient { 680 private class WarplyWebChromeClient extends WebChromeClient {
681 @Override 681 @Override
682 public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) { 682 public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
683 - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); 683 + if (WarpActivity != null && !WarpActivity.isFinishing()) {
684 + AlertDialog.Builder builder = new AlertDialog.Builder(WarpActivity);
684 builder.setTitle(getContext().getString(R.string.lbl_cosmote_webview_permission_title)); 685 builder.setTitle(getContext().getString(R.string.lbl_cosmote_webview_permission_title));
685 builder.setMessage(getContext().getString(R.string.lbl_cosmote_webview_permission_message)) 686 builder.setMessage(getContext().getString(R.string.lbl_cosmote_webview_permission_message))
686 .setCancelable(false) 687 .setCancelable(false)
...@@ -689,6 +690,7 @@ public class WarpView extends WebView implements DefaultLifecycleObserver { ...@@ -689,6 +690,7 @@ public class WarpView extends WebView implements DefaultLifecycleObserver {
689 AlertDialog alert = builder.create(); 690 AlertDialog alert = builder.create();
690 alert.show(); 691 alert.show();
691 } 692 }
693 + }
692 694
693 @Override 695 @Override
694 public void onProgressChanged(WebView view, int newProgress) { 696 public void onProgressChanged(WebView view, int newProgress) {
......