Panagiotis Triantafyllou

new unified coupons screen with basket part2, minor fixes

......@@ -140,7 +140,7 @@ public class ActiveCouponsActivity extends Activity implements View.OnClickListe
WarplyAnalyticsManager.logTrackersEvent(this, "click", ("Coupon").concat(":").concat(coupon.getName()));
Intent intent = new Intent(ActiveCouponsActivity.this, CouponInfoActivity.class);
intent.putExtra("coupon", coupon.getCoupon());
intent.putExtra("isFromWallet", true);
intent.putExtra("isFromWallet", false);
startActivity(intent);
}
})
......
......@@ -7,6 +7,7 @@ import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
......@@ -16,6 +17,7 @@ import androidx.recyclerview.widget.RecyclerView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.json.JSONArray;
import java.io.Serializable;
import java.text.ParseException;
......@@ -23,9 +25,12 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
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.UnifiedCoupon;
import ly.warp.sdk.utils.WarpUtils;
import ly.warp.sdk.utils.WarplyManagerHelper;
......@@ -51,11 +56,13 @@ public class ActiveUnifiedCouponsActivity extends Activity implements View.OnCli
private MarketCouponAdapter mAdapterUnifiedCoupons;
private TextView mTvEmptyUnifiedCoupons, mFontHeader, mTvInnerTitle,
mTvInnerSubtitle, mTvInnerClose, mTvUnifieCouponsTitle, mTvActiveUnifiedCouponsTitle,
mTvChooseAll;
mTvChooseAll, mTvActivate;
private boolean mUnifiedPressed = false, mActiveUnifiedPressed = false;
private ConstraintLayout mClInfoView, mClActiveCouponsHeader;
private RelativeLayout mRlUnifiedCoupons, mRlActiveUnifiedCoupons;
private ActiveCouponAdapter mAdapterCoupons;
private Set<Coupon> mSelectedItems = new HashSet<>();
private LinearLayout mLlActivateunified;
// ===========================================================
// Methods for/from SuperClass/Interfaces
......@@ -85,11 +92,13 @@ public class ActiveUnifiedCouponsActivity extends Activity implements View.OnCli
mTvActiveUnifiedCouponsTitle = mClActiveCouponsHeader.findViewById(R.id.tv_active_sm_coupons_title);
mTvChooseAll = mClActiveCouponsHeader.findViewById(R.id.tv_choose_all);
mIvChooseAll = mClActiveCouponsHeader.findViewById(R.id.iv_choose_all);
mLlActivateunified = findViewById(R.id.ll_activate_unified);
mTvActivate = mLlActivateunified.findViewById(R.id.button_activate);
WarpUtils.renderCustomFont(this, R.font.bt_cosmo_bold, mFontHeader, mTvInnerTitle,
mTvUnifieCouponsTitle, mTvActiveUnifiedCouponsTitle);
WarpUtils.renderCustomFont(this, R.font.peridot_regular, mTvEmptyUnifiedCoupons, mTvInnerSubtitle);
WarpUtils.renderCustomFont(this, R.font.peridot_bold, mTvInnerClose);
WarpUtils.renderCustomFont(this, R.font.peridot_semi_bold, mTvChooseAll);
WarpUtils.renderCustomFont(this, R.font.peridot_semi_bold, mTvChooseAll, mTvActivate);
initViews();
}
......@@ -144,7 +153,29 @@ public class ActiveUnifiedCouponsActivity extends Activity implements View.OnCli
return;
}
if (view.getId() == R.id.iv_choose_all) {
if (mSelectedItems.isEmpty() || (!mSelectedItems.isEmpty() && mSelectedItems.size() != mAdapterCoupons.getItemCount())) {
mSelectedItems.clear();
mSelectedItems.addAll(mAdapterCoupons.getItems());
mIvChooseAll.setBackgroundResource(R.drawable.ic_circle_checked_skyblue);
mLlActivateunified.setBackgroundResource(R.drawable.selector_button_green);
mAdapterCoupons.updateChecked(mSelectedItems);
} else if (mSelectedItems.size() == mAdapterCoupons.getItemCount()) {
mSelectedItems.clear();
mIvChooseAll.setBackgroundResource(R.drawable.ic_circle_gray);
mLlActivateunified.setBackgroundResource(R.drawable.selector_button_grey_dark);
mAdapterCoupons.updateChecked(mSelectedItems);
}
return;
}
if (view.getId() == R.id.ll_activate_unified) {
if (!mSelectedItems.isEmpty()) {
JSONArray tempArray = new JSONArray();
for (Coupon selectedCoupon : mSelectedItems) {
tempArray.put(selectedCoupon.getCoupon());
}
WarplyManager.createUnifiedCoupon(tempArray, mCreateUnifiedCallback);
}
}
}
......@@ -158,9 +189,15 @@ public class ActiveUnifiedCouponsActivity extends Activity implements View.OnCli
mIvInfoClose.setOnClickListener(this);
mTvInnerClose.setOnClickListener(this);
mIvChooseAll.setOnClickListener(this);
mLlActivateunified.setOnClickListener(this);
}
private void filterItems() {
mClInfoView.setVisibility(View.GONE);
mIvChooseAll.setBackgroundResource(R.drawable.ic_circle_gray);
mLlActivateunified.setBackgroundResource(R.drawable.selector_button_grey_dark);
mSelectedItems.clear();
if (WarplyManagerHelper.getMarketCouponsList() != null && WarplyManagerHelper.getMarketCouponsList().isEmpty()
&& WarplyManagerHelper.getSmCouponsList() != null && WarplyManagerHelper.getSmCouponsList().isEmpty()) {
mTvEmptyUnifiedCoupons.setVisibility(View.VISIBLE);
......@@ -212,7 +249,8 @@ public class ActiveUnifiedCouponsActivity extends Activity implements View.OnCli
mRvActiveUnifiedCoupons.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
mAdapterCoupons = new ActiveCouponAdapter(this, WarplyManagerHelper.getSmCouponsList(), false, false, true);
mRvActiveUnifiedCoupons.setAdapter(mAdapterCoupons);
mAdapterCoupons.getPositionClicks()
mAdapterCoupons
.getPositionClicks()
.doOnNext(coupon -> {
if (!mActiveUnifiedPressed) {
mActiveUnifiedPressed = true;
......@@ -229,6 +267,31 @@ public class ActiveUnifiedCouponsActivity extends Activity implements View.OnCli
})
.subscribe();
mAdapterCoupons
.getPositionCheck()
.doOnNext(coupon -> {
if (mSelectedItems.contains(coupon)) {
mSelectedItems.remove(coupon);
} else {
mSelectedItems.add(coupon);
}
if (mSelectedItems.size() != mAdapterCoupons.getItemCount()) {
mIvChooseAll.setBackgroundResource(R.drawable.ic_circle_gray);
} else {
mIvChooseAll.setBackgroundResource(R.drawable.ic_circle_checked_skyblue);
}
if (mSelectedItems.isEmpty()) {
mLlActivateunified.setBackgroundResource(R.drawable.selector_button_grey_dark);
} else {
mLlActivateunified.setBackgroundResource(R.drawable.selector_button_green);
}
})
.doOnError(error -> {
})
.subscribe();
mRlActiveUnifiedCoupons.setVisibility(View.VISIBLE);
} else {
mRlActiveUnifiedCoupons.setVisibility(View.GONE);
......@@ -251,4 +314,18 @@ public class ActiveUnifiedCouponsActivity extends Activity implements View.OnCli
}
};
private final CallbackReceiver<ArrayList<UnifiedCoupon>> mCreateUnifiedCallback = new CallbackReceiver<ArrayList<UnifiedCoupon>>() {
@Override
public void onSuccess(ArrayList<UnifiedCoupon> result) {
mIvChooseAll.setBackgroundResource(R.drawable.ic_circle_gray);
mLlActivateunified.setBackgroundResource(R.drawable.selector_button_grey_dark);
mSelectedItems.clear();
}
@Override
public void onFailure(int errorCode) {
}
};
}
......
......@@ -101,6 +101,7 @@ import ly.warp.sdk.io.models.NewCampaign;
import ly.warp.sdk.io.models.PacingDetails;
import ly.warp.sdk.io.models.PointsList;
import ly.warp.sdk.io.models.ProductList;
import ly.warp.sdk.io.models.RefreshUnifiedCouponsEventModel;
import ly.warp.sdk.io.models.SharingList;
import ly.warp.sdk.io.models.TagsCategoriesList;
import ly.warp.sdk.io.models.TagsList;
......@@ -3044,6 +3045,109 @@ public class WarplyManager {
});
}
private static void createUnifiedCouponsRetro(ApiService service, JSONArray couponCodes, Callback<ResponseBody> callback) {
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> jsonParamsCouponsets = new ArrayMap<>();
Map<String, Object> jsonParams = new ArrayMap<>();
jsonParams.put("action", "unify_coupons");
jsonParams.put("coupon_codes", couponCodes);
jsonParamsCouponsets.put("coupon", jsonParams);
RequestBody couponsetsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCouponsets)).toString());
Call<ResponseBody> unifiedCouponsCall = service.getCouponsets(
WarplyProperty.getAppUuid(Warply.getWarplyContext()),
couponsetsRequest,
timeStamp,
"android:" + Warply.getWarplyContext().getPackageName(),
new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(),
"mobile",
webId,
WarpUtils.produceSignature(apiKey + timeStamp),
"Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token")
);
unifiedCouponsCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
if (response.code() == 401) {
refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
int status = result.optInt("status", 2);
if (status == 1)
createUnifiedCouponsRetro(service, couponCodes, callback);
else
callback.onFailure(call, new Throwable());
}
@Override
public void onFailure(int errorCode) {
callback.onFailure(call, new Throwable());
}
});
} else {
callback.onResponse(call, response);
}
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
callback.onFailure(call, t);
}
});
}
public static void createUnifiedCoupon(JSONArray couponCodes, final CallbackReceiver<ArrayList<UnifiedCoupon>> receiver) {
WarpUtils.log("************* WARPLY Create Unified Coupons Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Create Unified Coupons Request is active");
WarpUtils.log("**************************************************");
ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
createUnifiedCouponsRetro(service, couponCodes, new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.code() == 200 && response.body() != null) {
JSONObject jobjUnifiedResponse = null;
try {
jobjUnifiedResponse = new JSONObject(response.body().string());
} catch (Exception e) {
e.printStackTrace();
}
if (jobjUnifiedResponse != null && jobjUnifiedResponse.has("status") && jobjUnifiedResponse.optString("status", "2").equals("1")) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_success_create_unified_coupons");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
RefreshUnifiedCouponsEventModel couponsRefreshed = new RefreshUnifiedCouponsEventModel();
EventBus.getDefault().post(new WarplyEventBusManager(couponsRefreshed));
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_create_unified_coupons");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(2);
}
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_create_unified_coupons");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(response.code());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_create_unified_coupons");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(2);
}
});
}
public static void getUnifiedCouponsDeals(final CallbackReceiver<ArrayList<UnifiedCoupon>> receiver) {
WarpUtils.log("************* WARPLY User Coupons Request ********************");
WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active");
......
......@@ -38,6 +38,7 @@ public class ActiveCouponAdapter extends RecyclerView.Adapter<ActiveCouponAdapte
private Context mContext;
private CouponList mCoupons;
private final PublishSubject<Coupon> onClickSubject = PublishSubject.create();
private final PublishSubject<Coupon> onCheckSubject = PublishSubject.create();
private boolean mIsPast = false, mIsCustom = false, mIsActiveSM = false;
private Set<Coupon> mSelectedItems = new HashSet<>();
......@@ -107,6 +108,10 @@ public class ActiveCouponAdapter extends RecyclerView.Adapter<ActiveCouponAdapte
return mCoupons.size();
}
public CouponList getItems() {
return mCoupons;
}
public Coupon getItem(int id) {
return mCoupons.get(id);
}
......@@ -117,6 +122,12 @@ public class ActiveCouponAdapter extends RecyclerView.Adapter<ActiveCouponAdapte
notifyDataSetChanged();
}
public void updateChecked(Set<Coupon> checkedList) {
mSelectedItems.clear();
mSelectedItems.addAll(checkedList);
notifyDataSetChanged();
}
@Override
public ActiveCouponViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView;
......@@ -253,6 +264,7 @@ public class ActiveCouponAdapter extends RecyclerView.Adapter<ActiveCouponAdapte
holder.ivChooseCoupon.setBackgroundResource(R.drawable.ic_circle_checked_skyblue);
holder.clActiveCustomLayout.setBackgroundResource(R.drawable.ic_coupon_background_new3_border_skyblue);
}
onCheckSubject.onNext(couponItem);
});
}
......@@ -350,6 +362,10 @@ public class ActiveCouponAdapter extends RecyclerView.Adapter<ActiveCouponAdapte
return onClickSubject.cache();
}
public Observable<Coupon> getPositionCheck() {
return onCheckSubject.cache();
}
private long getDifferenceDays(Date d1, Date d2) {
long diff = d2.getTime() - d1.getTime();
return TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
......
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/shape_cos_grey2_dark" android:state_pressed="true" />
<item android:drawable="@drawable/shape_cos_grey2_dark" android:state_pressed="false" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="16dp" />
<solid
android:width="2dp"
android:color="@color/cos_gray" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="16dp" />
<solid
android:width="2dp"
android:color="@color/cos_gray_tr" />
</shape>
\ No newline at end of file
......@@ -139,7 +139,19 @@
</androidx.constraintlayout.widget.ConstraintLayout>
<!-- android:background="@drawable/shape_cos_loyalty"-->
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cl_bill_header"
app:layout_constraintBottom_toBottomOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="80dp">
<RelativeLayout
android:id="@+id/rl_unified_coupons"
android:layout_width="match_parent"
......@@ -147,9 +159,6 @@
android:background="@color/cos_light_grey3"
android:orientation="vertical"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cl_bill_header"
tools:visibility="visible">
<TextView
......@@ -181,12 +190,10 @@
android:id="@+id/rl_active_unified_coupons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/rl_unified_coupons"
android:background="@color/cos_light_grey3"
android:orientation="vertical"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rl_unified_coupons"
tools:visibility="visible">
<androidx.constraintlayout.widget.ConstraintLayout
......@@ -234,7 +241,7 @@
android:layout_height="28dp"
android:layout_marginStart="8dp"
android:scaleType="fitXY"
android:src="@drawable/ic_circle_gray" />
tools:src="@drawable/ic_circle_gray" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
......@@ -249,6 +256,8 @@
android:paddingVertical="16dp"
android:scrollbars="none" />
</RelativeLayout>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
<TextView
android:id="@+id/tv_no_unified_coupons"
......@@ -266,4 +275,29 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cl_bill_header" />
<LinearLayout
android:id="@+id/ll_activate_unified"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_marginHorizontal="24dp"
android:layout_marginBottom="24dp"
android:background="@drawable/selector_button_grey_dark"
android:gravity="center"
android:paddingVertical="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:id="@+id/button_activate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:includeFontPadding="false"
android:text="@string/cos_activate_unified"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......
......@@ -69,6 +69,7 @@
<color name="cos_green12">#0EA600</color>
<color name="cos_green6_tr">#660EA600</color>
<color name="cos_gray">#9D9D9C</color>
<color name="cos_gray_tr">#669D9D9C</color>
<color name="cos_gray2">#848484</color>
<color name="cos_light_blue">#00A5E3</color>
<color name="cos_grey_dark2">#32485A</color>
......
......@@ -82,6 +82,7 @@
<string name="cos_popup_gifts_subtitle">Σε αυτή την ενότητα βρίσκεις τα διαθέσιμα δώρα και επιβραβεύσεις αποκλειστικά για σένα!</string>
<string name="cos_mycoupon_date">Το κουπόνι ισχύει έως %1$s</string>
<string name="cos_gift_it">Δώρισέ το</string>
<string name="cos_activate_unified">Συνδύασε τις προσφορές σε ένα κουπόνι</string>
<string name="cos_popup_more_title">COSMOTE MORE FOR YOU</string>
<string name="cos_popup_more_subtitle">Σε αυτή την ενότητα βρες έρευνες, παιχνίδια, διαγωνισμούς και επιβραβεύσεις για τις αθλητικές σου δραστηριότητες!</string>
<string name="cos_deals_win_title">Μέχρι τώρα έχεις όφελος %1$s€ από τα FREE COUPONS</string>
......