Panagiotis Triantafyllou

redesign supermarket part1

Showing 23 changed files with 847 additions and 2 deletions
...@@ -104,6 +104,9 @@ dependencies { ...@@ -104,6 +104,9 @@ dependencies {
104 //------------------------------ Retrofit -----------------------------// 104 //------------------------------ Retrofit -----------------------------//
105 implementation 'com.squareup.retrofit2:retrofit:2.9.0' 105 implementation 'com.squareup.retrofit2:retrofit:2.9.0'
106 implementation 'com.squareup.retrofit2:converter-gson:2.9.0' 106 implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
107 +
108 + //------------------------------ Expandable Layout -----------------------------//
109 + api 'net.cachapa.expandablelayout:expandablelayout:2.9.2'
107 } 110 }
108 111
109 // In every export please update the version number 112 // In every export please update the version number
......
...@@ -48,6 +48,18 @@ ...@@ -48,6 +48,18 @@
48 android:theme="@style/SDKAppTheme" /> 48 android:theme="@style/SDKAppTheme" />
49 49
50 <activity 50 <activity
51 + android:name="ly.warp.sdk.activities.LoyaltyMarketAnalysisActivity"
52 + android:exported="false"
53 + android:screenOrientation="portrait"
54 + android:theme="@style/SDKAppTheme" />
55 +
56 + <activity
57 + android:name="ly.warp.sdk.activities.UnifiedCouponInfoActivity"
58 + android:exported="false"
59 + android:screenOrientation="portrait"
60 + android:theme="@style/SDKAppTheme" />
61 +
62 + <activity
51 android:name="ly.warp.sdk.activities.ActiveCouponsActivity" 63 android:name="ly.warp.sdk.activities.ActiveCouponsActivity"
52 android:exported="false" 64 android:exported="false"
53 android:screenOrientation="portrait" 65 android:screenOrientation="portrait"
......
1 +/*
2 + * Copyright 2010-2013 Warply Ltd. All rights reserved.
3 + *
4 + * Redistribution and use in source and binary forms, without modification, are
5 + * permitted provided that the following conditions are met:
6 + *
7 + * 1. Redistributions of source code must retain the above copyright notice,
8 + * this list of conditions and the following disclaimer.
9 + *
10 + * 2. Redistributions in binary form must reproduce the above copyright notice,
11 + * this list of conditions and the following disclaimer in the documentation
12 + * and/or other materials provided with the distribution.
13 + *
14 + * THIS SOFTWARE IS PROVIDED BY THE WARPLY LTD ``AS IS'' AND ANY EXPRESS OR
15 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
17 + * EVENT SHALL WARPLY LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20 + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23 + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 + */
25 +
26 +package ly.warp.sdk.io.models;
27 +
28 +import android.os.Parcel;
29 +import android.os.Parcelable;
30 +
31 +import org.json.JSONArray;
32 +import org.json.JSONException;
33 +import org.json.JSONObject;
34 +
35 +import java.io.Serializable;
36 +import java.util.ArrayList;
37 +import java.util.Date;
38 +
39 +import ly.warp.sdk.utils.WarpUtils;
40 +import ly.warp.sdk.utils.constants.WarpConstants;
41 +
42 +/**
43 + * Created by Panagiotis Triantafyllou on 04-Apr-23.
44 + */
45 +
46 +public class UnifiedCoupon implements Parcelable, Serializable {
47 +
48 + private static final long serialVersionUID = -4754964462459705285L;
49 +
50 + /* Constants used to export the campaign in JSON formal and vice versa */
51 +
52 + private static final String BARCODE = "barcode";
53 + private static final String CODE = "code";
54 + private static final String CREATED = "created";
55 + private static final String COUPONS = "coupons";
56 + private static final String STATUS = "status";
57 + private static final String DESCRIPTION = "description";
58 +
59 + /* Member variables of the Campaign object */
60 +
61 + private String barcode = "";
62 + private String description = "";
63 + private String status = "";
64 + private int code = 0;
65 + private String created = "";
66 + private ArrayList<Coupon> coupons = new ArrayList();
67 + private Date expirationDate = new Date();
68 +
69 + public UnifiedCoupon() {
70 + this.barcode = "";
71 + this.description = "";
72 + this.status = "";
73 + this.code = 0;
74 + this.created = "";
75 + this.coupons = new ArrayList();
76 + this.expirationDate = new Date();
77 + }
78 +
79 + /**
80 + * Basic constructor used to create an object from a String, representing a
81 + * JSON Object
82 + *
83 + * @param json The String, representing the JSON Object
84 + * @throws JSONException Thrown if the String cannot be converted to JSON
85 + */
86 + public UnifiedCoupon(String json) throws JSONException {
87 + this(new JSONObject(json));
88 + }
89 +
90 + /**
91 + * Constructor used to create an Object from a given JSON Object
92 + *
93 + * @param json JSON Object used to create the Coupon
94 + */
95 + public UnifiedCoupon(JSONObject json) {
96 + if (json != null) {
97 + this.barcode = json.optString(BARCODE);
98 + this.description = json.optString(DESCRIPTION);
99 + this.status = json.optString(STATUS);
100 + this.code = json.optInt(CODE);
101 + this.created = json.optString(CREATED);
102 + JSONArray jArray = null;
103 + jArray = json.optJSONArray(COUPONS);
104 + if (jArray != null && jArray.length() > 0) {
105 + for (int i = 0; i < jArray.length(); i++) {
106 + JSONObject jObj = jArray.optJSONObject(i);
107 + this.coupons.add(new Coupon(jObj));
108 + }
109 + }
110 + }
111 + }
112 +
113 + public UnifiedCoupon(Parcel source) {
114 + this.barcode = source.readString();
115 + this.description = source.readString();
116 + this.status = source.readString();
117 + this.code = source.readInt();
118 + this.created = source.readString();
119 + }
120 +
121 + @Override
122 + public void writeToParcel(Parcel dest, int flags) {
123 + dest.writeString(this.barcode);
124 + dest.writeString(this.description);
125 + dest.writeString(this.status);
126 + dest.writeInt(this.code);
127 + dest.writeString(this.created);
128 + }
129 +
130 + /**
131 + * Converts the Unified Coupon into a JSON Object
132 + *
133 + * @return The JSON Object created from this Unified Coupon
134 + */
135 + public JSONObject toJSONObject() {
136 + JSONObject jObj = new JSONObject();
137 + try {
138 + jObj.putOpt(BARCODE, this.barcode);
139 + jObj.putOpt(DESCRIPTION, this.description);
140 + jObj.putOpt(STATUS, this.status);
141 + jObj.putOpt(CODE, this.code);
142 + jObj.putOpt(CREATED, this.created);
143 + jObj.putOpt(COUPONS, this.coupons);
144 + } catch (JSONException e) {
145 + if (WarpConstants.DEBUG) {
146 + e.printStackTrace();
147 + }
148 + }
149 + return jObj;
150 + }
151 +
152 + /**
153 + * String representation of the Unified Coupon, as a JSON object
154 + *
155 + * @return A String representation of JSON object
156 + */
157 + public String toString() {
158 + if (toJSONObject() != null)
159 + return toJSONObject().toString();
160 + return null;
161 + }
162 +
163 + /**
164 + * String representation of the Coupon, as a human readable JSON object
165 + *
166 + * @return A human readable String representation of JSON object
167 + */
168 + public String toHumanReadableString() {
169 + String humanReadableString = null;
170 + try {
171 + humanReadableString = toJSONObject().toString(2);
172 + } catch (JSONException e) {
173 + WarpUtils.warn("Failed converting Unified Coupon JSON object to String", e);
174 + }
175 + return humanReadableString;
176 + }
177 +
178 + // ================================================================================
179 + // Getters
180 + // ================================================================================
181 +
182 +
183 + public String getBarcode() {
184 + return barcode;
185 + }
186 +
187 + public void setBarcode(String barcode) {
188 + this.barcode = barcode;
189 + }
190 +
191 + public int getCode() {
192 + return code;
193 + }
194 +
195 + public void setCode(int code) {
196 + this.code = code;
197 + }
198 +
199 + public String getCreated() {
200 + return created;
201 + }
202 +
203 + public void setCreated(String created) {
204 + this.created = created;
205 + }
206 +
207 + public ArrayList<Coupon> getCoupons() {
208 + return coupons;
209 + }
210 +
211 + public void setCoupons(ArrayList<Coupon> coupons) {
212 + this.coupons = coupons;
213 + }
214 +
215 + public String getStatus() {
216 + return status;
217 + }
218 +
219 + public void setStatus(String status) {
220 + this.status = status;
221 + }
222 +
223 + public String getDescription() {
224 + return description;
225 + }
226 +
227 + public void setDescription(String description) {
228 + this.description = description;
229 + }
230 +
231 + public Date getExpirationDate() {
232 + return expirationDate;
233 + }
234 +
235 + public void setExpirationDate(Date expirationDate) {
236 + this.expirationDate = expirationDate;
237 + }
238 +
239 + @Override
240 + public int describeContents() {
241 + return 0;
242 + }
243 +
244 + public static final Creator<UnifiedCoupon> CREATOR = new Creator<UnifiedCoupon>() {
245 + public UnifiedCoupon createFromParcel(Parcel source) {
246 + return new UnifiedCoupon(source);
247 + }
248 +
249 + public UnifiedCoupon[] newArray(int size) {
250 + return new UnifiedCoupon[size];
251 + }
252 + };
253 +}
...@@ -54,6 +54,18 @@ public interface ApiService { ...@@ -54,6 +54,18 @@ public interface ApiService {
54 @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer); 54 @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer);
55 55
56 @Headers("Content-Type: application/json") 56 @Headers("Content-Type: application/json")
57 + @POST("/oauth/{appUuid}/context")
58 + Call<ResponseBody> getUnifiedCoupons(@Path("appUuid") String appUuid,
59 + @Body RequestBody request,
60 + @Header(WarpConstants.HEADER_DATE) String timeStamp,
61 + @Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId,
62 + @Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId,
63 + @Header(WarpConstants.HEADER_CHANNEL) String channel,
64 + @Header(WarpConstants.HEADER_WEB_ID) String webId,
65 + @Header(WarpConstants.HEADER_SIGNATURE) String signature,
66 + @Header(WarpConstants.HEADER_AUTHORIZATION) String bearer);
67 +
68 + @Headers("Content-Type: application/json")
57 @POST("/api/mobile/v2/{appUuid}/context/") 69 @POST("/api/mobile/v2/{appUuid}/context/")
58 Call<ResponseBody> getMerchants(@Path("appUuid") String appUuid, 70 Call<ResponseBody> getMerchants(@Path("appUuid") String appUuid,
59 @Body RequestBody request, 71 @Body RequestBody request,
......
...@@ -74,6 +74,7 @@ import ly.warp.sdk.io.models.LoyaltyGiftsForYouPackage; ...@@ -74,6 +74,7 @@ import ly.warp.sdk.io.models.LoyaltyGiftsForYouPackage;
74 import ly.warp.sdk.io.models.LoyaltySDKFirebaseEventModel; 74 import ly.warp.sdk.io.models.LoyaltySDKFirebaseEventModel;
75 import ly.warp.sdk.io.models.MerchantList; 75 import ly.warp.sdk.io.models.MerchantList;
76 import ly.warp.sdk.io.models.PushCampaign; 76 import ly.warp.sdk.io.models.PushCampaign;
77 +import ly.warp.sdk.io.models.UnifiedCoupon;
77 import ly.warp.sdk.io.models.WarplyCouponsChangedEventModel; 78 import ly.warp.sdk.io.models.WarplyCouponsChangedEventModel;
78 import ly.warp.sdk.io.request.CosmoteRetrieveSharingRequest; 79 import ly.warp.sdk.io.request.CosmoteRetrieveSharingRequest;
79 import ly.warp.sdk.io.request.CosmoteSharingRequest; 80 import ly.warp.sdk.io.request.CosmoteSharingRequest;
...@@ -123,6 +124,7 @@ public class WarplyManagerHelper { ...@@ -123,6 +124,7 @@ public class WarplyManagerHelper {
123 public static double mMetersWebview = 0.0d; 124 public static double mMetersWebview = 0.0d;
124 public static int mStepsWebview = 0; 125 public static int mStepsWebview = 0;
125 public static int mSteps = 0; 126 public static int mSteps = 0;
127 + private static ArrayList<UnifiedCoupon> mMarketCoupons = new ArrayList<>();
126 128
127 // =========================================================== 129 // ===========================================================
128 // Methods for/from SuperClass/Interfaces 130 // Methods for/from SuperClass/Interfaces
...@@ -1247,6 +1249,13 @@ public class WarplyManagerHelper { ...@@ -1247,6 +1249,13 @@ public class WarplyManagerHelper {
1247 mDealsSum = sum; 1249 mDealsSum = sum;
1248 } 1250 }
1249 1251
1252 + public static ArrayList<UnifiedCoupon> getMarketCoupons() {
1253 + return mMarketCoupons;
1254 + }
1255 + public static void setMarketCoupons( ArrayList<UnifiedCoupon> marketCoupons) {
1256 + mMarketCoupons = marketCoupons;
1257 + }
1258 +
1250 public static boolean checkForLoyaltySDKNotification(Context context, Map<String, String> pushPayload) { 1259 public static boolean checkForLoyaltySDKNotification(Context context, Map<String, String> pushPayload) {
1251 Bundle data = convertToBundle(pushPayload); 1260 Bundle data = convertToBundle(pushPayload);
1252 if (data == null || !data.containsKey("loyalty-action")) 1261 if (data == null || !data.containsKey("loyalty-action"))
......
...@@ -97,6 +97,7 @@ import ly.warp.sdk.io.models.SharingList; ...@@ -97,6 +97,7 @@ import ly.warp.sdk.io.models.SharingList;
97 import ly.warp.sdk.io.models.TagsCategoriesList; 97 import ly.warp.sdk.io.models.TagsCategoriesList;
98 import ly.warp.sdk.io.models.TagsList; 98 import ly.warp.sdk.io.models.TagsList;
99 import ly.warp.sdk.io.models.TransactionsList; 99 import ly.warp.sdk.io.models.TransactionsList;
100 +import ly.warp.sdk.io.models.UnifiedCoupon;
100 import ly.warp.sdk.io.models.WarplyPacingEventModel; 101 import ly.warp.sdk.io.models.WarplyPacingEventModel;
101 import ly.warp.sdk.io.request.CosmoteCouponSharingRequest; 102 import ly.warp.sdk.io.request.CosmoteCouponSharingRequest;
102 import ly.warp.sdk.io.request.CosmotePostEventRequest; 103 import ly.warp.sdk.io.request.CosmotePostEventRequest;
...@@ -1892,6 +1893,71 @@ public class WarplyManager { ...@@ -1892,6 +1893,71 @@ public class WarplyManager {
1892 }); 1893 });
1893 } 1894 }
1894 1895
1896 + public static void getUnifiedCoupons(final CallbackReceiver<ArrayList<UnifiedCoupon>> receiver) {
1897 + WarpUtils.log("************* WARPLY User Coupons Request ********************");
1898 + WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active");
1899 + WarpUtils.log("**************************************************");
1900 + ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
1901 + getUnifiedCouponsRetro(service, new Callback<ResponseBody>() {
1902 + @Override
1903 + public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> responseCoupons) {
1904 + if (responseCoupons.code() == 200 && responseCoupons.body() != null) {
1905 + JSONObject jobjCouponsResponse = null;
1906 + try {
1907 + jobjCouponsResponse = new JSONObject(responseCoupons.body().string());
1908 + } catch (Exception e) {
1909 + e.printStackTrace();
1910 + }
1911 + if (jobjCouponsResponse != null && jobjCouponsResponse.has("status") && jobjCouponsResponse.optInt("status", 2) == 1) {
1912 + ArrayList<UnifiedCoupon> couponList = new ArrayList<UnifiedCoupon>();
1913 + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
1914 + dynatraceEvent.setEventName("custom_success_unified_coupons_loyalty");
1915 + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
1916 + JSONObject finalJobjCouponsResponse = jobjCouponsResponse;
1917 + final ExecutorService executor = Executors.newFixedThreadPool(1);
1918 + executor.submit(() -> {
1919 + JSONObject jCouponsBody = null;
1920 + try {
1921 + jCouponsBody = finalJobjCouponsResponse.optJSONObject("result");
1922 + if (jCouponsBody != null && jCouponsBody.length() > 0) {
1923 + JSONArray jCouponsInnerBody = null;
1924 + jCouponsInnerBody = jCouponsBody.optJSONArray("coupons");
1925 + if (jCouponsInnerBody != null && jCouponsInnerBody.length() > 0) {
1926 + for (int i = 0; i < jCouponsInnerBody.length(); i++) {
1927 + couponList.add(new UnifiedCoupon(jCouponsInnerBody.optJSONObject(i)));
1928 + }
1929 + }
1930 + }
1931 + } catch (Exception e) {
1932 + e.printStackTrace();
1933 + }
1934 + new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(couponList));
1935 + executor.shutdownNow();
1936 + });
1937 + } else {
1938 + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
1939 + dynatraceEvent.setEventName("custom_error_unified_coupons_loyalty");
1940 + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
1941 + receiver.onFailure(2);
1942 + }
1943 + } else {
1944 + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
1945 + dynatraceEvent.setEventName("custom_error_unified_coupons_loyalty");
1946 + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
1947 + receiver.onFailure(responseCoupons.code());
1948 + }
1949 + }
1950 +
1951 + @Override
1952 + public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
1953 + LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
1954 + dynatraceEvent.setEventName("custom_error_user_coupons_loyalty");
1955 + EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
1956 + receiver.onFailure(2);
1957 + }
1958 + });
1959 + }
1960 +
1895 public static void getUserCouponsWithCouponsets(WarplyUserCouponsRequest request, final CallbackReceiver<CouponList> receiver) { 1961 public static void getUserCouponsWithCouponsets(WarplyUserCouponsRequest request, final CallbackReceiver<CouponList> receiver) {
1896 WarpUtils.log("************* WARPLY User Coupons Request ********************"); 1962 WarpUtils.log("************* WARPLY User Coupons Request ********************");
1897 WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active"); 1963 WarpUtils.log("[WARP Trace] WARPLY User Coupons Request is active");
...@@ -2248,6 +2314,58 @@ public class WarplyManager { ...@@ -2248,6 +2314,58 @@ public class WarplyManager {
2248 }); 2314 });
2249 } 2315 }
2250 2316
2317 + private static void getUnifiedCouponsRetro(ApiService service, Callback<ResponseBody> callback) {
2318 + String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
2319 + String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext());
2320 + String webId = WarpUtils.getWebId(Warply.getWarplyContext());
2321 + Map<String, Object> jsonParamsCouponsets = new ArrayMap<>();
2322 + Map<String, Object> jsonParams = new ArrayMap<>();
2323 + jsonParams.put("action", "retrieve_unified_coupons");
2324 + jsonParams.put("language", WarplyProperty.getLanguage(Warply.getWarplyContext()));
2325 + jsonParamsCouponsets.put("coupon", jsonParams);
2326 + RequestBody unifiedCouponsRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParamsCouponsets)).toString());
2327 + Call<ResponseBody> unifiedCouponsCall = service.getUnifiedCoupons(
2328 + WarplyProperty.getAppUuid(Warply.getWarplyContext()),
2329 + unifiedCouponsRequest,
2330 + timeStamp,
2331 + "android:" + Warply.getWarplyContext().getPackageName(),
2332 + new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(),
2333 + "mobile",
2334 + webId,
2335 + WarpUtils.produceSignature(apiKey + timeStamp),
2336 + "Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token")
2337 + );
2338 + unifiedCouponsCall.enqueue(new Callback<ResponseBody>() {
2339 + @Override
2340 + public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
2341 + if (response.code() == 401) {
2342 + refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() {
2343 + @Override
2344 + public void onSuccess(JSONObject result) {
2345 + int status = result.optInt("status", 2);
2346 + if (status == 1)
2347 + getUnifiedCouponsRetro(service, callback);
2348 + else
2349 + callback.onFailure(call, new Throwable());
2350 + }
2351 +
2352 + @Override
2353 + public void onFailure(int errorCode) {
2354 + callback.onFailure(call, new Throwable());
2355 + }
2356 + });
2357 + } else {
2358 + callback.onResponse(call, response);
2359 + }
2360 + }
2361 +
2362 + @Override
2363 + public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
2364 + callback.onFailure(call, t);
2365 + }
2366 + });
2367 + }
2368 +
2251 private static void getMerchantsRetro(ApiService service, Callback<ResponseBody> callback) { 2369 private static void getMerchantsRetro(ApiService service, Callback<ResponseBody> callback) {
2252 String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); 2370 String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
2253 String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext()); 2371 String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext());
......
1 +package ly.warp.sdk.views.adapters;
2 +
3 +import android.content.Context;
4 +import android.view.LayoutInflater;
5 +import android.view.View;
6 +import android.view.ViewGroup;
7 +import android.widget.ImageView;
8 +import android.widget.TextView;
9 +
10 +import androidx.recyclerview.widget.RecyclerView;
11 +
12 +import java.text.ParseException;
13 +import java.text.SimpleDateFormat;
14 +import java.util.ArrayList;
15 +import java.util.Collections;
16 +import java.util.Date;
17 +import java.util.concurrent.TimeUnit;
18 +
19 +import io.reactivex.Observable;
20 +import io.reactivex.subjects.PublishSubject;
21 +import ly.warp.sdk.R;
22 +import ly.warp.sdk.io.models.Coupon;
23 +import ly.warp.sdk.io.models.UnifiedCoupon;
24 +
25 +public class MarketCouponAdapter extends RecyclerView.Adapter<MarketCouponAdapter.ActiveCouponViewHolder> {
26 +
27 + private Context mContext;
28 + private ArrayList<UnifiedCoupon> mCoupons;
29 + private final PublishSubject<UnifiedCoupon> onClickSubject = PublishSubject.create();
30 + private boolean mIsPast = false;
31 +
32 + public MarketCouponAdapter(Context mContext, ArrayList<UnifiedCoupon> campaignList) {
33 + this.mContext = mContext;
34 + this.mCoupons = campaignList;
35 + this.mIsPast = false;
36 + }
37 +
38 + public MarketCouponAdapter(Context mContext, ArrayList<UnifiedCoupon> campaignList, boolean past) {
39 + this.mContext = mContext;
40 + this.mCoupons = campaignList;
41 + this.mIsPast = past;
42 + }
43 +
44 + public class ActiveCouponViewHolder extends RecyclerView.ViewHolder {
45 + private ImageView ivCouponBackground;
46 + private TextView tvCouponTitle, tvCouponDate, tvCouponCount;
47 +
48 + public ActiveCouponViewHolder(View view) {
49 + super(view);
50 + ivCouponBackground = view.findViewById(R.id.iv_past_coupon_background);
51 + tvCouponTitle = view.findViewById(R.id.tv_market_coupons_title);
52 + tvCouponDate = view.findViewById(R.id.tv_market_coupons_date);
53 + tvCouponCount = view.findViewById(R.id.tv_market_coupons_count);
54 + }
55 + }
56 +
57 + @Override
58 + public int getItemCount() {
59 + if (mCoupons == null)
60 + return 0;
61 + else
62 + return mCoupons.size();
63 + }
64 +
65 +
66 + public UnifiedCoupon getItem(int id) {
67 + return mCoupons.get(id);
68 + }
69 +
70 + public void updateData(ArrayList<UnifiedCoupon> couponList) {
71 + mCoupons.clear();
72 + mCoupons.addAll(couponList);
73 + notifyDataSetChanged();
74 + }
75 +
76 +
77 + @Override
78 + public ActiveCouponViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
79 + View itemView;
80 + if (mIsPast)
81 + itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.past_coupon_layout, parent, false);
82 + else
83 + itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.market_coupon_layout, parent, false);
84 + return new ActiveCouponViewHolder(itemView);
85 + }
86 +
87 + @Override
88 + public void onBindViewHolder(final ActiveCouponViewHolder holder, int position) {
89 + UnifiedCoupon couponItem = mCoupons.get(position);
90 +
91 + if (couponItem != null) {
92 + int count = 0;
93 + if (couponItem.getCoupons() != null && couponItem.getCoupons().size() > 0) {
94 + ArrayList<Coupon> couponList = new ArrayList<Coupon>();
95 + for (Coupon item : couponItem.getCoupons()) {
96 + if (item.getStatus() == 1) {
97 + count++;
98 + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
99 + Date newDate = new Date();
100 + try {
101 + newDate = simpleDateFormat.parse(item.getExpiration());
102 + } catch (ParseException e) {
103 + e.printStackTrace();
104 + }
105 + item.setExpirationDate(newDate);
106 + couponList.add(item);
107 + }
108 + }
109 +
110 + Collections.sort(couponList, (coupon1, coupon2) -> coupon1.getExpirationDate().compareTo(coupon2.getExpirationDate()));
111 +
112 + if (couponList != null && couponList.size() > 0) {
113 + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
114 + Date newDate = new Date();
115 + try {
116 + newDate = simpleDateFormat.parse(couponList.get(0).getExpiration());
117 + } catch (ParseException e) {
118 + e.printStackTrace();
119 + }
120 + simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
121 + holder.tvCouponDate.setText(String.format(mContext.getString(R.string.cos_coupon_date), simpleDateFormat.format(newDate != null ? newDate : "")));
122 + }
123 + }
124 +
125 + if (count > 1) {
126 + holder.tvCouponCount.setText(String.format(mContext.getString(R.string.cos_market_active_coupons), String.valueOf(count)));
127 + } else if (count == 1) {
128 + holder.tvCouponCount.setText(String.format(mContext.getString(R.string.cos_market_active_coupons_single), String.valueOf(count)));
129 + }
130 +
131 +
132 +// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
133 +// Date newDate = new Date();
134 +// try {
135 +// newDate = simpleDateFormat.parse(couponItem.getExpiration());
136 +// } catch (ParseException e) {
137 +// e.printStackTrace();
138 +// }
139 +// simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
140 +// if (mIsPast)
141 +// holder.tvCouponDate.setText(String.format(mContext.getString(R.string.cos_coupon_expired_date), simpleDateFormat.format(newDate != null ? newDate : "")));
142 +// else
143 +// holder.tvCouponDate.setText(String.format(mContext.getString(R.string.cos_coupon_date), simpleDateFormat.format(newDate != null ? newDate : "")));
144 +
145 +// if (TextUtils.isEmpty(couponItem.getDiscount_type())) {
146 +// holder.tvCouponValue.setText(couponItem.getDiscount() + mContext.getResources().getString(R.string.euro));
147 +// } else {
148 +// if (couponItem.getDiscount_type().equals("value")) {
149 +// holder.tvCouponValue.setText(couponItem.getDiscount() + mContext.getResources().getString(R.string.euro));
150 +// } else if (couponItem.getDiscount_type().equals("percentage")) {
151 +// holder.tvCouponValue.setText(couponItem.getDiscount() + mContext.getResources().getString(R.string.percentage));
152 +// } else if (couponItem.getDiscount_type().equals("plus_one")) {
153 +// holder.tvCouponValue.setText(couponItem.getDiscount() + mContext.getResources().getString(R.string.plus_one));
154 +// } else {
155 +// holder.tvCouponValue.setText(couponItem.getDiscount() + mContext.getResources().getString(R.string.euro));
156 +// }
157 +// }
158 + holder.itemView.setOnClickListener(v -> onClickSubject.onNext(couponItem));
159 + }
160 + }
161 +
162 + public Observable<UnifiedCoupon> getPositionClicks() {
163 + return onClickSubject.cache();
164 + }
165 +
166 + private long getDifferenceDays(Date d1, Date d2) {
167 + long diff = d2.getTime() - d1.getTime();
168 + return TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
169 + }
170 +}
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<shape xmlns:android="http://schemas.android.com/apk/res/android">
3 + <solid android:color="#F0E6E6"/>
4 + <corners android:radius="10dp"/>
5 + <padding android:left="4dp" android:top="2dp" android:right="4dp" android:bottom="2dp" />
6 +</shape>
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 + xmlns:app="http://schemas.android.com/apk/res-auto"
4 + xmlns:tools="http://schemas.android.com/tools"
5 + android:id="@+id/cl_custom_layout"
6 + android:layout_width="match_parent"
7 + android:layout_height="130dp"
8 + android:layout_marginHorizontal="4dp"
9 + android:layout_marginVertical="4dp"
10 + android:background="@drawable/ic_coupon_background">
11 +
12 + <androidx.constraintlayout.widget.Guideline
13 + android:id="@+id/gl_vertical_72_percent"
14 + android:layout_width="wrap_content"
15 + android:layout_height="wrap_content"
16 + android:orientation="vertical"
17 + app:layout_constraintGuide_percent="0.72" />
18 +
19 + <ImageView
20 + android:id="@+id/iv_active_coupon"
21 + android:layout_width="80dp"
22 + android:layout_height="80dp"
23 + android:layout_marginStart="24dp"
24 + app:layout_constraintBottom_toBottomOf="parent"
25 + app:layout_constraintStart_toStartOf="parent"
26 + app:layout_constraintTop_toTopOf="parent"
27 + tools:src="@drawable/ic_gifts_for_you" />
28 +
29 + <View
30 + android:id="@+id/v_separator"
31 + android:layout_width="1dp"
32 + android:layout_height="match_parent"
33 + android:layout_marginVertical="16dp"
34 + android:layout_marginStart="8dp"
35 + android:background="@drawable/shape_dashed_vertical"
36 + app:layout_constraintBottom_toBottomOf="parent"
37 + app:layout_constraintStart_toEndOf="@+id/iv_active_coupon"
38 + app:layout_constraintTop_toTopOf="parent" />
39 +
40 + <LinearLayout
41 + android:id="@+id/ll_coupon_info"
42 + android:layout_width="0dp"
43 + android:layout_height="wrap_content"
44 + android:layout_marginStart="16dp"
45 + android:orientation="vertical"
46 + app:layout_constraintBottom_toBottomOf="parent"
47 + app:layout_constraintEnd_toStartOf="@+id/gl_vertical_72_percent"
48 + app:layout_constraintStart_toEndOf="@+id/v_separator"
49 + app:layout_constraintTop_toTopOf="parent">
50 +
51 + <TextView
52 + android:id="@+id/tv_active_coupons_title"
53 + fontPath="fonts/pf_square_sans_pro_medium.ttf"
54 + android:layout_width="wrap_content"
55 + android:layout_height="wrap_content"
56 + android:ellipsize="end"
57 + android:maxLines="1"
58 + android:textColor="#3A5266"
59 + android:textSize="16sp"
60 + tools:text="Εκπτωτικο κουπονι 10$ για αγορες στα ΙΚΕΑ" />
61 +
62 + <TextView
63 + android:id="@+id/tv_active_coupons_value"
64 + fontPath="fonts/pf_square_sans_pro_bold.ttf"
65 + android:layout_width="wrap_content"
66 + android:layout_height="wrap_content"
67 + android:textColor="#3A5266"
68 + android:textSize="42sp"
69 + tools:text="10$" />
70 +
71 + <TextView
72 + android:id="@+id/tv_active_coupons_date"
73 + fontPath="fonts/pf_square_sans_pro_medium.ttf"
74 + android:layout_width="wrap_content"
75 + android:layout_height="wrap_content"
76 + android:textColor="#617181"
77 + android:textSize="12sp"
78 + android:visibility="gone"
79 + tools:text="@string/cos_active_coupon_date" />
80 +
81 + <TextView
82 + android:id="@+id/tv_active_coupons_date_expired"
83 + fontPath="fonts/pf_square_sans_pro_bold.ttf"
84 + android:layout_width="wrap_content"
85 + android:layout_height="wrap_content"
86 + android:textColor="#617181"
87 + android:textSize="12sp"
88 + android:visibility="gone"
89 + tools:text="@string/cos_market_coupon_expired" />
90 + </LinearLayout>
91 +
92 + <LinearLayout
93 + android:id="@+id/ll_date_limit"
94 + android:layout_width="wrap_content"
95 + android:layout_height="wrap_content"
96 + android:background="@drawable/shape_market_limit"
97 + android:gravity="center_vertical"
98 + android:orientation="horizontal"
99 + android:visibility="gone"
100 + android:layout_marginBottom="36dp"
101 + android:layout_marginStart="8dp"
102 + app:layout_constraintBottom_toBottomOf="parent"
103 + app:layout_constraintTop_toBottomOf="@+id/ll_coupon_info"
104 + app:layout_constraintStart_toEndOf="@+id/v_separator"
105 + tools:visibility="visible">
106 +
107 +<!-- <ImageView-->
108 +<!-- android:layout_width="14dp"-->
109 +<!-- android:layout_height="14dp"-->
110 +<!-- android:layout_marginEnd="4dp"-->
111 +<!-- android:src="@drawable/timer_red" />-->
112 +
113 + <TextView
114 + fontPath="fonts/pf_square_sans_pro_medium.ttf"
115 + android:layout_width="wrap_content"
116 + android:layout_height="wrap_content"
117 + android:text="@string/cos_coupon_date_limit"
118 + android:textColor="#617181"
119 + android:textSize="12sp" />
120 +
121 + <TextView
122 + android:id="@+id/tv_active_coupons_date_limit"
123 + fontPath="fonts/pf_square_sans_pro_medium.ttf"
124 + android:layout_width="wrap_content"
125 + android:layout_height="wrap_content"
126 + android:text="@string/cos_coupon_date_limit"
127 + android:textColor="#FF6B6B"
128 + android:textSize="12sp"
129 + tools:text="@string/cos_coupon_date_limit2" />
130 + </LinearLayout>
131 +
132 + <TextView
133 + android:id="@+id/tv_active_coupons_description"
134 + fontPath="fonts/pf_square_sans_pro_medium.ttf"
135 + android:layout_width="0dp"
136 + android:layout_height="wrap_content"
137 + android:layout_marginStart="8dp"
138 + android:layout_marginEnd="32dp"
139 + android:maxLines="4"
140 + android:textColor="#617181"
141 + android:textSize="12sp"
142 + app:layout_constraintBottom_toBottomOf="parent"
143 + app:layout_constraintEnd_toEndOf="parent"
144 + app:layout_constraintStart_toEndOf="@+id/gl_vertical_72_percent"
145 + app:layout_constraintTop_toTopOf="parent"
146 + tools:text="Εκπτωση με ελάχιστες αγορές 100€" />
147 +</androidx.constraintlayout.widget.ConstraintLayout>
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 + xmlns:app="http://schemas.android.com/apk/res-auto"
4 + xmlns:tools="http://schemas.android.com/tools"
5 + android:layout_width="match_parent"
6 + android:layout_height="130dp"
7 + android:layout_marginHorizontal="4dp"
8 + android:layout_marginVertical="4dp"
9 + android:background="@drawable/ic_coupon_background_new2">
10 +
11 + <androidx.constraintlayout.widget.Guideline
12 + android:id="@+id/gl_vertical_72_percent"
13 + android:layout_width="wrap_content"
14 + android:layout_height="wrap_content"
15 + android:orientation="vertical"
16 + app:layout_constraintGuide_percent="0.72" />
17 +
18 + <ImageView
19 + android:id="@+id/iv_market_coupon"
20 + android:layout_width="80dp"
21 + android:layout_height="80dp"
22 + android:layout_marginStart="24dp"
23 + android:padding="18dp"
24 + android:src="@drawable/ic_market_trolley"
25 + app:layout_constraintBottom_toBottomOf="parent"
26 + app:layout_constraintStart_toStartOf="parent"
27 + app:layout_constraintTop_toTopOf="parent" />
28 +
29 + <View
30 + android:id="@+id/v_separator"
31 + android:layout_width="1dp"
32 + android:layout_height="match_parent"
33 + android:layout_marginVertical="16dp"
34 + android:layout_marginStart="8dp"
35 + android:background="@drawable/shape_dashed_vertical"
36 + app:layout_constraintBottom_toBottomOf="parent"
37 + app:layout_constraintStart_toEndOf="@+id/iv_market_coupon"
38 + app:layout_constraintTop_toTopOf="parent" />
39 +
40 + <LinearLayout
41 + android:id="@+id/ll_coupon_info"
42 + android:layout_width="0dp"
43 + android:layout_height="wrap_content"
44 + android:layout_marginStart="16dp"
45 + android:orientation="vertical"
46 + app:layout_constraintBottom_toBottomOf="parent"
47 + app:layout_constraintEnd_toStartOf="@+id/gl_vertical_72_percent"
48 + app:layout_constraintStart_toEndOf="@+id/v_separator"
49 + app:layout_constraintTop_toTopOf="parent">
50 +
51 + <TextView
52 + android:id="@+id/tv_market_coupons_title"
53 + fontPath="fonts/BTCosmo-Bold.ttf"
54 + android:layout_width="wrap_content"
55 + android:layout_height="wrap_content"
56 + android:ellipsize="end"
57 + android:maxLines="3"
58 + android:textColor="@color/cos_light_black"
59 + android:textSize="16sp"
60 + android:text="@string/cos_market_item_title" />
61 +
62 + <TextView
63 + fontPath="fonts/pf_square_sans_pro_bold.ttf"
64 + android:layout_width="wrap_content"
65 + android:layout_height="wrap_content"
66 + android:textColor="#3A5266"
67 + android:textSize="22sp"
68 + android:text="" />
69 +
70 + <TextView
71 + android:id="@+id/tv_market_coupons_date"
72 + fontPath="fonts/PeridotPE-Regular.ttf"
73 + android:layout_width="wrap_content"
74 + android:layout_height="wrap_content"
75 + android:textColor="@color/cos_light_black"
76 + android:textSize="12sp"
77 + tools:text="@string/cos_active_coupon_date" />
78 + </LinearLayout>
79 +
80 + <TextView
81 + android:id="@+id/tv_market_coupons_count"
82 + fontPath="fonts/PeridotPE-Regular.ttf"
83 + android:layout_width="0dp"
84 + android:layout_height="wrap_content"
85 + android:layout_marginStart="8dp"
86 + android:layout_marginEnd="32dp"
87 + android:maxLines="4"
88 + android:textColor="@color/cos_light_black"
89 + android:textSize="12sp"
90 + app:layout_constraintBottom_toBottomOf="parent"
91 + app:layout_constraintEnd_toEndOf="parent"
92 + app:layout_constraintStart_toEndOf="@+id/gl_vertical_72_percent"
93 + app:layout_constraintTop_toTopOf="parent"
94 + tools:text="@string/cos_market_active_coupons" />
95 +</androidx.constraintlayout.widget.ConstraintLayout>
...\ No newline at end of file ...\ No newline at end of file
...@@ -71,4 +71,5 @@ ...@@ -71,4 +71,5 @@
71 <color name="cos_gray">#9D9D9C</color> 71 <color name="cos_gray">#9D9D9C</color>
72 <color name="cos_gray2">#848484</color> 72 <color name="cos_gray2">#848484</color>
73 <color name="cos_light_blue">#00A5E3</color> 73 <color name="cos_light_blue">#00A5E3</color>
74 + <color name="cos_grey_dark2">#32485A</color>
74 </resources> 75 </resources>
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -73,8 +73,8 @@ ...@@ -73,8 +73,8 @@
73 <string name="cos_gift_it">Δώρισέ το</string> 73 <string name="cos_gift_it">Δώρισέ το</string>
74 <string name="cos_popup_more_title">COSMOTE MORE FOR YOU</string> 74 <string name="cos_popup_more_title">COSMOTE MORE FOR YOU</string>
75 <string name="cos_popup_more_subtitle">Σε αυτή την ενότητα βρες έρευνες, παιχνίδια, διαγωνισμούς και επιβραβεύσεις για τις αθλητικές σου δραστηριότητες!</string> 75 <string name="cos_popup_more_subtitle">Σε αυτή την ενότητα βρες έρευνες, παιχνίδια, διαγωνισμούς και επιβραβεύσεις για τις αθλητικές σου δραστηριότητες!</string>
76 - <string name="cos_deals_win_title">Μέχρι τώρα έχεις κερδίσει %1$s€ σε προσφορές από %2$s κουπόνια!</string> 76 + <string name="cos_deals_win_title">Έχεις κερδίσει&#160;%1$s€&#160;με το\nGIFTS for YOU!</string>
77 - <string name="cos_deals_win_title_cos">Μέχρι τώρα έχεις κερδίσει %1$s€ με το DEALS for YOU!</string> 77 + <string name="cos_deals_win_title_cos">Έχεις κερδίσει&#160;%1$s€&#160;με το\nDEALS for YOU!</string>
78 <string name="cos_mygifts">Τα δώρα μου</string> 78 <string name="cos_mygifts">Τα δώρα μου</string>
79 <string name="cos_gifts_banner_title">Δώρα:</string> 79 <string name="cos_gifts_banner_title">Δώρα:</string>
80 <string name="cos_see_more">Δες περισσότερα</string> 80 <string name="cos_see_more">Δες περισσότερα</string>
...@@ -150,6 +150,25 @@ ...@@ -150,6 +150,25 @@
150 <string name="cos_dlg_no_shops_title">Καταστήματα συνεργάτη</string> 150 <string name="cos_dlg_no_shops_title">Καταστήματα συνεργάτη</string>
151 <string name="cos_dlg_no_shops_positive">Δες το eshop</string> 151 <string name="cos_dlg_no_shops_positive">Δες το eshop</string>
152 <string name="cos_profile_preferences_placeholder">Οι προτιμήσεις μου</string> 152 <string name="cos_profile_preferences_placeholder">Οι προτιμήσεις μου</string>
153 + <string name="cos_market_title">SuperMarket Deals</string>
154 + <string name="cos_rewards_title2">COSMOTE Επιβράβευση</string>
155 + <string name="cos_market_item_title">COSMOTE\nSuperMarket\nDeals</string>
156 + <string name="cos_market_active_coupons">έχεις %1$s ενεργά κουπόνια</string>
157 + <string name="cos_market_active_coupons_single">έχεις %1$s ενεργό κουπόνι</string>
158 + <string name="cos_unified_title">Εκπτωτικό κουπόνι COSMOTE SuperMarket Deals!</string>
159 + <string name="cos_unified_subtitle">Χρησιμοποίησε τον παρακάτω κωδικό και πάρε έκπτωση στα ενεργά κουπόνια προσφορών.</string>
160 + <string name="cos_markets">Δες τα supermarket</string>
161 + <string name="cos_show_market_coupons">Εμφάνιση κουπονιών</string>
162 + <string name="cos_hide_market_coupons">Απόκρυψη κουπονιών</string>
163 + <string name="cos_market_terms">1. Το εκπτωτικό κουπόνι ισχύει έως την ημερομηνία που αναφέρεται παραπάνω\n
164 +2. To εκπτωτικό κουπόνι αφορά στα ενεργά κουπόνια προσφορών όπως αναφέρονται παραπάνω.\n
165 +3. Το εκπτωτικό κουπόνι μπορεί να χρησιμοποιηθεί σε μια μόνο συναλλαγή.\n
166 +4. Εάν δεν γίνει χρήση ενός επιμέρους κουπονιού προσφοράς από το εκπτωτικό κουπόνι, το κουπόνι προσφοράς επιστρέφει στο καλάθι στην ενότητα COSMOTE SuperMarket Deals</string>
167 + <string name="cos_market_coupon_expired">Το κουπόνι έληξε</string>
168 + <string name="cos_coupon_date_limit">Ισχύει έως&#160;</string>
169 + <string name="cos_coupon_date_limit2">%1$s</string>
170 + <string name="cos_for_you_all">Μέχρι τώρα έχεις κερδίσει&#160;%1$s€&#160;στο For You!</string>
171 + <string name="cos_supermarket_win">Έχεις κερδίσει&#160;%1$s€&#160;με τα\nSuperMarket Deals!</string>
153 172
154 <string-array name="coupons_array"> 173 <string-array name="coupons_array">
155 <item>Κουπόνια</item> 174 <item>Κουπόνια</item>
......