Panagiotis Triantafyllou

unified screen basket part6

...@@ -43,6 +43,7 @@ import java.util.Date; ...@@ -43,6 +43,7 @@ import java.util.Date;
43 import ly.warp.sdk.R; 43 import ly.warp.sdk.R;
44 import ly.warp.sdk.io.models.Coupon; 44 import ly.warp.sdk.io.models.Coupon;
45 import ly.warp.sdk.io.models.Couponset; 45 import ly.warp.sdk.io.models.Couponset;
46 +import ly.warp.sdk.io.models.Merchant;
46 import ly.warp.sdk.io.models.UnifiedCoupon; 47 import ly.warp.sdk.io.models.UnifiedCoupon;
47 import ly.warp.sdk.services.EventCouponsService; 48 import ly.warp.sdk.services.EventCouponsService;
48 import ly.warp.sdk.utils.WarpUtils; 49 import ly.warp.sdk.utils.WarpUtils;
...@@ -113,6 +114,14 @@ public class CouponInfoActivity extends Activity implements View.OnClickListener ...@@ -113,6 +114,14 @@ public class CouponInfoActivity extends Activity implements View.OnClickListener
113 for (Coupon cpn : WarplyManagerHelper.getSmCouponsList()) { 114 for (Coupon cpn : WarplyManagerHelper.getSmCouponsList()) {
114 if (cpn.getCoupon().equals(couponCode)) { 115 if (cpn.getCoupon().equals(couponCode)) {
115 mCoupon = cpn; 116 mCoupon = cpn;
117 +
118 + for (Couponset cpns : WarplyManagerHelper.getCouponsetsDeals()) {
119 + if (cpns.getUuid().equals(mCoupon.getCouponsetUuid())) {
120 + mCoupon.setCouponsetDetails(cpns);
121 + break;
122 + }
123 + }
124 +
116 break; 125 break;
117 } 126 }
118 } 127 }
...@@ -288,8 +297,17 @@ public class CouponInfoActivity extends Activity implements View.OnClickListener ...@@ -288,8 +297,17 @@ public class CouponInfoActivity extends Activity implements View.OnClickListener
288 if (!mIsFindItPressed) { 297 if (!mIsFindItPressed) {
289 mIsFindItPressed = true; 298 mIsFindItPressed = true;
290 299
291 - //TODO: add check to open the sheet only if there are available merchants 300 + JSONObject extraFields = mCoupon.getCouponsetDetails().getExtraFields();
292 - showChooseMerchantDialog(); 301 + if (extraFields != null && extraFields.has("shop_availability")) {
302 + try {
303 + JSONArray shopAvailability = new JSONArray(extraFields.optString("shop_availability"));
304 + if (shopAvailability.length() > 0) {
305 + showChooseMerchantDialog(shopAvailability);
306 + }
307 + } catch (JSONException e) {
308 + e.printStackTrace();
309 + }
310 + }
293 } 311 }
294 } 312 }
295 } 313 }
...@@ -298,7 +316,7 @@ public class CouponInfoActivity extends Activity implements View.OnClickListener ...@@ -298,7 +316,7 @@ public class CouponInfoActivity extends Activity implements View.OnClickListener
298 // Methods 316 // Methods
299 // =========================================================== 317 // ===========================================================
300 318
301 - private void showChooseMerchantDialog() { 319 + private void showChooseMerchantDialog(JSONArray shopAvailability) {
302 final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this, R.style.BottomSheetDialog); 320 final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this, R.style.BottomSheetDialog);
303 bottomSheetDialog.setContentView(R.layout.dl_bottom_sheet_merchants); 321 bottomSheetDialog.setContentView(R.layout.dl_bottom_sheet_merchants);
304 bottomSheetDialog.setOnDismissListener(dialog -> { 322 bottomSheetDialog.setOnDismissListener(dialog -> {
...@@ -317,20 +335,46 @@ public class CouponInfoActivity extends Activity implements View.OnClickListener ...@@ -317,20 +335,46 @@ public class CouponInfoActivity extends Activity implements View.OnClickListener
317 mIsFindItPressed = false; 335 mIsFindItPressed = false;
318 }); 336 });
319 337
320 - int tempLoop = 2; 338 + for (int i = 0; i < shopAvailability.length(); i++) {
321 - for (int i = 0; i < tempLoop; i++) { 339 + int tempIndex = i;
340 + String productUrl = "";
341 + String merchantUuid = "";
342 + Merchant tempMerchant = new Merchant();
343 + try {
344 + JSONObject extraFieldsByItem = (JSONObject) shopAvailability.get(tempIndex);
345 + productUrl = extraFieldsByItem.optString("product_url");
346 + merchantUuid = extraFieldsByItem.optString("merchant_uuid");
347 +
348 + for (Merchant merc : WarplyManagerHelper.getMerchantList()) {
349 + if (merc.getUuid().equals(merchantUuid)) {
350 + tempMerchant = merc;
351 + break;
352 + }
353 + }
354 + } catch (JSONException e) {
355 + e.printStackTrace();
356 + }
357 +
358 + String finalProductUrl = productUrl;
359 +
322 LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 360 LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
323 LinearLayout v = (LinearLayout) vi.inflate(R.layout.item_sheet_merchant, null); 361 LinearLayout v = (LinearLayout) vi.inflate(R.layout.item_sheet_merchant, null);
324 362
325 TextView textView = (TextView) v.findViewById(R.id.button_sm_buy_it); 363 TextView textView = (TextView) v.findViewById(R.id.button_sm_buy_it);
326 WarpUtils.renderCustomFont(this, R.font.peridot_semi_bold, textView); 364 WarpUtils.renderCustomFont(this, R.font.peridot_semi_bold, textView);
365 + ImageView merchantLogo = (ImageView) v.findViewById(R.id.iv_merchant_sheet_logo);
366 + Glide.with(this)
367 + .load(tempMerchant.getImgPreview())
368 + .diskCacheStrategy(DiskCacheStrategy.DATA)
369 + .into(merchantLogo);
327 ConstraintLayout buyButton = (ConstraintLayout) v.findViewById(R.id.cl_button_sm_buy_it); 370 ConstraintLayout buyButton = (ConstraintLayout) v.findViewById(R.id.cl_button_sm_buy_it);
328 buyButton.setOnClickListener(view -> { 371 buyButton.setOnClickListener(view -> {
329 - //TODO: open webview with the specified url
330 bottomSheetDialog.dismiss(); 372 bottomSheetDialog.dismiss();
373 + if (!TextUtils.isEmpty(finalProductUrl))
374 + startActivity(WarpViewActivity.createIntentFromURL(this, finalProductUrl));
331 }); 375 });
332 376
333 - parent.addView(v, 0, new ViewGroup.LayoutParams( 377 + parent.addView(v, tempIndex, new ViewGroup.LayoutParams(
334 ViewGroup.LayoutParams.MATCH_PARENT, 378 ViewGroup.LayoutParams.MATCH_PARENT,
335 ViewGroup.LayoutParams.WRAP_CONTENT)); 379 ViewGroup.LayoutParams.WRAP_CONTENT));
336 } 380 }
......
...@@ -20,6 +20,7 @@ import androidx.core.content.ContextCompat; ...@@ -20,6 +20,7 @@ import androidx.core.content.ContextCompat;
20 import androidx.recyclerview.widget.LinearLayoutManager; 20 import androidx.recyclerview.widget.LinearLayoutManager;
21 import androidx.recyclerview.widget.RecyclerView; 21 import androidx.recyclerview.widget.RecyclerView;
22 22
23 +import com.bumptech.glide.Glide;
23 import com.google.android.gms.common.ConnectionResult; 24 import com.google.android.gms.common.ConnectionResult;
24 import com.google.android.gms.common.GoogleApiAvailability; 25 import com.google.android.gms.common.GoogleApiAvailability;
25 import com.google.android.material.bottomsheet.BottomSheetDialog; 26 import com.google.android.material.bottomsheet.BottomSheetDialog;
...@@ -28,6 +29,9 @@ import com.google.zxing.common.BitMatrix; ...@@ -28,6 +29,9 @@ import com.google.zxing.common.BitMatrix;
28 import com.google.zxing.oned.EAN13Writer; 29 import com.google.zxing.oned.EAN13Writer;
29 30
30 import org.greenrobot.eventbus.EventBus; 31 import org.greenrobot.eventbus.EventBus;
32 +import org.json.JSONArray;
33 +import org.json.JSONException;
34 +import org.json.JSONObject;
31 35
32 import java.text.ParseException; 36 import java.text.ParseException;
33 import java.text.SimpleDateFormat; 37 import java.text.SimpleDateFormat;
...@@ -38,6 +42,7 @@ import ly.warp.sdk.R; ...@@ -38,6 +42,7 @@ import ly.warp.sdk.R;
38 import ly.warp.sdk.io.callbacks.CallbackReceiver; 42 import ly.warp.sdk.io.callbacks.CallbackReceiver;
39 import ly.warp.sdk.io.models.Coupon; 43 import ly.warp.sdk.io.models.Coupon;
40 import ly.warp.sdk.io.models.CouponList; 44 import ly.warp.sdk.io.models.CouponList;
45 +import ly.warp.sdk.io.models.Merchant;
41 import ly.warp.sdk.io.models.RefreshUnifiedCouponsEventModel; 46 import ly.warp.sdk.io.models.RefreshUnifiedCouponsEventModel;
42 import ly.warp.sdk.io.models.UnifiedCoupon; 47 import ly.warp.sdk.io.models.UnifiedCoupon;
43 import ly.warp.sdk.utils.WarpUtils; 48 import ly.warp.sdk.utils.WarpUtils;
...@@ -70,6 +75,7 @@ public class UnifiedCouponInfoActivity extends Activity implements View.OnClickL ...@@ -70,6 +75,7 @@ public class UnifiedCouponInfoActivity extends Activity implements View.OnClickL
70 private RecyclerView mRecyclerCoupons; 75 private RecyclerView mRecyclerCoupons;
71 private ActiveCouponAdapter mAdapterCoupons; 76 private ActiveCouponAdapter mAdapterCoupons;
72 private AlertDialog mErrorAlertDialog, mSuccessAlertDialog, mAskCancelUnifiedAlertDialog; 77 private AlertDialog mErrorAlertDialog, mSuccessAlertDialog, mAskCancelUnifiedAlertDialog;
78 + private JSONArray mBottomSheetData;
73 79
74 // =========================================================== 80 // ===========================================================
75 // Methods for/from SuperClass/Interfaces 81 // Methods for/from SuperClass/Interfaces
...@@ -143,7 +149,7 @@ public class UnifiedCouponInfoActivity extends Activity implements View.OnClickL ...@@ -143,7 +149,7 @@ public class UnifiedCouponInfoActivity extends Activity implements View.OnClickL
143 return; 149 return;
144 } 150 }
145 if (view.getId() == R.id.ll_shops) { 151 if (view.getId() == R.id.ll_shops) {
146 - showChooseCategoryDialog(); 152 + showChooseMerchantCategoryDialog();
147 } 153 }
148 if (view.getId() == R.id.ll_terms_inner) { 154 if (view.getId() == R.id.ll_terms_inner) {
149 if (mIsTermsShown) { 155 if (mIsTermsShown) {
...@@ -182,7 +188,7 @@ public class UnifiedCouponInfoActivity extends Activity implements View.OnClickL ...@@ -182,7 +188,7 @@ public class UnifiedCouponInfoActivity extends Activity implements View.OnClickL
182 // Methods 188 // Methods
183 // =========================================================== 189 // ===========================================================
184 190
185 - private void showChooseCategoryDialog() { 191 + private void showChooseMerchantCategoryDialog() {
186 final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this, R.style.BottomSheetDialog); 192 final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this, R.style.BottomSheetDialog);
187 bottomSheetDialog.setContentView(R.layout.dl_bottom_sheet_categories); 193 bottomSheetDialog.setContentView(R.layout.dl_bottom_sheet_categories);
188 bottomSheetDialog.setOnDismissListener(dialog -> bottomSheetDialog.dismiss()); 194 bottomSheetDialog.setOnDismissListener(dialog -> bottomSheetDialog.dismiss());
...@@ -233,23 +239,57 @@ public class UnifiedCouponInfoActivity extends Activity implements View.OnClickL ...@@ -233,23 +239,57 @@ public class UnifiedCouponInfoActivity extends Activity implements View.OnClickL
233 ImageView dialogClose = (ImageView) bottomSheetDialog.findViewById(R.id.iv_sm_sheet_close); 239 ImageView dialogClose = (ImageView) bottomSheetDialog.findViewById(R.id.iv_sm_sheet_close);
234 dialogClose.setOnClickListener(view -> bottomSheetDialog.dismiss()); 240 dialogClose.setOnClickListener(view -> bottomSheetDialog.dismiss());
235 241
236 - int tempLoop = 2; 242 + JSONObject tempObject = new JSONObject();
237 - for (int i = 0; i < tempLoop; i++) { 243 + mBottomSheetData = new JSONArray();
244 + try {
245 + tempObject.put("merchant_key", "ab");
246 + tempObject.put("merchant_url", "https://www.ab.gr");
247 + mBottomSheetData.put(tempObject);
248 + tempObject = new JSONObject();
249 + tempObject.put("merchant_key", "masoutis");
250 + tempObject.put("merchant_url", "https://www.masoutis.gr");
251 + mBottomSheetData.put(tempObject);
252 + } catch (JSONException e) {
253 + throw new RuntimeException(e);
254 + }
255 +
256 + for (int i = 0; i < mBottomSheetData.length(); i++) {
257 + int tempIndex = i;
258 + String merchantUrl = "";
259 + String merchantKey = "";
260 + try {
261 + JSONObject bottomSheetData = (JSONObject) mBottomSheetData.get(tempIndex);
262 + merchantUrl = bottomSheetData.optString("merchant_url");
263 + merchantKey = bottomSheetData.optString("merchant_key");
264 + } catch (JSONException e) {
265 + e.printStackTrace();
266 + }
267 +
268 + String finalMerchantUrl = merchantUrl;
269 +
238 LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 270 LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
239 LinearLayout v = (LinearLayout) vi.inflate(R.layout.item_sheet_merchant, null); 271 LinearLayout v = (LinearLayout) vi.inflate(R.layout.item_sheet_merchant, null);
240 272
241 TextView textView = (TextView) v.findViewById(R.id.button_sm_buy_it); 273 TextView textView = (TextView) v.findViewById(R.id.button_sm_buy_it);
242 textView.setText(R.string.cos_markets_eshop_item); 274 textView.setText(R.string.cos_markets_eshop_item);
243 WarpUtils.renderCustomFont(this, R.font.peridot_semi_bold, textView); 275 WarpUtils.renderCustomFont(this, R.font.peridot_semi_bold, textView);
244 - ImageView buttonIcon = (ImageView) v.findViewById(R.id.iv_sheet_cart); 276 + ImageView buttonIcon = (ImageView) v.findViewById(R.id.iv_merchant_sheet_logo);
245 - buttonIcon.setVisibility(View.GONE); 277 + if (merchantKey.equals("ab")) {
278 + Glide.with(this)
279 + .load(R.drawable.ic_merchant_ab)
280 + .into(buttonIcon);
281 + } else if (merchantKey.equals("masoutis")) {
282 + Glide.with(this)
283 + .load(R.drawable.ic_merchant_masoutis)
284 + .into(buttonIcon);
285 + }
246 ConstraintLayout buyButton = (ConstraintLayout) v.findViewById(R.id.cl_button_sm_buy_it); 286 ConstraintLayout buyButton = (ConstraintLayout) v.findViewById(R.id.cl_button_sm_buy_it);
247 buyButton.setOnClickListener(view -> { 287 buyButton.setOnClickListener(view -> {
248 - //TODO: open webview with the specified url
249 bottomSheetDialog.dismiss(); 288 bottomSheetDialog.dismiss();
289 + startActivity(WarpViewActivity.createIntentFromURL(this, finalMerchantUrl));
250 }); 290 });
251 291
252 - parent.addView(v, 0, new ViewGroup.LayoutParams( 292 + parent.addView(v, tempIndex, new ViewGroup.LayoutParams(
253 ViewGroup.LayoutParams.MATCH_PARENT, 293 ViewGroup.LayoutParams.MATCH_PARENT,
254 ViewGroup.LayoutParams.WRAP_CONTENT)); 294 ViewGroup.LayoutParams.WRAP_CONTENT));
255 } 295 }
......
...@@ -223,7 +223,10 @@ public class Couponset implements Parcelable, Serializable { ...@@ -223,7 +223,10 @@ public class Couponset implements Parcelable, Serializable {
223 this.innerText = json.optString(INNER_TEXT); 223 this.innerText = json.optString(INNER_TEXT);
224 this.discount_type = json.isNull(DISCOUNT_TYPE) ? "" : json.optString(DISCOUNT_TYPE); 224 this.discount_type = json.isNull(DISCOUNT_TYPE) ? "" : json.optString(DISCOUNT_TYPE);
225 this.final_price = json.isNull(FINAL_PRICE) ? 0.0d : json.optDouble(FINAL_PRICE); 225 this.final_price = json.isNull(FINAL_PRICE) ? 0.0d : json.optDouble(FINAL_PRICE);
226 - this.extraFields = json.optJSONObject(EXTRA_FIELDS); 226 +// this.extraFields = json.optJSONObject(EXTRA_FIELDS);
227 + JSONObject ef = null;
228 + ef = json.optJSONObject(EXTRA_FIELDS);
229 + this.extraFields = ef;
227 } 230 }
228 } 231 }
229 232
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
3 xmlns:app="http://schemas.android.com/apk/res-auto" 3 xmlns:app="http://schemas.android.com/apk/res-auto"
4 android:layout_width="match_parent" 4 android:layout_width="match_parent"
5 android:layout_height="wrap_content" 5 android:layout_height="wrap_content"
6 + xmlns:tools="http://schemas.android.com/tools"
6 android:background="@android:color/white"> 7 android:background="@android:color/white">
7 8
8 <androidx.constraintlayout.widget.ConstraintLayout 9 <androidx.constraintlayout.widget.ConstraintLayout
...@@ -12,10 +13,11 @@ ...@@ -12,10 +13,11 @@
12 android:background="@drawable/shape_cos_sheet_item"> 13 android:background="@drawable/shape_cos_sheet_item">
13 14
14 <ImageView 15 <ImageView
16 + android:id="@+id/iv_merchant_sheet_logo"
15 android:layout_width="140dp" 17 android:layout_width="140dp"
16 android:layout_height="36dp" 18 android:layout_height="36dp"
17 android:layout_marginStart="24dp" 19 android:layout_marginStart="24dp"
18 - android:background="@color/blue_dark" 20 + tools:src="@drawable/cosmote_insurance_logo"
19 app:layout_constraintBottom_toBottomOf="parent" 21 app:layout_constraintBottom_toBottomOf="parent"
20 app:layout_constraintStart_toStartOf="parent" 22 app:layout_constraintStart_toStartOf="parent"
21 app:layout_constraintTop_toTopOf="parent" /> 23 app:layout_constraintTop_toTopOf="parent" />
......