Showing
7 changed files
with
665 additions
and
133 deletions
| ... | @@ -3,6 +3,8 @@ package ly.warp.sdk.activities; | ... | @@ -3,6 +3,8 @@ package ly.warp.sdk.activities; |
| 3 | import android.app.Activity; | 3 | import android.app.Activity; |
| 4 | import android.content.Intent; | 4 | import android.content.Intent; |
| 5 | import android.os.Bundle; | 5 | import android.os.Bundle; |
| 6 | +import android.text.TextUtils; | ||
| 7 | +import android.util.Log; | ||
| 6 | import android.view.View; | 8 | import android.view.View; |
| 7 | import android.widget.ImageView; | 9 | import android.widget.ImageView; |
| 8 | import android.widget.LinearLayout; | 10 | import android.widget.LinearLayout; |
| ... | @@ -26,7 +28,9 @@ import ly.warp.sdk.io.models.Couponset; | ... | @@ -26,7 +28,9 @@ import ly.warp.sdk.io.models.Couponset; |
| 26 | import ly.warp.sdk.io.models.CouponsetsList; | 28 | import ly.warp.sdk.io.models.CouponsetsList; |
| 27 | import ly.warp.sdk.io.models.LoyaltyContextualOfferModel; | 29 | import ly.warp.sdk.io.models.LoyaltyContextualOfferModel; |
| 28 | import ly.warp.sdk.io.models.LoyaltyGiftsForYouOfferClickEvent; | 30 | import ly.warp.sdk.io.models.LoyaltyGiftsForYouOfferClickEvent; |
| 31 | +import ly.warp.sdk.io.models.LoyaltyGiftsForYouPackage; | ||
| 29 | import ly.warp.sdk.io.models.MergedGifts; | 32 | import ly.warp.sdk.io.models.MergedGifts; |
| 33 | +import ly.warp.sdk.utils.WarpJSONParser; | ||
| 30 | import ly.warp.sdk.utils.WarpUtils; | 34 | import ly.warp.sdk.utils.WarpUtils; |
| 31 | import ly.warp.sdk.utils.WarplyManagerHelper; | 35 | import ly.warp.sdk.utils.WarplyManagerHelper; |
| 32 | import ly.warp.sdk.utils.managers.WarplyEventBusManager; | 36 | import ly.warp.sdk.utils.managers.WarplyEventBusManager; |
| ... | @@ -45,13 +49,7 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene | ... | @@ -45,13 +49,7 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene |
| 45 | 49 | ||
| 46 | private ImageView mIvBack, mIvPopupClose; | 50 | private ImageView mIvBack, mIvPopupClose; |
| 47 | private TextView mTvTitle; | 51 | private TextView mTvTitle; |
| 48 | - /**** Old functionality ****/ | ||
| 49 | -// private RecyclerView mRecyclerGifts, mRecyclerRewards, mRecyclerCoupons; | ||
| 50 | -// private ProfileCampaignAdapter mAdapterGifts, mAdapterRewards; | ||
| 51 | -// private CouponsetsAdapter mAdapterCoupons; | ||
| 52 | -// private ConstraintLayout mClGiftsOuter, mClRewardsOuter, mClCouponsOuter; | ||
| 53 | private HashMap<String, CampaignList> mUniqueGiftsList = new HashMap<String, CampaignList>(); | 52 | private HashMap<String, CampaignList> mUniqueGiftsList = new HashMap<String, CampaignList>(); |
| 54 | - /**** Old functionality ****/ | ||
| 55 | private LinearLayout mLlGiftsPopup; | 53 | private LinearLayout mLlGiftsPopup; |
| 56 | private ArrayList<MergedGifts> mData = new ArrayList(); | 54 | private ArrayList<MergedGifts> mData = new ArrayList(); |
| 57 | private RecyclerView mRecyclerMergedGifts; | 55 | private RecyclerView mRecyclerMergedGifts; |
| ... | @@ -64,10 +62,7 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene | ... | @@ -64,10 +62,7 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene |
| 64 | public void onCreate(Bundle savedInstanceState) { | 62 | public void onCreate(Bundle savedInstanceState) { |
| 65 | super.onCreate(savedInstanceState); | 63 | super.onCreate(savedInstanceState); |
| 66 | setContentView(R.layout.activity_gifts_for_you); | 64 | setContentView(R.layout.activity_gifts_for_you); |
| 67 | - | 65 | + ArrayList<LoyaltyGiftsForYouPackage> list = new ArrayList(); |
| 68 | - /**** Old functionality ****/ | ||
| 69 | -// getCampaignsBySubcategory(); | ||
| 70 | - /**** Old functionality ****/ | ||
| 71 | mergeDatasets( | 66 | mergeDatasets( |
| 72 | WarplyManagerHelper.getUniqueCampaignList().get("gifts_for_you"), | 67 | WarplyManagerHelper.getUniqueCampaignList().get("gifts_for_you"), |
| 73 | WarplyManagerHelper.getCouponsets() | 68 | WarplyManagerHelper.getCouponsets() |
| ... | @@ -78,17 +73,6 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene | ... | @@ -78,17 +73,6 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene |
| 78 | mIvPopupClose = findViewById(R.id.iv_popup_gifts_close); | 73 | mIvPopupClose = findViewById(R.id.iv_popup_gifts_close); |
| 79 | mLlGiftsPopup = findViewById(R.id.ll_gifts_popup); | 74 | mLlGiftsPopup = findViewById(R.id.ll_gifts_popup); |
| 80 | 75 | ||
| 81 | - /**** Old functionality ****/ | ||
| 82 | -// mClGiftsOuter = findViewById(R.id.cl_recycler_inner); | ||
| 83 | -// mRecyclerGifts = findViewById(R.id.rv_gifts); | ||
| 84 | - | ||
| 85 | -// mClRewardsOuter = findViewById(R.id.cl_recycler_inner2); | ||
| 86 | -// mRecyclerRewards = findViewById(R.id.rv_rewards); | ||
| 87 | - | ||
| 88 | -// mClCouponsOuter = findViewById(R.id.cl_recycler_inner3); | ||
| 89 | -// mRecyclerCoupons = findViewById(R.id.rv_coupons); | ||
| 90 | - /**** Old functionality ****/ | ||
| 91 | - | ||
| 92 | mRecyclerMergedGifts = findViewById(R.id.rv_merged_gifts); | 76 | mRecyclerMergedGifts = findViewById(R.id.rv_merged_gifts); |
| 93 | 77 | ||
| 94 | initViews(); | 78 | initViews(); |
| ... | @@ -123,55 +107,6 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene | ... | @@ -123,55 +107,6 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene |
| 123 | if (WarpUtils.getGiftsPopup(this)) | 107 | if (WarpUtils.getGiftsPopup(this)) |
| 124 | mLlGiftsPopup.setVisibility(View.VISIBLE); | 108 | mLlGiftsPopup.setVisibility(View.VISIBLE); |
| 125 | 109 | ||
| 126 | - /**** Old functionality ****/ | ||
| 127 | -// if (mUniqueGiftsList.get("gifts") != null && mUniqueGiftsList.get("gifts").size() > 0) { | ||
| 128 | -// mRecyclerGifts.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)); | ||
| 129 | -// mAdapterGifts = new ProfileCampaignAdapter(this, mUniqueGiftsList.get("gifts")); | ||
| 130 | -// mRecyclerGifts.setAdapter(mAdapterGifts); | ||
| 131 | -// mAdapterGifts.getPositionClicks() | ||
| 132 | -// .doOnNext(gift -> { | ||
| 133 | -// startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(gift))); | ||
| 134 | -// }) | ||
| 135 | -// .doOnError(error -> { | ||
| 136 | -// }) | ||
| 137 | -// .subscribe(); | ||
| 138 | -// } else { | ||
| 139 | -// mClGiftsOuter.setVisibility(View.GONE); | ||
| 140 | -// } | ||
| 141 | - | ||
| 142 | -// if (mUniqueGiftsList.get("rewards") != null && mUniqueGiftsList.get("rewards").size() > 0) { | ||
| 143 | -// mRecyclerRewards.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)); | ||
| 144 | -// mAdapterRewards = new ProfileCampaignAdapter(this, mUniqueGiftsList.get("rewards")); | ||
| 145 | -// mRecyclerRewards.setAdapter(mAdapterRewards); | ||
| 146 | -// mAdapterRewards.getPositionClicks() | ||
| 147 | -// .doOnNext(reward -> { | ||
| 148 | -// startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(reward))); | ||
| 149 | -// }) | ||
| 150 | -// .doOnError(error -> { | ||
| 151 | -// }) | ||
| 152 | -// .subscribe(); | ||
| 153 | -// } else { | ||
| 154 | -// mClRewardsOuter.setVisibility(View.GONE); | ||
| 155 | -// } | ||
| 156 | - | ||
| 157 | -// if (WarplyManagerHelper.getCouponsets() != null && WarplyManagerHelper.getCouponsets().size() > 0) { | ||
| 158 | -// mRecyclerCoupons.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)); | ||
| 159 | -// mAdapterCoupons = new CouponsetsAdapter(this, WarplyManagerHelper.getCouponsets()); | ||
| 160 | -// mRecyclerCoupons.setAdapter(mAdapterCoupons); | ||
| 161 | -// mAdapterCoupons.getPositionClicks() | ||
| 162 | -// .doOnNext(couponset -> { | ||
| 163 | -// Intent intent = new Intent(GiftsForYouActivity.this, CouponsetInfoActivity.class); | ||
| 164 | -// intent.putExtra("couponset", (Serializable) couponset); | ||
| 165 | -// startActivity(intent); | ||
| 166 | -// }) | ||
| 167 | -// .doOnError(error -> { | ||
| 168 | -// }) | ||
| 169 | -// .subscribe(); | ||
| 170 | -// } else { | ||
| 171 | -// mClCouponsOuter.setVisibility(View.GONE); | ||
| 172 | -// } | ||
| 173 | - /**** Old functionality ****/ | ||
| 174 | - | ||
| 175 | if (mData != null && mData.size() > 0) { | 110 | if (mData != null && mData.size() > 0) { |
| 176 | mRecyclerMergedGifts.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); | 111 | mRecyclerMergedGifts.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); |
| 177 | mAdapterMergedGifts = new MergedGiftsAdapter(this, mData); | 112 | mAdapterMergedGifts = new MergedGiftsAdapter(this, mData); |
| ... | @@ -181,7 +116,21 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene | ... | @@ -181,7 +116,21 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene |
| 181 | if (dataItem.getDataType() == 1) { | 116 | if (dataItem.getDataType() == 1) { |
| 182 | EventBus.getDefault().post(new WarplyEventBusManager(new LoyaltyGiftsForYouOfferClickEvent())); | 117 | EventBus.getDefault().post(new WarplyEventBusManager(new LoyaltyGiftsForYouOfferClickEvent())); |
| 183 | 118 | ||
| 184 | - startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(dataItem.getCampaign()))); | 119 | + try { |
| 120 | + String key = WarpJSONParser.getJSONFromString(dataItem.getCampaign().getExtraFields()).keys().next(); | ||
| 121 | + if (!TextUtils.isEmpty(key) && key.equals("loyaltyCampaignId")) { | ||
| 122 | + String value = WarpJSONParser.getJSONFromString(dataItem.getCampaign().getExtraFields()).optString("loyaltyCampaignId"); | ||
| 123 | + for (LoyaltyContextualOfferModel ccms : WarplyManagerHelper.getCCMSLoyaltyCampaigns()) { | ||
| 124 | + if (ccms.getLoyaltyCampaignId().equals(value)) { | ||
| 125 | + startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCcmsUrl(dataItem.getCampaign(), ccms.getSessionId()))); | ||
| 126 | + return; | ||
| 127 | + } | ||
| 128 | + } | ||
| 129 | + } | ||
| 130 | + startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(dataItem.getCampaign()))); | ||
| 131 | + } catch (Exception exception) { | ||
| 132 | + startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(dataItem.getCampaign()))); | ||
| 133 | + } | ||
| 185 | } else if (dataItem.getDataType() == 2) { | 134 | } else if (dataItem.getDataType() == 2) { |
| 186 | EventBus.getDefault().post(new WarplyEventBusManager(new LoyaltyContextualOfferModel())); | 135 | EventBus.getDefault().post(new WarplyEventBusManager(new LoyaltyContextualOfferModel())); |
| 187 | 136 | ||
| ... | @@ -193,33 +142,6 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene | ... | @@ -193,33 +142,6 @@ public class GiftsForYouActivity extends Activity implements View.OnClickListene |
| 193 | .doOnError(error -> { | 142 | .doOnError(error -> { |
| 194 | }) | 143 | }) |
| 195 | .subscribe(); | 144 | .subscribe(); |
| 196 | - } else { | ||
| 197 | -// mClCouponsOuter.setVisibility(View.GONE); | ||
| 198 | - } | ||
| 199 | - } | ||
| 200 | - | ||
| 201 | - private void getCampaignsBySubcategory() { | ||
| 202 | - if (WarplyManagerHelper.getUniqueCampaignList().get("gifts_for_you") != null && WarplyManagerHelper.getUniqueCampaignList().get("gifts_for_you").size() > 0) { | ||
| 203 | - for (Campaign campaign : WarplyManagerHelper.getUniqueCampaignList().get("gifts_for_you")) { | ||
| 204 | - JSONObject campaignExtra = null; | ||
| 205 | - try { | ||
| 206 | - campaignExtra = new JSONObject(campaign.getExtraFields()); | ||
| 207 | - } catch (JSONException e) { | ||
| 208 | - e.printStackTrace(); | ||
| 209 | - } | ||
| 210 | - | ||
| 211 | - if (campaignExtra != null) { | ||
| 212 | - if (mUniqueGiftsList.containsKey(campaignExtra.optString("subcategory").trim())) { | ||
| 213 | - CampaignList tempCampaignList = mUniqueGiftsList.get(campaignExtra.optString("subcategory").trim()); | ||
| 214 | - tempCampaignList.add(campaign); | ||
| 215 | - mUniqueGiftsList.put(campaignExtra.optString("subcategory").trim(), tempCampaignList); | ||
| 216 | - } else { | ||
| 217 | - CampaignList tempCampaignList = new CampaignList(); | ||
| 218 | - tempCampaignList.add(campaign); | ||
| 219 | - mUniqueGiftsList.put(campaignExtra.optString("subcategory").trim(), tempCampaignList); | ||
| 220 | - } | ||
| 221 | - } | ||
| 222 | - } | ||
| 223 | } | 145 | } |
| 224 | } | 146 | } |
| 225 | 147 | ... | ... |
warply_android_sdk/src/main/java/ly/warp/sdk/io/request/CosmoteRetrieveSharingRequest.java
0 → 100644
| 1 | +package ly.warp.sdk.io.request; | ||
| 2 | + | ||
| 3 | +import android.util.Base64; | ||
| 4 | + | ||
| 5 | +import org.json.JSONException; | ||
| 6 | +import org.json.JSONObject; | ||
| 7 | + | ||
| 8 | +import java.io.UnsupportedEncodingException; | ||
| 9 | +import java.security.MessageDigest; | ||
| 10 | +import java.security.NoSuchAlgorithmException; | ||
| 11 | +import java.util.HashMap; | ||
| 12 | + | ||
| 13 | +import ly.warp.sdk.utils.constants.WarpConstants; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * Created by Panagiotis Triantafyllou on 23-June-22. | ||
| 17 | + */ | ||
| 18 | + | ||
| 19 | +public class CosmoteRetrieveSharingRequest { | ||
| 20 | + | ||
| 21 | + // =========================================================== | ||
| 22 | + // Constants | ||
| 23 | + // =========================================================== | ||
| 24 | + | ||
| 25 | + private final String KEY_MAPP = "wallet"; | ||
| 26 | + private final String KEY_ACTION = "action"; | ||
| 27 | + private final String KEY_ACTION_VALUE = "sharing_response"; | ||
| 28 | + private final String KEY_SHARING_ID_KEY = "sharing_id"; | ||
| 29 | + private final String KEY_ACCEPT_KEY = "accept"; | ||
| 30 | + | ||
| 31 | + // =========================================================== | ||
| 32 | + // Fields | ||
| 33 | + // =========================================================== | ||
| 34 | + | ||
| 35 | + private HashMap<String, String> mFilters; | ||
| 36 | + private long mCacheUpdateInterval = 0; | ||
| 37 | + private String mSharingId = ""; | ||
| 38 | + private boolean mIsAccept = false; | ||
| 39 | + | ||
| 40 | + // =========================================================== | ||
| 41 | + // Constructor | ||
| 42 | + // =========================================================== | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * Default constructor of CosmoteRetrieveSharingRequest, initializes an empty filters HashMap | ||
| 46 | + */ | ||
| 47 | + public CosmoteRetrieveSharingRequest() { | ||
| 48 | + mFilters = new HashMap<>(); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public CosmoteRetrieveSharingRequest(CosmoteRetrieveSharingRequest copy) { | ||
| 52 | + if (copy != null) { | ||
| 53 | + this.mFilters = copy.mFilters; | ||
| 54 | + this.mCacheUpdateInterval = copy.mCacheUpdateInterval; | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + // =========================================================== | ||
| 59 | + // Methods for/from SuperClass/Interfaces | ||
| 60 | + // =========================================================== | ||
| 61 | + | ||
| 62 | + @Override | ||
| 63 | + public boolean equals(Object object) { | ||
| 64 | + if (object instanceof CosmoteRetrieveSharingRequest) { | ||
| 65 | + CosmoteRetrieveSharingRequest other = (CosmoteRetrieveSharingRequest) object; | ||
| 66 | + return other == this || (this.mFilters == other.mFilters || (this.mFilters != null && this.mFilters.equals(other.mFilters))); | ||
| 67 | + } | ||
| 68 | + return false; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public int hashCode() { | ||
| 73 | + return mFilters.hashCode(); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + // =========================================================== | ||
| 77 | + // Methods | ||
| 78 | + // =========================================================== | ||
| 79 | + | ||
| 80 | + // =========================================================== | ||
| 81 | + // Getter & Setter | ||
| 82 | + // =========================================================== | ||
| 83 | + | ||
| 84 | + public CosmoteRetrieveSharingRequest setSharingId(String sharingId) { | ||
| 85 | + mSharingId = sharingId; | ||
| 86 | + return this; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + public CosmoteRetrieveSharingRequest setAccept(boolean acceptGift) { | ||
| 90 | + mIsAccept = acceptGift; | ||
| 91 | + return this; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * Call this to get how often the cached data will be updated. | ||
| 96 | + * | ||
| 97 | + * @return mCacheUpdateInterval | ||
| 98 | + */ | ||
| 99 | + public long getCacheUpdateInterval() { | ||
| 100 | + return mCacheUpdateInterval; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + /** | ||
| 104 | + * Call this to set how often the cached data will be updated. | ||
| 105 | + * | ||
| 106 | + * @param updateInterval The time that data will be cached | ||
| 107 | + * @return CosmoteRetrieveSharingRequest | ||
| 108 | + */ | ||
| 109 | + public CosmoteRetrieveSharingRequest setCacheUpdateInterval(long updateInterval) { | ||
| 110 | + | ||
| 111 | + this.mCacheUpdateInterval = updateInterval; | ||
| 112 | + if (mCacheUpdateInterval < 0) { | ||
| 113 | + mCacheUpdateInterval = 0; | ||
| 114 | + } | ||
| 115 | + return this; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + /** | ||
| 119 | + * Call this to check if the Application uses Cache | ||
| 120 | + * | ||
| 121 | + * @return <p>true - the Application is using Cache</p> | ||
| 122 | + * <p>false - the Application is not using Cache</p> | ||
| 123 | + */ | ||
| 124 | + public boolean isUseCache() { | ||
| 125 | + return mCacheUpdateInterval > 0; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + /** | ||
| 129 | + * Call this to check whether the cached data need to be updated | ||
| 130 | + * | ||
| 131 | + * @param useCache <p>true - the Application is using Cache</p> | ||
| 132 | + * <p>false - the Application is not using Cache</p> | ||
| 133 | + * @return CosmoteRetrieveSharingRequest | ||
| 134 | + */ | ||
| 135 | + public CosmoteRetrieveSharingRequest setUseCache(boolean useCache) { | ||
| 136 | + | ||
| 137 | + if (useCache) { | ||
| 138 | + mCacheUpdateInterval = mCacheUpdateInterval > 0 ? mCacheUpdateInterval | ||
| 139 | + : WarpConstants.INBOX_UPDATE_INTERVAL; | ||
| 140 | + } else { | ||
| 141 | + mCacheUpdateInterval = 0; | ||
| 142 | + } | ||
| 143 | + return this; | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + /** | ||
| 147 | + * Call this to build the offers Json object | ||
| 148 | + * | ||
| 149 | + * @return bodyJsonObject | ||
| 150 | + */ | ||
| 151 | + public JSONObject toJson() { | ||
| 152 | + JSONObject bodyJsonObject = new JSONObject(); | ||
| 153 | + try { | ||
| 154 | + JSONObject extraJson = new JSONObject(); | ||
| 155 | + extraJson.putOpt(KEY_ACTION, KEY_ACTION_VALUE); | ||
| 156 | + extraJson.putOpt(KEY_SHARING_ID_KEY, mSharingId); | ||
| 157 | + extraJson.putOpt(KEY_ACCEPT_KEY, mIsAccept); | ||
| 158 | + bodyJsonObject.putOpt(KEY_MAPP, extraJson); | ||
| 159 | + } catch (JSONException e) { | ||
| 160 | + if (WarpConstants.DEBUG) | ||
| 161 | + e.printStackTrace(); | ||
| 162 | + } | ||
| 163 | + return bodyJsonObject; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + public String getSignature() { | ||
| 167 | + String signature = mFilters != null && mFilters.size() > 0 ? String.valueOf(mFilters.hashCode()) : "default_cosmote_retrieve_sharing_request"; | ||
| 168 | + try { | ||
| 169 | + byte[] hash = MessageDigest.getInstance("SHA-256").digest(signature.getBytes("UTF-8")); | ||
| 170 | + signature = Base64.encodeToString(hash, Base64.NO_WRAP); | ||
| 171 | + } catch (NullPointerException | NoSuchAlgorithmException | ||
| 172 | + | UnsupportedEncodingException e) { | ||
| 173 | + e.printStackTrace(); | ||
| 174 | + } | ||
| 175 | + return signature; | ||
| 176 | + } | ||
| 177 | +} |
| 1 | +package ly.warp.sdk.io.request; | ||
| 2 | + | ||
| 3 | +import android.util.Base64; | ||
| 4 | + | ||
| 5 | +import org.json.JSONArray; | ||
| 6 | +import org.json.JSONException; | ||
| 7 | +import org.json.JSONObject; | ||
| 8 | + | ||
| 9 | +import java.io.UnsupportedEncodingException; | ||
| 10 | +import java.security.MessageDigest; | ||
| 11 | +import java.security.NoSuchAlgorithmException; | ||
| 12 | +import java.util.ArrayList; | ||
| 13 | +import java.util.HashMap; | ||
| 14 | + | ||
| 15 | +import ly.warp.sdk.utils.constants.WarpConstants; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * Created by Panagiotis Triantafyllou on 23-June-22. | ||
| 19 | + */ | ||
| 20 | + | ||
| 21 | +public class CosmoteSharingRequest { | ||
| 22 | + | ||
| 23 | + // =========================================================== | ||
| 24 | + // Constants | ||
| 25 | + // =========================================================== | ||
| 26 | + | ||
| 27 | + private final String KEY_MAPP = "wallet"; | ||
| 28 | + private final String KEY_ACTION = "action"; | ||
| 29 | + private final String KEY_ACTION_VALUE = "sharing_info"; | ||
| 30 | + private final String KEY_SHARING_ID_KEY = "sharing_id"; | ||
| 31 | + | ||
| 32 | + // =========================================================== | ||
| 33 | + // Fields | ||
| 34 | + // =========================================================== | ||
| 35 | + | ||
| 36 | + private HashMap<String, String> mFilters; | ||
| 37 | + private long mCacheUpdateInterval = 0; | ||
| 38 | + private String mSharingId = ""; | ||
| 39 | + | ||
| 40 | + // =========================================================== | ||
| 41 | + // Constructor | ||
| 42 | + // =========================================================== | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * Default constructor of CosmoteSharingRequest, initializes an empty filters HashMap | ||
| 46 | + */ | ||
| 47 | + public CosmoteSharingRequest() { | ||
| 48 | + mFilters = new HashMap<>(); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public CosmoteSharingRequest(CosmoteSharingRequest copy) { | ||
| 52 | + if (copy != null) { | ||
| 53 | + this.mFilters = copy.mFilters; | ||
| 54 | + this.mCacheUpdateInterval = copy.mCacheUpdateInterval; | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + // =========================================================== | ||
| 59 | + // Methods for/from SuperClass/Interfaces | ||
| 60 | + // =========================================================== | ||
| 61 | + | ||
| 62 | + @Override | ||
| 63 | + public boolean equals(Object object) { | ||
| 64 | + if (object instanceof CosmoteSharingRequest) { | ||
| 65 | + CosmoteSharingRequest other = (CosmoteSharingRequest) object; | ||
| 66 | + return other == this || (this.mFilters == other.mFilters || (this.mFilters != null && this.mFilters.equals(other.mFilters))); | ||
| 67 | + } | ||
| 68 | + return false; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public int hashCode() { | ||
| 73 | + return mFilters.hashCode(); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + // =========================================================== | ||
| 77 | + // Methods | ||
| 78 | + // =========================================================== | ||
| 79 | + | ||
| 80 | + // =========================================================== | ||
| 81 | + // Getter & Setter | ||
| 82 | + // =========================================================== | ||
| 83 | + | ||
| 84 | + public CosmoteSharingRequest setSharingId(String sharingId) { | ||
| 85 | + mSharingId = sharingId; | ||
| 86 | + return this; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + /** | ||
| 90 | + * Call this to get how often the cached data will be updated. | ||
| 91 | + * | ||
| 92 | + * @return mCacheUpdateInterval | ||
| 93 | + */ | ||
| 94 | + public long getCacheUpdateInterval() { | ||
| 95 | + return mCacheUpdateInterval; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + /** | ||
| 99 | + * Call this to set how often the cached data will be updated. | ||
| 100 | + * | ||
| 101 | + * @param updateInterval The time that data will be cached | ||
| 102 | + * @return CosmoteSharingRequest | ||
| 103 | + */ | ||
| 104 | + public CosmoteSharingRequest setCacheUpdateInterval(long updateInterval) { | ||
| 105 | + | ||
| 106 | + this.mCacheUpdateInterval = updateInterval; | ||
| 107 | + if (mCacheUpdateInterval < 0) { | ||
| 108 | + mCacheUpdateInterval = 0; | ||
| 109 | + } | ||
| 110 | + return this; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + /** | ||
| 114 | + * Call this to check if the Application uses Cache | ||
| 115 | + * | ||
| 116 | + * @return <p>true - the Application is using Cache</p> | ||
| 117 | + * <p>false - the Application is not using Cache</p> | ||
| 118 | + */ | ||
| 119 | + public boolean isUseCache() { | ||
| 120 | + return mCacheUpdateInterval > 0; | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + /** | ||
| 124 | + * Call this to check whether the cached data need to be updated | ||
| 125 | + * | ||
| 126 | + * @param useCache <p>true - the Application is using Cache</p> | ||
| 127 | + * <p>false - the Application is not using Cache</p> | ||
| 128 | + * @return CosmoteSharingRequest | ||
| 129 | + */ | ||
| 130 | + public CosmoteSharingRequest setUseCache(boolean useCache) { | ||
| 131 | + | ||
| 132 | + if (useCache) { | ||
| 133 | + mCacheUpdateInterval = mCacheUpdateInterval > 0 ? mCacheUpdateInterval | ||
| 134 | + : WarpConstants.INBOX_UPDATE_INTERVAL; | ||
| 135 | + } else { | ||
| 136 | + mCacheUpdateInterval = 0; | ||
| 137 | + } | ||
| 138 | + return this; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + /** | ||
| 142 | + * Call this to build the offers Json object | ||
| 143 | + * | ||
| 144 | + * @return bodyJsonObject | ||
| 145 | + */ | ||
| 146 | + public JSONObject toJson() { | ||
| 147 | + JSONObject bodyJsonObject = new JSONObject(); | ||
| 148 | + try { | ||
| 149 | + JSONObject extraJson = new JSONObject(); | ||
| 150 | + extraJson.putOpt(KEY_ACTION, KEY_ACTION_VALUE); | ||
| 151 | + extraJson.putOpt(KEY_SHARING_ID_KEY, mSharingId); | ||
| 152 | + bodyJsonObject.putOpt(KEY_MAPP, extraJson); | ||
| 153 | + } catch (JSONException e) { | ||
| 154 | + if (WarpConstants.DEBUG) | ||
| 155 | + e.printStackTrace(); | ||
| 156 | + } | ||
| 157 | + return bodyJsonObject; | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + public String getSignature() { | ||
| 161 | + String signature = mFilters != null && mFilters.size() > 0 ? String.valueOf(mFilters.hashCode()) : "default_cosmote_sharing_request"; | ||
| 162 | + try { | ||
| 163 | + byte[] hash = MessageDigest.getInstance("SHA-256").digest(signature.getBytes("UTF-8")); | ||
| 164 | + signature = Base64.encodeToString(hash, Base64.NO_WRAP); | ||
| 165 | + } catch (NullPointerException | NoSuchAlgorithmException | ||
| 166 | + | UnsupportedEncodingException e) { | ||
| 167 | + e.printStackTrace(); | ||
| 168 | + } | ||
| 169 | + return signature; | ||
| 170 | + } | ||
| 171 | +} |
| ... | @@ -12,6 +12,7 @@ import java.security.NoSuchAlgorithmException; | ... | @@ -12,6 +12,7 @@ import java.security.NoSuchAlgorithmException; |
| 12 | import java.util.ArrayList; | 12 | import java.util.ArrayList; |
| 13 | import java.util.HashMap; | 13 | import java.util.HashMap; |
| 14 | 14 | ||
| 15 | +import ly.warp.sdk.utils.WarplyManagerHelper; | ||
| 15 | import ly.warp.sdk.utils.constants.WarpConstants; | 16 | import ly.warp.sdk.utils.constants.WarpConstants; |
| 16 | 17 | ||
| 17 | /** | 18 | /** |
| ... | @@ -145,15 +146,11 @@ public class WarplyIntegrationRequest { | ... | @@ -145,15 +146,11 @@ public class WarplyIntegrationRequest { |
| 145 | JSONObject extraJson = new JSONObject(); | 146 | JSONObject extraJson = new JSONObject(); |
| 146 | extraJson.putOpt(KEY_ACTION, KEY_ACTION_VALUE); | 147 | extraJson.putOpt(KEY_ACTION, KEY_ACTION_VALUE); |
| 147 | extraJson.putOpt(KEY_METHOD, KEY_METHOD_VALUE); | 148 | extraJson.putOpt(KEY_METHOD, KEY_METHOD_VALUE); |
| 148 | - ArrayList list = new ArrayList(); | ||
| 149 | - list.add("6982853746"); | ||
| 150 | - list.add("6982853747"); | ||
| 151 | - list.add("6982853748"); | ||
| 152 | JSONObject data = new JSONObject(); | 149 | JSONObject data = new JSONObject(); |
| 153 | - data.putOpt("nonTelco", false); | 150 | + data.putOpt("nonTelco", WarplyManagerHelper.loadCustomerState().isNonTelco()); |
| 154 | - data.putOpt("acceptedConsent", true); | 151 | + data.putOpt("acceptedConsent", WarplyManagerHelper.loadCustomerState().isAcceptedConsent()); |
| 155 | - data.putOpt("msisdnList", new JSONArray(list)); | 152 | + data.putOpt("msisdnList", new JSONArray(WarplyManagerHelper.loadCustomerState().getMsisdnList())); |
| 156 | - data.putOpt("guid", "12345678"); | 153 | + data.putOpt("guid", WarplyManagerHelper.loadCustomerState().getGuid()); |
| 157 | 154 | ||
| 158 | extraJson.putOpt(KEY_DATA, data); | 155 | extraJson.putOpt(KEY_DATA, data); |
| 159 | bodyJsonObject.putOpt(KEY_MAPP, extraJson); | 156 | bodyJsonObject.putOpt(KEY_MAPP, extraJson); | ... | ... |
| ... | @@ -25,15 +25,21 @@ | ... | @@ -25,15 +25,21 @@ |
| 25 | 25 | ||
| 26 | package ly.warp.sdk.utils; | 26 | package ly.warp.sdk.utils; |
| 27 | 27 | ||
| 28 | +import android.content.Context; | ||
| 29 | +import android.text.TextUtils; | ||
| 28 | import android.util.Log; | 30 | import android.util.Log; |
| 29 | 31 | ||
| 32 | +import androidx.appcompat.app.AlertDialog; | ||
| 33 | + | ||
| 30 | import org.json.JSONObject; | 34 | import org.json.JSONObject; |
| 31 | 35 | ||
| 32 | import java.util.ArrayList; | 36 | import java.util.ArrayList; |
| 33 | import java.util.HashMap; | 37 | import java.util.HashMap; |
| 34 | 38 | ||
| 39 | +import ly.warp.sdk.R; | ||
| 35 | import ly.warp.sdk.Warply; | 40 | import ly.warp.sdk.Warply; |
| 36 | import ly.warp.sdk.db.WarplyDBHelper; | 41 | import ly.warp.sdk.db.WarplyDBHelper; |
| 42 | +import ly.warp.sdk.io.callbacks.CallbackReceiver; | ||
| 37 | import ly.warp.sdk.io.models.ActiveDFYCouponModel; | 43 | import ly.warp.sdk.io.models.ActiveDFYCouponModel; |
| 38 | import ly.warp.sdk.io.models.Campaign; | 44 | import ly.warp.sdk.io.models.Campaign; |
| 39 | import ly.warp.sdk.io.models.CampaignList; | 45 | import ly.warp.sdk.io.models.CampaignList; |
| ... | @@ -43,6 +49,9 @@ import ly.warp.sdk.io.models.CouponsetsList; | ... | @@ -43,6 +49,9 @@ import ly.warp.sdk.io.models.CouponsetsList; |
| 43 | import ly.warp.sdk.io.models.CustomerStateModel; | 49 | import ly.warp.sdk.io.models.CustomerStateModel; |
| 44 | import ly.warp.sdk.io.models.LoyaltyContextualOfferModel; | 50 | import ly.warp.sdk.io.models.LoyaltyContextualOfferModel; |
| 45 | import ly.warp.sdk.io.models.LoyaltyGiftsForYouPackage; | 51 | import ly.warp.sdk.io.models.LoyaltyGiftsForYouPackage; |
| 52 | +import ly.warp.sdk.io.request.CosmoteRetrieveSharingRequest; | ||
| 53 | +import ly.warp.sdk.io.request.CosmoteSharingRequest; | ||
| 54 | +import ly.warp.sdk.utils.managers.WarplyManager; | ||
| 46 | 55 | ||
| 47 | /** | 56 | /** |
| 48 | * Created by Panagiotis Triantafyllou on 18-Apr-22. | 57 | * Created by Panagiotis Triantafyllou on 18-Apr-22. |
| ... | @@ -67,6 +76,8 @@ public class WarplyManagerHelper { | ... | @@ -67,6 +76,8 @@ public class WarplyManagerHelper { |
| 67 | private static ArrayList<ActiveDFYCouponModel> mDfyCoupons = new ArrayList(); | 76 | private static ArrayList<ActiveDFYCouponModel> mDfyCoupons = new ArrayList(); |
| 68 | private static ArrayList<LoyaltyGiftsForYouPackage> mSeasonalList = new ArrayList<>(); | 77 | private static ArrayList<LoyaltyGiftsForYouPackage> mSeasonalList = new ArrayList<>(); |
| 69 | private static ArrayList<LoyaltyContextualOfferModel> mCCMSList = new ArrayList<>(); | 78 | private static ArrayList<LoyaltyContextualOfferModel> mCCMSList = new ArrayList<>(); |
| 79 | + private static AlertDialog mAlertDialogSharing, mAlertDialogAcceptSharing, mAlertDialogRejectSharing, | ||
| 80 | + mAlertDialogReturnSharing, mAlertDialogErrorSharing; | ||
| 70 | 81 | ||
| 71 | // =========================================================== | 82 | // =========================================================== |
| 72 | // Methods for/from SuperClass/Interfaces | 83 | // Methods for/from SuperClass/Interfaces |
| ... | @@ -100,39 +111,164 @@ public class WarplyManagerHelper { | ... | @@ -100,39 +111,164 @@ public class WarplyManagerHelper { |
| 100 | } | 111 | } |
| 101 | 112 | ||
| 102 | /** | 113 | /** |
| 103 | - * Open Warply campaign with sharing id | 114 | + * Handle sharing flow |
| 104 | */ | 115 | */ |
| 105 | - public static void constructCampaignUrlForShare(String sharingId) { | 116 | + public static void handleSharing(Context context, String sharingId) { |
| 106 | -// if (getCampaignList() != null) { | 117 | + WarplyManager.cosmoteSharing(new CosmoteSharingRequest().setSharingId(sharingId), new CallbackReceiver<JSONObject>() { |
| 107 | -// for (Campaign item : getCampaignList()) { | 118 | + @Override |
| 108 | -// if (item.getSessionUUID().equals(sessionUuid)) { | 119 | + public void onSuccess(JSONObject result) { |
| 109 | -// String url = item.getIndexUrl() | 120 | + Log.v("CosmoteSharing", "Success"); |
| 110 | -// + "?web_id=" + WarpUtils.getWebId(Warply.getWarplyContext()) | 121 | + int status = result.optInt("status", 2); |
| 111 | -// + "&app_uuid=" + WarplyProperty.getAppUuid(Warply.getWarplyContext()) | 122 | + if (status == 1) { |
| 112 | -// + "&api_key=" + WarpUtils.getApiKey(Warply.getWarplyContext()) | 123 | + JSONObject innerResult = new JSONObject(); |
| 113 | -// + "&session_uuid=" + item.getSessionUUID() | 124 | + innerResult = result.optJSONObject("result"); |
| 114 | -// + "&access_token=" + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token") | 125 | + if (innerResult != null) { |
| 115 | -// + "&refresh_token=" + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("refresh_token") | 126 | + String modalText = innerResult.optString("modal_text", ""); |
| 116 | -// + "&client_id=" + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getClientValue("client_id") | 127 | + String sharingStatus = innerResult.optString("status", ""); |
| 117 | -// + "&client_secret=" + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getClientValue("client_secret") | 128 | + |
| 118 | -// + "&sharing_id=" + sharingId; | 129 | + if (!TextUtils.isEmpty(sharingStatus) && sharingStatus.equals("pending")) { |
| 119 | -// return url; | 130 | + initialSharingDialog(context, modalText, sharingId); |
| 120 | -// } | 131 | + return; |
| 121 | -// } | 132 | + } |
| 122 | -// } | 133 | + if (!TextUtils.isEmpty(sharingStatus) && sharingStatus.equals("reject")) { |
| 123 | -// | 134 | + returnSharingDialog(context, modalText); |
| 124 | -// return ""; | 135 | + } |
| 136 | + } | ||
| 137 | + } else | ||
| 138 | + errorSharingDialog(context); | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + @Override | ||
| 142 | + public void onFailure(int errorCode) { | ||
| 143 | + Log.v("CosmoteSharing", "Error"); | ||
| 144 | + errorSharingDialog(context); | ||
| 145 | + } | ||
| 146 | + }); | ||
| 125 | } | 147 | } |
| 126 | 148 | ||
| 127 | /** | 149 | /** |
| 128 | - * Open CCMS campaign | 150 | + * First dialog when we handle the deeplink |
| 151 | + */ | ||
| 152 | + private static void initialSharingDialog(Context context, String alertTitle, String sharingId) { | ||
| 153 | + mAlertDialogSharing = new AlertDialog.Builder(context) | ||
| 154 | + .setTitle(R.string.cos_dlg_success_title) | ||
| 155 | + .setMessage(alertTitle) | ||
| 156 | + .setPositiveButton(R.string.cos_dlg_positive_button, (dialogPositive, whichPositive) -> { | ||
| 157 | + WarplyManager.cosmoteRetrieveSharing(new CosmoteRetrieveSharingRequest() | ||
| 158 | + .setSharingId(sharingId) | ||
| 159 | + .setAccept(true), | ||
| 160 | + new CallbackReceiver<JSONObject>() { | ||
| 161 | + @Override | ||
| 162 | + public void onSuccess(JSONObject result) { | ||
| 163 | + int status = result.optInt("status", 2); | ||
| 164 | + if (status == 1) | ||
| 165 | + acceptSharingDialog(context); | ||
| 166 | + else | ||
| 167 | + errorSharingDialog(context); | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + @Override | ||
| 171 | + public void onFailure(int errorCode) { | ||
| 172 | + errorSharingDialog(context); | ||
| 173 | + } | ||
| 174 | + }); | ||
| 175 | + }) | ||
| 176 | + .setNegativeButton(R.string.cos_dlg_negative_button, (dialogNegative, whichNegative) -> { | ||
| 177 | + rejectSharingDialog(context, sharingId); | ||
| 178 | + }) | ||
| 179 | + .show(); | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + /** | ||
| 183 | + * Dialog when we success get the sharing gift | ||
| 184 | + */ | ||
| 185 | + private static void acceptSharingDialog(Context context) { | ||
| 186 | + mAlertDialogAcceptSharing = new AlertDialog.Builder(context) | ||
| 187 | + .setTitle(R.string.cos_dlg_success_title) | ||
| 188 | + .setMessage(R.string.cos_dlg_positive_button_text) | ||
| 189 | + .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> { | ||
| 190 | + dialogPositive.dismiss(); | ||
| 191 | + }) | ||
| 192 | + .show(); | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + /** | ||
| 196 | + * Dialog when we reject the sharing gift | ||
| 129 | */ | 197 | */ |
| 130 | - public static String constructCcmsUrl(LoyaltyContextualOfferModel item) { | 198 | + private static void rejectSharingDialog(Context context, String sharingId) { |
| 131 | - return /*url*/ ""; | 199 | + mAlertDialogRejectSharing = new AlertDialog.Builder(context) |
| 200 | + .setTitle(R.string.cos_dlg_reject_title) | ||
| 201 | + .setMessage(R.string.cos_dlg_reject_text) | ||
| 202 | + .setPositiveButton(R.string.cos_dlg_negative_button, (dialogPositive, whichPositive) -> { | ||
| 203 | + WarplyManager.cosmoteRetrieveSharing(new CosmoteRetrieveSharingRequest() | ||
| 204 | + .setSharingId(sharingId) | ||
| 205 | + .setAccept(false), | ||
| 206 | + new CallbackReceiver<JSONObject>() { | ||
| 207 | + @Override | ||
| 208 | + public void onSuccess(JSONObject result) { | ||
| 209 | + int status = result.optInt("status", 2); | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + @Override | ||
| 213 | + public void onFailure(int errorCode) { | ||
| 214 | + errorSharingDialog(context); | ||
| 215 | + } | ||
| 216 | + }); | ||
| 217 | + }) | ||
| 218 | + .setNegativeButton(R.string.cos_dlg_negative_button2, (dialogNegative, whichNegative) -> { | ||
| 219 | + dialogNegative.dismiss(); | ||
| 220 | + }) | ||
| 221 | + .show(); | ||
| 132 | } | 222 | } |
| 133 | 223 | ||
| 134 | - private void mergeCCMS() { | 224 | + /** |
| 225 | + * Dialog when the gift gets returned | ||
| 226 | + */ | ||
| 227 | + private static void returnSharingDialog(Context context, String alertTitle) { | ||
| 228 | + mAlertDialogReturnSharing = new AlertDialog.Builder(context) | ||
| 229 | + .setTitle(R.string.cod_dlg_return_title) | ||
| 230 | + .setMessage(alertTitle) | ||
| 231 | + .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> { | ||
| 232 | + dialogPositive.dismiss(); | ||
| 233 | + }) | ||
| 234 | + .show(); | ||
| 235 | + } | ||
| 236 | + | ||
| 237 | + /** | ||
| 238 | + * Error dialog | ||
| 239 | + */ | ||
| 240 | + private static void errorSharingDialog(Context context) { | ||
| 241 | + mAlertDialogErrorSharing = new AlertDialog.Builder(context) | ||
| 242 | + .setTitle(R.string.cos_dlg_error_title) | ||
| 243 | + .setMessage(R.string.cos_dlg_error_subtitle) | ||
| 244 | + .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> { | ||
| 245 | + dialogPositive.dismiss(); | ||
| 246 | + }) | ||
| 247 | + .show(); | ||
| 248 | + } | ||
| 249 | + | ||
| 250 | + /** | ||
| 251 | + * Open CCMS campaign | ||
| 252 | + */ | ||
| 253 | + public static String constructCcmsUrl(Campaign item, String sessionId) { | ||
| 254 | + item.setNew(false); | ||
| 255 | + String url = item.getIndexUrl() | ||
| 256 | + + "?web_id=" + WarpUtils.getWebId(Warply.getWarplyContext()) | ||
| 257 | + + "&app_uuid=" + WarplyProperty.getAppUuid(Warply.getWarplyContext()) | ||
| 258 | + + "&api_key=" + WarpUtils.getApiKey(Warply.getWarplyContext()) | ||
| 259 | + + "&session_uuid=" + item.getSessionUUID() | ||
| 260 | + + "&access_token=" + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token") | ||
| 261 | + + "&refresh_token=" + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("refresh_token") | ||
| 262 | + + "&client_id=" + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getClientValue("client_id") | ||
| 263 | + + "&client_secret=" + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getClientValue("client_secret") | ||
| 264 | + + "&session_id=" + sessionId; | ||
| 265 | + | ||
| 266 | +// if (mConsumer != null) | ||
| 267 | +// url = url + "&auth_token=" + (mConsumer.getUuid()); | ||
| 268 | +// else | ||
| 269 | +// url = url + "&auth_token="; | ||
| 135 | 270 | ||
| 271 | + return url; | ||
| 136 | } | 272 | } |
| 137 | 273 | ||
| 138 | /** | 274 | /** |
| ... | @@ -140,18 +276,58 @@ public class WarplyManagerHelper { | ... | @@ -140,18 +276,58 @@ public class WarplyManagerHelper { |
| 140 | */ | 276 | */ |
| 141 | public static void setCCMSLoyaltyCampaigns(ArrayList<LoyaltyContextualOfferModel> list) { | 277 | public static void setCCMSLoyaltyCampaigns(ArrayList<LoyaltyContextualOfferModel> list) { |
| 142 | mCCMSList = list; | 278 | mCCMSList = list; |
| 279 | + | ||
| 280 | + if (list != null && list.size() == 0) { | ||
| 281 | + CampaignList tempGifts = new CampaignList(); | ||
| 282 | + if (mUniqueCampaignList != null && mUniqueCampaignList.get("gifts_for_you") != null && mUniqueCampaignList.get("gifts_for_you").size() > 0) { | ||
| 283 | + for (Campaign camp : mUniqueCampaignList.get("gifts_for_you")) { | ||
| 284 | + try { | ||
| 285 | + String key = WarpJSONParser.getJSONFromString(camp.getExtraFields()).keys().next(); | ||
| 286 | + if (!TextUtils.isEmpty(key) && key.equals("loyaltyCampaignId")) { | ||
| 287 | + tempGifts.add(camp); | ||
| 288 | + } | ||
| 289 | + } catch (Exception exception) { | ||
| 290 | + Log.v("WarplyManagerHelper_CCMS_Upper", exception.toString()); | ||
| 291 | + } | ||
| 292 | + } | ||
| 293 | + | ||
| 294 | + mUniqueCampaignList.get("gifts_for_you").removeAll(tempGifts); | ||
| 295 | + } | ||
| 296 | + return; | ||
| 297 | + } | ||
| 298 | + | ||
| 299 | + CampaignList tempGifts = new CampaignList(); | ||
| 143 | if (mUniqueCampaignList != null && mUniqueCampaignList.get("gifts_for_you") != null && mUniqueCampaignList.get("gifts_for_you").size() > 0) { | 300 | if (mUniqueCampaignList != null && mUniqueCampaignList.get("gifts_for_you") != null && mUniqueCampaignList.get("gifts_for_you").size() > 0) { |
| 144 | for (Campaign camp : mUniqueCampaignList.get("gifts_for_you")) { | 301 | for (Campaign camp : mUniqueCampaignList.get("gifts_for_you")) { |
| 145 | try { | 302 | try { |
| 146 | - String te2 = WarpJSONParser.getJSONFromString(camp.getExtraFields()).keys().next(); | 303 | + String key = WarpJSONParser.getJSONFromString(camp.getExtraFields()).keys().next(); |
| 304 | + if (!TextUtils.isEmpty(key) && key.equals("loyaltyCampaignId")) { | ||
| 305 | + String value = WarpJSONParser.getJSONFromString(camp.getExtraFields()).optString("loyaltyCampaignId"); | ||
| 306 | + for (LoyaltyContextualOfferModel ccms : list) { | ||
| 307 | + if (ccms.getLoyaltyCampaignId().equals(value)) { | ||
| 308 | + tempGifts.add(camp); | ||
| 309 | + break; | ||
| 310 | + } | ||
| 311 | + } | ||
| 312 | + } | ||
| 147 | } catch (Exception exception) { | 313 | } catch (Exception exception) { |
| 148 | Log.v("WarplyManagerHelper_CCMS", exception.toString()); | 314 | Log.v("WarplyManagerHelper_CCMS", exception.toString()); |
| 315 | + tempGifts.add(camp); | ||
| 149 | } | 316 | } |
| 150 | } | 317 | } |
| 318 | + | ||
| 319 | + mUniqueCampaignList.get("gifts_for_you").retainAll(tempGifts); | ||
| 151 | } | 320 | } |
| 152 | } | 321 | } |
| 153 | 322 | ||
| 154 | /** | 323 | /** |
| 324 | + * Get the List with CCMS Campaigns | ||
| 325 | + */ | ||
| 326 | + public static ArrayList<LoyaltyContextualOfferModel> getCCMSLoyaltyCampaigns() { | ||
| 327 | + return mCCMSList; | ||
| 328 | + } | ||
| 329 | + | ||
| 330 | + /** | ||
| 155 | * Save the LoyaltyGiftsForYouPackage list | 331 | * Save the LoyaltyGiftsForYouPackage list |
| 156 | */ | 332 | */ |
| 157 | public static void setSeasonalList(ArrayList<LoyaltyGiftsForYouPackage> seasonalCoupons) { | 333 | public static void setSeasonalList(ArrayList<LoyaltyGiftsForYouPackage> seasonalCoupons) { | ... | ... |
| ... | @@ -60,6 +60,8 @@ import ly.warp.sdk.io.models.ProductList; | ... | @@ -60,6 +60,8 @@ import ly.warp.sdk.io.models.ProductList; |
| 60 | import ly.warp.sdk.io.models.TagsCategoriesList; | 60 | import ly.warp.sdk.io.models.TagsCategoriesList; |
| 61 | import ly.warp.sdk.io.models.TagsList; | 61 | import ly.warp.sdk.io.models.TagsList; |
| 62 | import ly.warp.sdk.io.models.TransactionsList; | 62 | import ly.warp.sdk.io.models.TransactionsList; |
| 63 | +import ly.warp.sdk.io.request.CosmoteRetrieveSharingRequest; | ||
| 64 | +import ly.warp.sdk.io.request.CosmoteSharingRequest; | ||
| 63 | import ly.warp.sdk.io.request.WarplyAddAddressRequest; | 65 | import ly.warp.sdk.io.request.WarplyAddAddressRequest; |
| 64 | import ly.warp.sdk.io.request.WarplyAddCardRequest; | 66 | import ly.warp.sdk.io.request.WarplyAddCardRequest; |
| 65 | import ly.warp.sdk.io.request.WarplyAuthorizeRequest; | 67 | import ly.warp.sdk.io.request.WarplyAuthorizeRequest; |
| ... | @@ -1349,4 +1351,82 @@ public class WarplyManager { | ... | @@ -1349,4 +1351,82 @@ public class WarplyManager { |
| 1349 | } | 1351 | } |
| 1350 | }); | 1352 | }); |
| 1351 | } | 1353 | } |
| 1354 | + | ||
| 1355 | + public static void cosmoteSharing(CosmoteSharingRequest request, final CallbackReceiver<JSONObject> receiver) { | ||
| 1356 | + WarpUtils.log("************* WARPLY Cosmote Sharing Request ********************"); | ||
| 1357 | + WarpUtils.log("[WARP Trace] WARPLY Cosmote Sharing Request is active"); | ||
| 1358 | + WarpUtils.log("**************************************************"); | ||
| 1359 | + | ||
| 1360 | + Warply.postReceiveMicroappData(true, "context", request.toJson(), new CallbackReceiver<JSONObject>() { | ||
| 1361 | + @Override | ||
| 1362 | + public void onSuccess(JSONObject result) { | ||
| 1363 | + int status = result.optInt("status", 2); | ||
| 1364 | + if (status == 1) | ||
| 1365 | + receiver.onSuccess(result); | ||
| 1366 | + else | ||
| 1367 | + receiver.onFailure(status); | ||
| 1368 | + } | ||
| 1369 | + | ||
| 1370 | + @Override | ||
| 1371 | + public void onFailure(int errorCode) { | ||
| 1372 | + if (errorCode == 401) { | ||
| 1373 | + refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() { | ||
| 1374 | + @Override | ||
| 1375 | + public void onSuccess(JSONObject result) { | ||
| 1376 | + int status = result.optInt("status", 2); | ||
| 1377 | + if (status == 1) | ||
| 1378 | + cosmoteSharing(request, receiver); | ||
| 1379 | + else | ||
| 1380 | + receiver.onFailure(status); | ||
| 1381 | + } | ||
| 1382 | + | ||
| 1383 | + @Override | ||
| 1384 | + public void onFailure(int errorCode) { | ||
| 1385 | + receiver.onFailure(errorCode); | ||
| 1386 | + } | ||
| 1387 | + }); | ||
| 1388 | + } else | ||
| 1389 | + receiver.onFailure(errorCode); | ||
| 1390 | + } | ||
| 1391 | + }); | ||
| 1392 | + } | ||
| 1393 | + | ||
| 1394 | + public static void cosmoteRetrieveSharing(CosmoteRetrieveSharingRequest request, final CallbackReceiver<JSONObject> receiver) { | ||
| 1395 | + WarpUtils.log("************* WARPLY Cosmote Retrieve Sharing Request ********************"); | ||
| 1396 | + WarpUtils.log("[WARP Trace] WARPLY Cosmote Retrieve Sharing Request is active"); | ||
| 1397 | + WarpUtils.log("**************************************************"); | ||
| 1398 | + | ||
| 1399 | + Warply.postReceiveMicroappData(true, "context", request.toJson(), new CallbackReceiver<JSONObject>() { | ||
| 1400 | + @Override | ||
| 1401 | + public void onSuccess(JSONObject result) { | ||
| 1402 | + int status = result.optInt("status", 2); | ||
| 1403 | + if (status == 1) | ||
| 1404 | + receiver.onSuccess(result); | ||
| 1405 | + else | ||
| 1406 | + receiver.onFailure(status); | ||
| 1407 | + } | ||
| 1408 | + | ||
| 1409 | + @Override | ||
| 1410 | + public void onFailure(int errorCode) { | ||
| 1411 | + if (errorCode == 401) { | ||
| 1412 | + refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() { | ||
| 1413 | + @Override | ||
| 1414 | + public void onSuccess(JSONObject result) { | ||
| 1415 | + int status = result.optInt("status", 2); | ||
| 1416 | + if (status == 1) | ||
| 1417 | + cosmoteRetrieveSharing(request, receiver); | ||
| 1418 | + else | ||
| 1419 | + receiver.onFailure(status); | ||
| 1420 | + } | ||
| 1421 | + | ||
| 1422 | + @Override | ||
| 1423 | + public void onFailure(int errorCode) { | ||
| 1424 | + receiver.onFailure(errorCode); | ||
| 1425 | + } | ||
| 1426 | + }); | ||
| 1427 | + } else | ||
| 1428 | + receiver.onFailure(errorCode); | ||
| 1429 | + } | ||
| 1430 | + }); | ||
| 1431 | + } | ||
| 1352 | } | 1432 | } | ... | ... |
| ... | @@ -35,7 +35,6 @@ | ... | @@ -35,7 +35,6 @@ |
| 35 | <string name="cos_coupons_title">ΚΟΥΠΟΝΙΑ</string> | 35 | <string name="cos_coupons_title">ΚΟΥΠΟΝΙΑ</string> |
| 36 | <string name="cos_coupon_terms_title">Όροι χρήσης</string> | 36 | <string name="cos_coupon_terms_title">Όροι χρήσης</string> |
| 37 | <string name="cos_redeem_coupon">Απόκτησέ το</string> | 37 | <string name="cos_redeem_coupon">Απόκτησέ το</string> |
| 38 | - <string name="cos_dlg_success_title">Συγχαρητήρια</string> | ||
| 39 | <string name="cos_dlg_success_subtitle">Το κουπόνι εξαργυρώθηκε με επιτυχία</string> | 38 | <string name="cos_dlg_success_subtitle">Το κουπόνι εξαργυρώθηκε με επιτυχία</string> |
| 40 | <string name="cos_dlg_error_title">Αποτυχία</string> | 39 | <string name="cos_dlg_error_title">Αποτυχία</string> |
| 41 | <string name="cos_dlg_error_subtitle">Κάτι πήγε στραβά</string> | 40 | <string name="cos_dlg_error_subtitle">Κάτι πήγε στραβά</string> |
| ... | @@ -75,6 +74,16 @@ | ... | @@ -75,6 +74,16 @@ |
| 75 | <string name="cos_active_gifts_title">Ενεργά δώρα</string> | 74 | <string name="cos_active_gifts_title">Ενεργά δώρα</string> |
| 76 | <string name="cos_loyalty_analysis">Ανάλυση συναλλαγών</string> | 75 | <string name="cos_loyalty_analysis">Ανάλυση συναλλαγών</string> |
| 77 | <string name="cos_value">%1$s€</string> | 76 | <string name="cos_value">%1$s€</string> |
| 77 | + <string name="cos_dlg_success_title">Συγχαρητήρια!</string> | ||
| 78 | + <string name="cos_dlg_reject_title">Είσαι σίγουρος;</string> | ||
| 79 | + <string name="cod_dlg_return_title">Επιστροφή δώρου</string> | ||
| 80 | + <string name="cos_dlg_positive_button">Ενεργοποίηση</string> | ||
| 81 | + <string name="cos_dlg_negative_button">Απόρριψη</string> | ||
| 82 | + <string name="cos_dlg_positive_button2">ΟΚ</string> | ||
| 83 | + <string name="cos_dlg_positive_button_text">Μόλις έλαβες το δώρο σου!</string> | ||
| 84 | + <string name="cos_dlg_reject_text">Είσαι σίγουρος ότι θέλεις να απορρίψεις το δώρο που μόλις έλαβες;</string> | ||
| 85 | + <string name="cos_dlg_return_text">Έλαβες πίσω το δώρο σου, κουπόνι αξίας 100€ για τα Intersport</string> | ||
| 86 | + <string name="cos_dlg_negative_button2">Άκυρο</string> | ||
| 78 | 87 | ||
| 79 | <string-array name="coupons_array"> | 88 | <string-array name="coupons_array"> |
| 80 | <item>Κουπόνια</item> | 89 | <item>Κουπόνια</item> | ... | ... |
-
Please register or login to post a comment