From 171bdd441f2b9ed67ebb544b7138530fa5227e28 Mon Sep 17 00:00:00 2001 From: Rajul Babel Date: Tue, 25 May 2021 17:58:15 +0530 Subject: [PATCH] add dose constraint to alerts --- .../helper/SlotResponseHelper.java | 22 ++++++++++++++----- .../service/CheckSlotsService.java | 4 ++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/vaccinenotifier/helper/SlotResponseHelper.java b/app/src/main/java/com/vaccinenotifier/helper/SlotResponseHelper.java index b073d2a..9257068 100644 --- a/app/src/main/java/com/vaccinenotifier/helper/SlotResponseHelper.java +++ b/app/src/main/java/com/vaccinenotifier/helper/SlotResponseHelper.java @@ -1,5 +1,8 @@ package com.vaccinenotifier.helper; +import android.content.res.Resources; + +import com.vaccinenotifier.R; import com.vaccinenotifier.bean.AvailableCenter; import com.vaccinenotifier.bean.GetSlotsResponse; @@ -9,7 +12,7 @@ public class SlotResponseHelper { - public static List filter(GetSlotsResponse slotsResponse, int ageLimit, String vaccine, String feeType, String dose) { + public static List filter(GetSlotsResponse slotsResponse, int ageLimit, String vaccine, String feeType, String dose, Resources resources) { List feeTypeList = null; if (!feeType.equals("")) { @@ -22,10 +25,10 @@ public static List filter(GetSlotsResponse slotsResponse, int a } List availableSessions = new ArrayList<>(); for (GetSlotsResponse.Session session : center.getSessions()) { - if (constraintChecks(session, ageLimit, vaccine)) { + if (constraintChecks(session, ageLimit, vaccine, dose, resources)) { AvailableCenter.AvailableSession availableSession = new AvailableCenter.AvailableSession(); availableSession.setVaccine(session.getVaccine()); - availableSession.setAvailableCapacity(session.getAvailableCapacity()); + availableSession.setAvailableCapacity(getAvailableCapacity(dose, session, resources)); availableSession.setDate(session.getDate()); availableSessions.add(availableSession); } @@ -41,11 +44,20 @@ public static List filter(GetSlotsResponse slotsResponse, int a return availableCenters; } - private static boolean constraintChecks(GetSlotsResponse.Session session, int ageLimit, String vaccine) { + private static int getAvailableCapacity(String dose, GetSlotsResponse.Session session, Resources resources) { + if (dose.equals(resources.getString(R.string.dose1))) { + return session.getAvailableCapacityDose1(); + } else if (dose.equals(resources.getString(R.string.dose2))) { + return session.getAvailableCapacityDose2(); + } + return session.getAvailableCapacity(); + } + + private static boolean constraintChecks(GetSlotsResponse.Session session, int ageLimit, String vaccine, String dose, Resources resources) { if (session.getMinAgeLimit() != ageLimit) { return false; } - if (session.getAvailableCapacity() <= 0) { + if (getAvailableCapacity(dose, session, resources) <= 0) { return false; } List vaccineList = null; diff --git a/app/src/main/java/com/vaccinenotifier/service/CheckSlotsService.java b/app/src/main/java/com/vaccinenotifier/service/CheckSlotsService.java index 5c2b4af..99c221e 100644 --- a/app/src/main/java/com/vaccinenotifier/service/CheckSlotsService.java +++ b/app/src/main/java/com/vaccinenotifier/service/CheckSlotsService.java @@ -63,7 +63,7 @@ private SlotConstraints getSlotConstraints() { @Override public void onTaskSuccess(GetSlotsResponse result) { - List availableCenters = SlotResponseHelper.filter(result, slotConstraints.getAge(), slotConstraints.getVaccine(), slotConstraints.getFeeType(), slotConstraints.getDose()); + List availableCenters = SlotResponseHelper.filter(result, slotConstraints.getAge(), slotConstraints.getVaccine(), slotConstraints.getFeeType(), slotConstraints.getDose(), getResources()); if (availableCenters.size() == 0) { Log.i("onTaskSuccess", getString(R.string.noCentersAvailable)); return; @@ -72,7 +72,7 @@ public void onTaskSuccess(GetSlotsResponse result) { StringBuilder notificationText = new StringBuilder(); for (AvailableCenter availableCenter : availableCenters) { - notificationText.append(availableCenter.getName()).append(" @ ").append(availableCenter.getAvailableSessions().get(0).getDate()).append("\n"); + notificationText.append(availableCenter.getName()).append(" @ ").append(availableCenter.getAvailableSessions().get(0).getDate()).append(getResources().getString(R.string.newLine)); } Intent centersIntent = new Intent(this, CentersActivity.class);