Showing
5 changed files
with
131 additions
and
26 deletions
| ... | @@ -3,25 +3,33 @@ package ly.warp.sdk.activities; | ... | @@ -3,25 +3,33 @@ 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.os.Parcelable; | ||
| 6 | import android.text.TextUtils; | 7 | import android.text.TextUtils; |
| 7 | import android.view.View; | 8 | import android.view.View; |
| 8 | import android.widget.ImageView; | 9 | import android.widget.ImageView; |
| 9 | import android.widget.LinearLayout; | 10 | import android.widget.LinearLayout; |
| 11 | +import android.widget.RelativeLayout; | ||
| 10 | import android.widget.TextView; | 12 | import android.widget.TextView; |
| 13 | +import android.widget.Toast; | ||
| 11 | 14 | ||
| 12 | import androidx.core.text.HtmlCompat; | 15 | import androidx.core.text.HtmlCompat; |
| 13 | 16 | ||
| 14 | import com.bumptech.glide.Glide; | 17 | import com.bumptech.glide.Glide; |
| 15 | import com.bumptech.glide.load.engine.DiskCacheStrategy; | 18 | import com.bumptech.glide.load.engine.DiskCacheStrategy; |
| 16 | 19 | ||
| 20 | +import org.json.JSONObject; | ||
| 21 | + | ||
| 17 | import java.text.ParseException; | 22 | import java.text.ParseException; |
| 18 | import java.text.SimpleDateFormat; | 23 | import java.text.SimpleDateFormat; |
| 19 | import java.util.Date; | 24 | import java.util.Date; |
| 20 | import java.util.Locale; | 25 | import java.util.Locale; |
| 21 | 26 | ||
| 22 | import ly.warp.sdk.R; | 27 | import ly.warp.sdk.R; |
| 28 | +import ly.warp.sdk.io.callbacks.CallbackReceiver; | ||
| 29 | +import ly.warp.sdk.io.models.Coupon; | ||
| 23 | import ly.warp.sdk.io.models.Couponset; | 30 | import ly.warp.sdk.io.models.Couponset; |
| 24 | import ly.warp.sdk.utils.WarpUtils; | 31 | import ly.warp.sdk.utils.WarpUtils; |
| 32 | +import ly.warp.sdk.utils.managers.WarplyManager; | ||
| 25 | 33 | ||
| 26 | public class SingleCouponsetActivity extends Activity implements View.OnClickListener { | 34 | public class SingleCouponsetActivity extends Activity implements View.OnClickListener { |
| 27 | // =========================================================== | 35 | // =========================================================== |
| ... | @@ -41,9 +49,9 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis | ... | @@ -41,9 +49,9 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis |
| 41 | private TextView mTvValue; | 49 | private TextView mTvValue; |
| 42 | private TextView mTvMoreButton; | 50 | private TextView mTvMoreButton; |
| 43 | private ImageView mIvImage; | 51 | private ImageView mIvImage; |
| 44 | - | 52 | + private LinearLayout mRedeemButton; |
| 45 | private boolean mIsDescriptionExpanded = false; | 53 | private boolean mIsDescriptionExpanded = false; |
| 46 | - | 54 | + private RelativeLayout mPbLoading; |
| 47 | // Terms of Use section | 55 | // Terms of Use section |
| 48 | private LinearLayout mTermsContainer; | 56 | private LinearLayout mTermsContainer; |
| 49 | private LinearLayout mTermsHeader; | 57 | private LinearLayout mTermsHeader; |
| ... | @@ -52,7 +60,7 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis | ... | @@ -52,7 +60,7 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis |
| 52 | private TextView mTvTermsText; | 60 | private TextView mTvTermsText; |
| 53 | private boolean mIsTermsExpanded = false; | 61 | private boolean mIsTermsExpanded = false; |
| 54 | 62 | ||
| 55 | - private TextView mTvHeaderTitle, mTvTermsTitle, mTvShopsTitle, mTvWebsiteTitle, mTVMoreTitle; | 63 | + private TextView mTvHeaderTitle, mTvTermsTitle, mTvRedeemTitle, mTVMoreTitle; |
| 56 | 64 | ||
| 57 | 65 | ||
| 58 | // =========================================================== | 66 | // =========================================================== |
| ... | @@ -85,6 +93,11 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis | ... | @@ -85,6 +93,11 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis |
| 85 | public void onClick(View v) { | 93 | public void onClick(View v) { |
| 86 | if (v.getId() == R.id.iv_back) { | 94 | if (v.getId() == R.id.iv_back) { |
| 87 | onBackPressed(); | 95 | onBackPressed(); |
| 96 | + return; | ||
| 97 | + } | ||
| 98 | + if (v.getId() == R.id.ll_redeem_coupon) { | ||
| 99 | + mPbLoading.setVisibility(View.VISIBLE); | ||
| 100 | + WarplyManager.retrieveCoupon(mOfferItem.getUuid(), mRetrieveCallback); | ||
| 88 | } | 101 | } |
| 89 | } | 102 | } |
| 90 | 103 | ||
| ... | @@ -93,9 +106,15 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis | ... | @@ -93,9 +106,15 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis |
| 93 | // =========================================================== | 106 | // =========================================================== |
| 94 | 107 | ||
| 95 | private void initViews() { | 108 | private void initViews() { |
| 109 | + mPbLoading = findViewById(R.id.pb_loading); | ||
| 110 | + mPbLoading.setOnTouchListener((v, event) -> true); | ||
| 111 | + | ||
| 96 | mIvBack = findViewById(R.id.iv_back); | 112 | mIvBack = findViewById(R.id.iv_back); |
| 97 | mIvBack.setOnClickListener(this); | 113 | mIvBack.setOnClickListener(this); |
| 98 | 114 | ||
| 115 | + mRedeemButton = findViewById(R.id.ll_redeem_coupon); | ||
| 116 | + mRedeemButton.setOnClickListener(this); | ||
| 117 | + | ||
| 99 | // Initialize views | 118 | // Initialize views |
| 100 | mTvSmallDescription = findViewById(R.id.tv_coupon_small_description); | 119 | mTvSmallDescription = findViewById(R.id.tv_coupon_small_description); |
| 101 | mTvFullDescription = findViewById(R.id.tv_coupon_full_description); | 120 | mTvFullDescription = findViewById(R.id.tv_coupon_full_description); |
| ... | @@ -113,12 +132,11 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis | ... | @@ -113,12 +132,11 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis |
| 113 | 132 | ||
| 114 | mTvHeaderTitle = findViewById(R.id.tv_header_title); | 133 | mTvHeaderTitle = findViewById(R.id.tv_header_title); |
| 115 | mTvTermsTitle = findViewById(R.id.tv_terms_title); | 134 | mTvTermsTitle = findViewById(R.id.tv_terms_title); |
| 116 | - mTvShopsTitle = findViewById(R.id.tv_shops_title); | 135 | + mTvRedeemTitle = findViewById(R.id.tv_redeem_title); |
| 117 | - mTvWebsiteTitle = findViewById(R.id.tv_website_title); | ||
| 118 | mTVMoreTitle = findViewById(R.id.tv_more_title); | 136 | mTVMoreTitle = findViewById(R.id.tv_more_title); |
| 119 | 137 | ||
| 120 | WarpUtils.renderCustomFont(this, R.font.ping_lcg_bold, mTvHeaderTitle, mTvValue, | 138 | WarpUtils.renderCustomFont(this, R.font.ping_lcg_bold, mTvHeaderTitle, mTvValue, |
| 121 | - mTvTermsTitle, mTvShopsTitle, mTvWebsiteTitle); | 139 | + mTvTermsTitle, mTvRedeemTitle); |
| 122 | 140 | ||
| 123 | WarpUtils.renderCustomFont(this, R.font.ping_lcg_regular, mTvSmallDescription, | 141 | WarpUtils.renderCustomFont(this, R.font.ping_lcg_regular, mTvSmallDescription, |
| 124 | mTvEndDate, mTvFullDescription, mTvTermsText, | 142 | mTvEndDate, mTvFullDescription, mTvTermsText, |
| ... | @@ -250,4 +268,25 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis | ... | @@ -250,4 +268,25 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis |
| 250 | // =========================================================== | 268 | // =========================================================== |
| 251 | // Inner and Anonymous Classes | 269 | // Inner and Anonymous Classes |
| 252 | // =========================================================== | 270 | // =========================================================== |
| 271 | + | ||
| 272 | + private final CallbackReceiver<JSONObject> mRetrieveCallback = new CallbackReceiver<JSONObject>() { | ||
| 273 | + @Override | ||
| 274 | + public void onSuccess(JSONObject result) { | ||
| 275 | + mPbLoading.setVisibility(View.GONE); | ||
| 276 | + Toast.makeText(SingleCouponsetActivity.this, "RETRIEVE SUCCESS", Toast.LENGTH_SHORT).show(); | ||
| 277 | + Coupon coupon = new Coupon(); | ||
| 278 | + coupon.setCoupon(result.optString("coupon", "")); | ||
| 279 | + coupon.setExpiration(result.optString("expiration", "")); | ||
| 280 | + coupon.setCouponsetDetails(mOfferItem); | ||
| 281 | + Intent myIntent = new Intent(SingleCouponsetActivity.this, SingleCouponActivity.class); | ||
| 282 | + myIntent.putExtra(SingleCouponActivity.EXTRA_OFFER_ITEM, (Parcelable) coupon); | ||
| 283 | + startActivity(myIntent); | ||
| 284 | + } | ||
| 285 | + | ||
| 286 | + @Override | ||
| 287 | + public void onFailure(int errorCode) { | ||
| 288 | + mPbLoading.setVisibility(View.GONE); | ||
| 289 | + Toast.makeText(SingleCouponsetActivity.this, "RETRIEVE ERROR", Toast.LENGTH_SHORT).show(); | ||
| 290 | + } | ||
| 291 | + }; | ||
| 253 | } | 292 | } | ... | ... |
| ... | @@ -89,6 +89,18 @@ public interface ApiService { | ... | @@ -89,6 +89,18 @@ public interface ApiService { |
| 89 | @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer); | 89 | @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer); |
| 90 | 90 | ||
| 91 | @Headers("Content-Type: application/json") | 91 | @Headers("Content-Type: application/json") |
| 92 | + @POST("/oauth/{appUuid}/context") | ||
| 93 | + Call<ResponseBody> retrieveCoupon(@Path("appUuid") String appUuid, | ||
| 94 | + @Body RequestBody request, | ||
| 95 | + @Header(WarpConstants.HEADER_DATE) String timeStamp, | ||
| 96 | + @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId, | ||
| 97 | + @Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId, | ||
| 98 | + @Header(WarpConstants.HEADER_CHANNEL) String channel, | ||
| 99 | + @Header(WarpConstants.HEADER_WEB_ID) String webId, | ||
| 100 | + @Header(WarpConstants.HEADER_SIGNATURE) String signature, | ||
| 101 | + @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer); | ||
| 102 | + | ||
| 103 | + @Headers("Content-Type: application/json") | ||
| 92 | @POST("/api/mobile/v2/{appUuid}/context/") | 104 | @POST("/api/mobile/v2/{appUuid}/context/") |
| 93 | Call<ResponseBody> getCampaigns(@Path("appUuid") String appUuid, | 105 | Call<ResponseBody> getCampaigns(@Path("appUuid") String appUuid, |
| 94 | @Body RequestBody request, | 106 | @Body RequestBody request, | ... | ... |
| ... | @@ -1137,4 +1137,56 @@ public class WarplyManager { | ... | @@ -1137,4 +1137,56 @@ public class WarplyManager { |
| 1137 | } | 1137 | } |
| 1138 | }, null); | 1138 | }, null); |
| 1139 | } | 1139 | } |
| 1140 | + | ||
| 1141 | + public static void retrieveCoupon(@NonNull String couponsetUuid, final CallbackReceiver<JSONObject> receiver) { | ||
| 1142 | + WarpUtils.log("************* WARPLY Retrieve Coupon Request ********************"); | ||
| 1143 | + WarpUtils.log("[WARP Trace] WARPLY Retrieve Coupon Request is active"); | ||
| 1144 | + WarpUtils.log("**************************************************"); | ||
| 1145 | + | ||
| 1146 | + ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class); | ||
| 1147 | + | ||
| 1148 | + String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); | ||
| 1149 | + String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext()); | ||
| 1150 | + String webId = WarpUtils.getWebId(Warply.getWarplyContext()); | ||
| 1151 | + | ||
| 1152 | + Map<String, Object> jsonParamsRetrieve = new ArrayMap<>(); | ||
| 1153 | + Map<String, Object> jsonParams = new ArrayMap<>(); | ||
| 1154 | + jsonParams.put("action", "retrieve_coupon"); | ||
| 1155 | + jsonParams.put("coupon_set", couponsetUuid); | ||
| 1156 | + | ||
| 1157 | + jsonParamsRetrieve.put("coupon", jsonParams); | ||
| 1158 | + RequestBody retrieveRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsRetrieve)).toString()); | ||
| 1159 | + | ||
| 1160 | + Call<ResponseBody> retrieveCall = service.retrieveCoupon(WarplyProperty.getAppUuid(Warply.getWarplyContext()), retrieveRequest, timeStamp, "android:" + Warply.getWarplyContext().getPackageName(), new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(), "mobile", webId, WarpUtils.produceSignature(apiKey + timeStamp), "Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token")); | ||
| 1161 | + | ||
| 1162 | + retrieveCall.enqueue(new Callback<ResponseBody>() { | ||
| 1163 | + @Override | ||
| 1164 | + public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) { | ||
| 1165 | + if (response.code() == 200 && response.body() != null) { | ||
| 1166 | + JSONObject jobjRetrieveResponse = null; | ||
| 1167 | + try { | ||
| 1168 | + jobjRetrieveResponse = new JSONObject(response.body().string()); | ||
| 1169 | + } catch (Exception e) { | ||
| 1170 | + e.printStackTrace(); | ||
| 1171 | + } | ||
| 1172 | + | ||
| 1173 | + if (jobjRetrieveResponse != null && jobjRetrieveResponse.has("status") && jobjRetrieveResponse.optString("status", "2").equals("1")) { | ||
| 1174 | + JSONObject result = jobjRetrieveResponse.optJSONObject("result"); | ||
| 1175 | + if (result != null) { | ||
| 1176 | + receiver.onSuccess(result); | ||
| 1177 | + } else receiver.onFailure(2); | ||
| 1178 | + } else { | ||
| 1179 | + receiver.onFailure(2); | ||
| 1180 | + } | ||
| 1181 | + } else { | ||
| 1182 | + receiver.onFailure(response.code()); | ||
| 1183 | + } | ||
| 1184 | + } | ||
| 1185 | + | ||
| 1186 | + @Override | ||
| 1187 | + public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) { | ||
| 1188 | + receiver.onFailure(2); | ||
| 1189 | + } | ||
| 1190 | + }); | ||
| 1191 | + } | ||
| 1140 | } | 1192 | } | ... | ... |
| ... | @@ -251,24 +251,7 @@ | ... | @@ -251,24 +251,7 @@ |
| 251 | </LinearLayout> | 251 | </LinearLayout> |
| 252 | 252 | ||
| 253 | <LinearLayout | 253 | <LinearLayout |
| 254 | - android:layout_width="match_parent" | 254 | + android:id="@+id/ll_redeem_coupon" |
| 255 | - android:layout_height="55dp" | ||
| 256 | - android:layout_marginTop="48dp" | ||
| 257 | - android:background="@drawable/selector_button_black" | ||
| 258 | - android:gravity="center" | ||
| 259 | - android:orientation="horizontal"> | ||
| 260 | - | ||
| 261 | - <TextView | ||
| 262 | - android:id="@+id/tv_shops_title" | ||
| 263 | - android:layout_width="wrap_content" | ||
| 264 | - android:layout_height="wrap_content" | ||
| 265 | - android:text="@string/demo_shops" | ||
| 266 | - android:textColor="@color/white" | ||
| 267 | - android:textSize="15sp" | ||
| 268 | - android:textStyle="bold" /> | ||
| 269 | - </LinearLayout> | ||
| 270 | - | ||
| 271 | - <LinearLayout | ||
| 272 | android:layout_width="match_parent" | 255 | android:layout_width="match_parent" |
| 273 | android:layout_height="55dp" | 256 | android:layout_height="55dp" |
| 274 | android:layout_marginTop="20dp" | 257 | android:layout_marginTop="20dp" |
| ... | @@ -277,10 +260,10 @@ | ... | @@ -277,10 +260,10 @@ |
| 277 | android:orientation="horizontal"> | 260 | android:orientation="horizontal"> |
| 278 | 261 | ||
| 279 | <TextView | 262 | <TextView |
| 280 | - android:id="@+id/tv_website_title" | 263 | + android:id="@+id/tv_redeem_title" |
| 281 | android:layout_width="wrap_content" | 264 | android:layout_width="wrap_content" |
| 282 | android:layout_height="wrap_content" | 265 | android:layout_height="wrap_content" |
| 283 | - android:text="@string/demo_website" | 266 | + android:text="@string/demo_redeem" |
| 284 | android:textColor="@color/custom_black2" | 267 | android:textColor="@color/custom_black2" |
| 285 | android:textSize="15sp" | 268 | android:textSize="15sp" |
| 286 | android:textStyle="bold" /> | 269 | android:textStyle="bold" /> |
| ... | @@ -288,4 +271,22 @@ | ... | @@ -288,4 +271,22 @@ |
| 288 | </LinearLayout> | 271 | </LinearLayout> |
| 289 | </LinearLayout> | 272 | </LinearLayout> |
| 290 | </ScrollView> | 273 | </ScrollView> |
| 274 | + | ||
| 275 | + <RelativeLayout | ||
| 276 | + android:id="@+id/pb_loading" | ||
| 277 | + android:layout_width="match_parent" | ||
| 278 | + android:layout_height="wrap_content" | ||
| 279 | + android:background="@android:color/transparent" | ||
| 280 | + android:translationZ="100dp" | ||
| 281 | + android:visibility="gone" | ||
| 282 | + android:layout_centerInParent="true" | ||
| 283 | + tools:visibility="visible"> | ||
| 284 | + <ProgressBar | ||
| 285 | + android:layout_width="48dp" | ||
| 286 | + android:layout_height="48dp" | ||
| 287 | + android:layout_centerInParent="true" | ||
| 288 | + android:indeterminate="true" | ||
| 289 | + android:indeterminateTint="@color/custom_light_blue" | ||
| 290 | + android:indeterminateTintMode="src_atop" /> | ||
| 291 | + </RelativeLayout> | ||
| 291 | </RelativeLayout> | 292 | </RelativeLayout> | ... | ... |
| ... | @@ -21,6 +21,7 @@ | ... | @@ -21,6 +21,7 @@ |
| 21 | <string name="demo_lorem_ipsum">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</string> | 21 | <string name="demo_lorem_ipsum">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</string> |
| 22 | <string name="demo_shops">Καταστήματα κοντά μου</string> | 22 | <string name="demo_shops">Καταστήματα κοντά μου</string> |
| 23 | <string name="demo_website">Δες το website</string> | 23 | <string name="demo_website">Δες το website</string> |
| 24 | + <string name="demo_redeem">Απόκτησε το κουπόνι</string> | ||
| 24 | <string name="demo_profile">Το προφίλ μου</string> | 25 | <string name="demo_profile">Το προφίλ μου</string> |
| 25 | <string name="demo_my_coupons">Τα κουπόνια μου</string> | 26 | <string name="demo_my_coupons">Τα κουπόνια μου</string> |
| 26 | <string name="demo_active">Ενεργά</string> | 27 | <string name="demo_active">Ενεργά</string> | ... | ... |
-
Please register or login to post a comment