Panagiotis Triantafyllou

retrieve coupon request

......@@ -3,25 +3,33 @@ package ly.warp.sdk.activities;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.core.text.HtmlCompat;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import org.json.JSONObject;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import ly.warp.sdk.R;
import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.models.Coupon;
import ly.warp.sdk.io.models.Couponset;
import ly.warp.sdk.utils.WarpUtils;
import ly.warp.sdk.utils.managers.WarplyManager;
public class SingleCouponsetActivity extends Activity implements View.OnClickListener {
// ===========================================================
......@@ -41,9 +49,9 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis
private TextView mTvValue;
private TextView mTvMoreButton;
private ImageView mIvImage;
private LinearLayout mRedeemButton;
private boolean mIsDescriptionExpanded = false;
private RelativeLayout mPbLoading;
// Terms of Use section
private LinearLayout mTermsContainer;
private LinearLayout mTermsHeader;
......@@ -52,7 +60,7 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis
private TextView mTvTermsText;
private boolean mIsTermsExpanded = false;
private TextView mTvHeaderTitle, mTvTermsTitle, mTvShopsTitle, mTvWebsiteTitle, mTVMoreTitle;
private TextView mTvHeaderTitle, mTvTermsTitle, mTvRedeemTitle, mTVMoreTitle;
// ===========================================================
......@@ -85,6 +93,11 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis
public void onClick(View v) {
if (v.getId() == R.id.iv_back) {
onBackPressed();
return;
}
if (v.getId() == R.id.ll_redeem_coupon) {
mPbLoading.setVisibility(View.VISIBLE);
WarplyManager.retrieveCoupon(mOfferItem.getUuid(), mRetrieveCallback);
}
}
......@@ -93,9 +106,15 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis
// ===========================================================
private void initViews() {
mPbLoading = findViewById(R.id.pb_loading);
mPbLoading.setOnTouchListener((v, event) -> true);
mIvBack = findViewById(R.id.iv_back);
mIvBack.setOnClickListener(this);
mRedeemButton = findViewById(R.id.ll_redeem_coupon);
mRedeemButton.setOnClickListener(this);
// Initialize views
mTvSmallDescription = findViewById(R.id.tv_coupon_small_description);
mTvFullDescription = findViewById(R.id.tv_coupon_full_description);
......@@ -113,12 +132,11 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis
mTvHeaderTitle = findViewById(R.id.tv_header_title);
mTvTermsTitle = findViewById(R.id.tv_terms_title);
mTvShopsTitle = findViewById(R.id.tv_shops_title);
mTvWebsiteTitle = findViewById(R.id.tv_website_title);
mTvRedeemTitle = findViewById(R.id.tv_redeem_title);
mTVMoreTitle = findViewById(R.id.tv_more_title);
WarpUtils.renderCustomFont(this, R.font.ping_lcg_bold, mTvHeaderTitle, mTvValue,
mTvTermsTitle, mTvShopsTitle, mTvWebsiteTitle);
mTvTermsTitle, mTvRedeemTitle);
WarpUtils.renderCustomFont(this, R.font.ping_lcg_regular, mTvSmallDescription,
mTvEndDate, mTvFullDescription, mTvTermsText,
......@@ -250,4 +268,25 @@ public class SingleCouponsetActivity extends Activity implements View.OnClickLis
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
private final CallbackReceiver<JSONObject> mRetrieveCallback = new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
mPbLoading.setVisibility(View.GONE);
Toast.makeText(SingleCouponsetActivity.this, "RETRIEVE SUCCESS", Toast.LENGTH_SHORT).show();
Coupon coupon = new Coupon();
coupon.setCoupon(result.optString("coupon", ""));
coupon.setExpiration(result.optString("expiration", ""));
coupon.setCouponsetDetails(mOfferItem);
Intent myIntent = new Intent(SingleCouponsetActivity.this, SingleCouponActivity.class);
myIntent.putExtra(SingleCouponActivity.EXTRA_OFFER_ITEM, (Parcelable) coupon);
startActivity(myIntent);
}
@Override
public void onFailure(int errorCode) {
mPbLoading.setVisibility(View.GONE);
Toast.makeText(SingleCouponsetActivity.this, "RETRIEVE ERROR", Toast.LENGTH_SHORT).show();
}
};
}
......
......@@ -89,6 +89,18 @@ public interface ApiService {
@Header(WarpConstants.HEADER_AUTHORIZATION) String bearer);
@Headers("Content-Type: application/json")
@POST("/oauth/{appUuid}/context")
Call<ResponseBody> retrieveCoupon(@Path("appUuid") String appUuid,
@Body RequestBody request,
@Header(WarpConstants.HEADER_DATE) String timeStamp,
@Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId,
@Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId,
@Header(WarpConstants.HEADER_CHANNEL) String channel,
@Header(WarpConstants.HEADER_WEB_ID) String webId,
@Header(WarpConstants.HEADER_SIGNATURE) String signature,
@Header(WarpConstants.HEADER_AUTHORIZATION) String bearer);
@Headers("Content-Type: application/json")
@POST("/api/mobile/v2/{appUuid}/context/")
Call<ResponseBody> getCampaigns(@Path("appUuid") String appUuid,
@Body RequestBody request,
......
......@@ -1137,4 +1137,56 @@ public class WarplyManager {
}
}, null);
}
public static void retrieveCoupon(@NonNull String couponsetUuid, final CallbackReceiver<JSONObject> receiver) {
WarpUtils.log("************* WARPLY Retrieve Coupon Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Retrieve Coupon Request is active");
WarpUtils.log("**************************************************");
ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext());
String webId = WarpUtils.getWebId(Warply.getWarplyContext());
Map<String, Object> jsonParamsRetrieve = new ArrayMap<>();
Map<String, Object> jsonParams = new ArrayMap<>();
jsonParams.put("action", "retrieve_coupon");
jsonParams.put("coupon_set", couponsetUuid);
jsonParamsRetrieve.put("coupon", jsonParams);
RequestBody retrieveRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsRetrieve)).toString());
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"));
retrieveCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
if (response.code() == 200 && response.body() != null) {
JSONObject jobjRetrieveResponse = null;
try {
jobjRetrieveResponse = new JSONObject(response.body().string());
} catch (Exception e) {
e.printStackTrace();
}
if (jobjRetrieveResponse != null && jobjRetrieveResponse.has("status") && jobjRetrieveResponse.optString("status", "2").equals("1")) {
JSONObject result = jobjRetrieveResponse.optJSONObject("result");
if (result != null) {
receiver.onSuccess(result);
} else receiver.onFailure(2);
} else {
receiver.onFailure(2);
}
} else {
receiver.onFailure(response.code());
}
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
receiver.onFailure(2);
}
});
}
}
......
......@@ -251,24 +251,7 @@
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginTop="48dp"
android:background="@drawable/selector_button_black"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_shops_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/demo_shops"
android:textColor="@color/white"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_redeem_coupon"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginTop="20dp"
......@@ -277,10 +260,10 @@
android:orientation="horizontal">
<TextView
android:id="@+id/tv_website_title"
android:id="@+id/tv_redeem_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/demo_website"
android:text="@string/demo_redeem"
android:textColor="@color/custom_black2"
android:textSize="15sp"
android:textStyle="bold" />
......@@ -288,4 +271,22 @@
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="@+id/pb_loading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:translationZ="100dp"
android:visibility="gone"
android:layout_centerInParent="true"
tools:visibility="visible">
<ProgressBar
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_centerInParent="true"
android:indeterminate="true"
android:indeterminateTint="@color/custom_light_blue"
android:indeterminateTintMode="src_atop" />
</RelativeLayout>
</RelativeLayout>
......
......@@ -21,6 +21,7 @@
<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>
<string name="demo_shops">Καταστήματα κοντά μου</string>
<string name="demo_website">Δες το website</string>
<string name="demo_redeem">Απόκτησε το κουπόνι</string>
<string name="demo_profile">Το προφίλ μου</string>
<string name="demo_my_coupons">Τα κουπόνια μου</string>
<string name="demo_active">Ενεργά</string>
......