Skip to content

Commit

Permalink
add dose constraint to alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
rajulbabel committed May 25, 2021
1 parent 43360b6 commit 171bdd4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -9,7 +12,7 @@

public class SlotResponseHelper {

public static List<AvailableCenter> filter(GetSlotsResponse slotsResponse, int ageLimit, String vaccine, String feeType, String dose) {
public static List<AvailableCenter> filter(GetSlotsResponse slotsResponse, int ageLimit, String vaccine, String feeType, String dose, Resources resources) {

List<String> feeTypeList = null;
if (!feeType.equals("")) {
Expand All @@ -22,10 +25,10 @@ public static List<AvailableCenter> filter(GetSlotsResponse slotsResponse, int a
}
List<AvailableCenter.AvailableSession> 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);
}
Expand All @@ -41,11 +44,20 @@ public static List<AvailableCenter> 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<String> vaccineList = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private SlotConstraints getSlotConstraints() {

@Override
public void onTaskSuccess(GetSlotsResponse result) {
List<AvailableCenter> availableCenters = SlotResponseHelper.filter(result, slotConstraints.getAge(), slotConstraints.getVaccine(), slotConstraints.getFeeType(), slotConstraints.getDose());
List<AvailableCenter> 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;
Expand All @@ -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);
Expand Down

0 comments on commit 171bdd4

Please sign in to comment.