Panagiotis Triantafyllou

categories fixes

...@@ -94,7 +94,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup ...@@ -94,7 +94,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
94 WarplyManager.getCoupons(mCouponsCallback); 94 WarplyManager.getCoupons(mCouponsCallback);
95 WarplyManager.getCarousel(mCarouselCallback); 95 WarplyManager.getCarousel(mCarouselCallback);
96 WarplyManager.getCouponsets(null, null, mCouponsetsCallback); 96 WarplyManager.getCouponsets(null, null, mCouponsetsCallback);
97 - WarplyManager.getFilters(mFiltersCallback); 97 +// WarplyManager.getFilters(mFiltersCallback);
98 } 98 }
99 99
100 @Override 100 @Override
...@@ -299,8 +299,10 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup ...@@ -299,8 +299,10 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
299 TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()); 299 TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
300 int sectionMarginTopPx = (int) TypedValue.applyDimension( 300 int sectionMarginTopPx = (int) TypedValue.applyDimension(
301 TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics()); 301 TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics());
302 + int sectionMarginTopFirstPx = (int) TypedValue.applyDimension(
303 + TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics());
302 304
303 -// int sectionIndex = 0; 305 + int sectionIndex = 0;
304 for (Map.Entry<String, ArrayList<Couponset>> entry : categorizedMap.entrySet()) { 306 for (Map.Entry<String, ArrayList<Couponset>> entry : categorizedMap.entrySet()) {
305 String categoryName = entry.getKey(); 307 String categoryName = entry.getKey();
306 ArrayList<Couponset> couponsets = entry.getValue(); 308 ArrayList<Couponset> couponsets = entry.getValue();
...@@ -311,11 +313,15 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup ...@@ -311,11 +313,15 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
311 313
312 View sectionView = inflater.inflate(R.layout.item_couponset_section, mSectionsContainer, false); 314 View sectionView = inflater.inflate(R.layout.item_couponset_section, mSectionsContainer, false);
313 315
314 -// if (sectionIndex > 0) { 316 + if (sectionIndex == 0) {
315 - LinearLayout.LayoutParams sectionParams = (LinearLayout.LayoutParams) sectionView.getLayoutParams(); 317 + LinearLayout.LayoutParams sectionParams = (LinearLayout.LayoutParams) sectionView.getLayoutParams();
316 - sectionParams.topMargin = sectionMarginTopPx; 318 + sectionParams.topMargin = sectionMarginTopFirstPx;
317 - sectionView.setLayoutParams(sectionParams); 319 + sectionView.setLayoutParams(sectionParams);
318 -// } 320 + } else if (sectionIndex > 0) {
321 + LinearLayout.LayoutParams sectionParams = (LinearLayout.LayoutParams) sectionView.getLayoutParams();
322 + sectionParams.topMargin = sectionMarginTopPx;
323 + sectionView.setLayoutParams(sectionParams);
324 + }
319 325
320 TextView tvTitle = sectionView.findViewById(R.id.tv_section_title); 326 TextView tvTitle = sectionView.findViewById(R.id.tv_section_title);
321 String titleText = categoryName + " (" + couponsets.size() + ")"; 327 String titleText = categoryName + " (" + couponsets.size() + ")";
...@@ -344,7 +350,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup ...@@ -344,7 +350,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
344 rvSection.setAdapter(adapter); 350 rvSection.setAdapter(adapter);
345 351
346 mSectionsContainer.addView(sectionView); 352 mSectionsContainer.addView(sectionView);
347 -// sectionIndex++; 353 + sectionIndex++;
348 } 354 }
349 mSectionsLoading.setVisibility(View.GONE); 355 mSectionsLoading.setVisibility(View.GONE);
350 } 356 }
...@@ -422,15 +428,15 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup ...@@ -422,15 +428,15 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
422 } 428 }
423 }; 429 };
424 430
425 - private final CallbackReceiver<Filter> mFiltersCallback = new CallbackReceiver<Filter>() { 431 +// private final CallbackReceiver<Filter> mFiltersCallback = new CallbackReceiver<Filter>() {
426 - @Override 432 +// @Override
427 - public void onSuccess(Filter result) { 433 +// public void onSuccess(Filter result) {
428 - Toast.makeText(HomeActivity.this, "FILTERS SUCCESS", Toast.LENGTH_SHORT).show(); 434 +// Toast.makeText(HomeActivity.this, "FILTERS SUCCESS", Toast.LENGTH_SHORT).show();
429 - } 435 +// }
430 - 436 +//
431 - @Override 437 +// @Override
432 - public void onFailure(int errorCode) { 438 +// public void onFailure(int errorCode) {
433 - Toast.makeText(HomeActivity.this, "FILTERS ERROR", Toast.LENGTH_SHORT).show(); 439 +// Toast.makeText(HomeActivity.this, "FILTERS ERROR", Toast.LENGTH_SHORT).show();
434 - } 440 +// }
435 - }; 441 +// };
436 } 442 }
......
...@@ -407,7 +407,7 @@ public class WarplyManager { ...@@ -407,7 +407,7 @@ public class WarplyManager {
407 }, executorService); 407 }, executorService);
408 } 408 }
409 409
410 - private static LinkedHashMap<String, ArrayList<Couponset>> mergeCouponsetsResults(ArrayList<Couponset> resultCouponsets) { 410 + private static LinkedHashMap<String, ArrayList<Couponset>> mergeCouponsetsResults(ArrayList<Couponset> resultCouponsets, Filter resultFilter) {
411 LinkedHashMap<String, ArrayList<Couponset>> categorizedMap = new LinkedHashMap<>(); 411 LinkedHashMap<String, ArrayList<Couponset>> categorizedMap = new LinkedHashMap<>();
412 412
413 if (resultCouponsets == null || resultCouponsets.isEmpty()) { 413 if (resultCouponsets == null || resultCouponsets.isEmpty()) {
...@@ -415,6 +415,20 @@ public class WarplyManager { ...@@ -415,6 +415,20 @@ public class WarplyManager {
415 return categorizedMap; 415 return categorizedMap;
416 } 416 }
417 417
418 + // Build child admin_name -> parent admin_name lookup map from Filter
419 + HashMap<String, String> childToParentMap = new HashMap<>();
420 + if (resultFilter != null && resultFilter.getOfferCategories() != null) {
421 + for (Filter.OfferCategory parent : resultFilter.getOfferCategories()) {
422 + if (parent.getChildren() != null) {
423 + for (Filter.OfferCategory child : parent.getChildren()) {
424 + if (child.getAdminName() != null && parent.getAdminName() != null) {
425 + childToParentMap.put(child.getAdminName(), parent.getAdminName());
426 + }
427 + }
428 + }
429 + }
430 + }
431 +
418 ArrayList<Couponset> topOffers = new ArrayList<>(); 432 ArrayList<Couponset> topOffers = new ArrayList<>();
419 LinkedHashMap<String, ArrayList<Couponset>> categoryGroups = new LinkedHashMap<>(); 433 LinkedHashMap<String, ArrayList<Couponset>> categoryGroups = new LinkedHashMap<>();
420 434
...@@ -426,6 +440,10 @@ public class WarplyManager { ...@@ -426,6 +440,10 @@ public class WarplyManager {
426 if (category == null || category.isEmpty()) { 440 if (category == null || category.isEmpty()) {
427 category = "Other"; 441 category = "Other";
428 } 442 }
443 + // If this category is a child, map it to its parent
444 + if (childToParentMap.containsKey(category)) {
445 + category = childToParentMap.get(category);
446 + }
429 categoryGroups.computeIfAbsent(category, k -> new ArrayList<>()).add(couponset); 447 categoryGroups.computeIfAbsent(category, k -> new ArrayList<>()).add(couponset);
430 } 448 }
431 } 449 }
...@@ -490,14 +508,16 @@ public class WarplyManager { ...@@ -490,14 +508,16 @@ public class WarplyManager {
490 WarpUtils.log("**************************************************"); 508 WarpUtils.log("**************************************************");
491 509
492 ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class); 510 ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
493 - ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1)); 511 + ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2));
494 512
495 ListenableFuture<ArrayList<Couponset>> futureCouponsets = getCouponsetsRetro(region, offerCategory, service, 0); 513 ListenableFuture<ArrayList<Couponset>> futureCouponsets = getCouponsetsRetro(region, offerCategory, service, 0);
514 + ListenableFuture<Filter> futureFilters = getFiltersRetro(service);
496 515
497 - ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCouponsets); 516 + ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCouponsets, futureFilters);
498 ListenableFuture<LinkedHashMap<String, ArrayList<Couponset>>> mergedResultFuture = Futures.transformAsync(allResultsFuture, results -> { 517 ListenableFuture<LinkedHashMap<String, ArrayList<Couponset>>> mergedResultFuture = Futures.transformAsync(allResultsFuture, results -> {
499 ArrayList<Couponset> resultCouponsets = (ArrayList<Couponset>) results.get(0); 518 ArrayList<Couponset> resultCouponsets = (ArrayList<Couponset>) results.get(0);
500 - return executorService.submit(() -> mergeCouponsetsResults(resultCouponsets)); 519 + Filter resultFilter = (Filter) results.get(1);
520 + return executorService.submit(() -> mergeCouponsetsResults(resultCouponsets, resultFilter));
501 }, executorService); 521 }, executorService);
502 522
503 Futures.addCallback(mergedResultFuture, new FutureCallback<LinkedHashMap<String, ArrayList<Couponset>>>() { 523 Futures.addCallback(mergedResultFuture, new FutureCallback<LinkedHashMap<String, ArrayList<Couponset>>>() {
......