Commit 04cc7538 authored by Robert Hitt's avatar Robert Hitt
Browse files

Fixed some bugs

parent e774a11c
Pipeline #1940 passed with stages
in 2 minutes and 56 seconds
...@@ -26,8 +26,8 @@ android { ...@@ -26,8 +26,8 @@ android {
applicationId "srct.whatsopen" applicationId "srct.whatsopen"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 26 targetSdkVersion 26
versionCode 2 versionCode 4
versionName "1.0.1" versionName "1.0.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {
......
...@@ -19,10 +19,12 @@ open class MainSchedule : RealmObject, Schedule { ...@@ -19,10 +19,12 @@ open class MainSchedule : RealmObject, Schedule {
@SerializedName("twenty_four_hours") @SerializedName("twenty_four_hours")
var openTwentyFourHours: Boolean? = null var openTwentyFourHours: Boolean? = null
constructor(openTimesList: RealmList<OpenTimes>, validStart: String, validEnd: String) { constructor(openTimesList: RealmList<OpenTimes>, validStart: String, validEnd: String,
openTwentyFourHours: Boolean) {
mOpenTimesList = openTimesList mOpenTimesList = openTimesList
this.validStart = validStart this.validStart = validStart
this.validEnd = validEnd this.validEnd = validEnd
this.openTwentyFourHours = openTwentyFourHours
} }
constructor() {} constructor() {}
...@@ -42,4 +44,8 @@ open class MainSchedule : RealmObject, Schedule { ...@@ -42,4 +44,8 @@ open class MainSchedule : RealmObject, Schedule {
fun setOpenTimesList(openTimesList: RealmList<OpenTimes>) { fun setOpenTimesList(openTimesList: RealmList<OpenTimes>) {
mOpenTimesList = openTimesList mOpenTimesList = openTimesList
} }
override fun isOpen24Hours(): Boolean? {
return openTwentyFourHours
}
} }
...@@ -8,4 +8,6 @@ public interface Schedule { ...@@ -8,4 +8,6 @@ public interface Schedule {
RealmList<OpenTimes> getOpenTimesList(); RealmList<OpenTimes> getOpenTimesList();
String getValidEnd(); String getValidEnd();
Boolean isOpen24Hours();
} }
...@@ -16,10 +16,15 @@ open class SpecialSchedule : RealmObject, Schedule { ...@@ -16,10 +16,15 @@ open class SpecialSchedule : RealmObject, Schedule {
@SerializedName("valid_end") @SerializedName("valid_end")
private var validEnd: String? = null private var validEnd: String? = null
constructor(openTimesList: RealmList<OpenTimes>, validStart: String, validEnd: String) { @SerializedName("twenty_four_hours")
var openTwentyFourHours: Boolean? = null
constructor(openTimesList: RealmList<OpenTimes>, validStart: String, validEnd: String,
openTwentyFourHours: Boolean) {
mOpenTimesList = openTimesList mOpenTimesList = openTimesList
this.validStart = validStart this.validStart = validStart
this.validEnd = validEnd this.validEnd = validEnd
this.openTwentyFourHours = openTwentyFourHours
} }
constructor() {} constructor() {}
...@@ -39,4 +44,8 @@ open class SpecialSchedule : RealmObject, Schedule { ...@@ -39,4 +44,8 @@ open class SpecialSchedule : RealmObject, Schedule {
fun setOpenTimesList(openTimesList: RealmList<OpenTimes>) { fun setOpenTimesList(openTimesList: RealmList<OpenTimes>) {
mOpenTimesList = openTimesList mOpenTimesList = openTimesList
} }
override fun isOpen24Hours(): Boolean? {
return openTwentyFourHours
}
} }
...@@ -78,12 +78,12 @@ public class FacilityPresenter { ...@@ -78,12 +78,12 @@ public class FacilityPresenter {
RealmList<OpenTimes> openTimesList = schedule.getOpenTimesList(); RealmList<OpenTimes> openTimesList = schedule.getOpenTimesList();
int currentDay = (5 + now.get(Calendar.DAY_OF_WEEK)) % 7; int currentDay = (5 + now.get(Calendar.DAY_OF_WEEK)) % 7;
if(schedule.isOpen24Hours())
return "This facility is always open";
if(openTimesList.size() == 0) if(openTimesList.size() == 0)
return "No schedule available"; return "No schedule available";
if(facilityDoesNotClose(openTimesList))
return "This facility is always open";
StringBuilder scheduleString = new StringBuilder(); StringBuilder scheduleString = new StringBuilder();
boolean first = true; boolean first = true;
for(OpenTimes o : openTimesList) { for(OpenTimes o : openTimesList) {
...@@ -110,26 +110,6 @@ public class FacilityPresenter { ...@@ -110,26 +110,6 @@ public class FacilityPresenter {
return scheduleString.toString(); return scheduleString.toString();
} }
public static boolean facilityDoesNotClose(List<OpenTimes> openTimesList) {
boolean doesNotClose = false;
int counter = 0;
for(OpenTimes o : openTimesList) {
if(o.getStartTime().equals("00:00:00") && o.getEndTime().equals("23:59:59")
|| o.getEndTime().equals("00:00:00")) {
doesNotClose = true;
counter++;
}
}
if(counter != openTimesList.size()) {
doesNotClose = false;
}
return doesNotClose;
}
// Parses 24 hour formatted time String to 12 hour formatted time String // Parses 24 hour formatted time String to 12 hour formatted time String
public static String parseTo12HourTime(String time) { public static String parseTo12HourTime(String time) {
try { try {
......
...@@ -23,6 +23,7 @@ import rx.android.schedulers.AndroidSchedulers; ...@@ -23,6 +23,7 @@ import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers; import rx.schedulers.Schedulers;
import srct.whatsopen.model.Facility; import srct.whatsopen.model.Facility;
import srct.whatsopen.model.OpenTimes; import srct.whatsopen.model.OpenTimes;
import srct.whatsopen.model.Schedule;
import srct.whatsopen.model.SpecialSchedule; import srct.whatsopen.model.SpecialSchedule;
import srct.whatsopen.util.WhatsOpenService; import srct.whatsopen.util.WhatsOpenService;
import srct.whatsopen.util.WhatsOpenApi; import srct.whatsopen.util.WhatsOpenApi;
...@@ -48,6 +49,7 @@ public class MainPresenter { ...@@ -48,6 +49,7 @@ public class MainPresenter {
// Gets a Call from the given Retrofit service, then asynchronously executes it // Gets a Call from the given Retrofit service, then asynchronously executes it
// On success, copies the resulting facility list to the Realm DB // On success, copies the resulting facility list to the Realm DB
public void loadFacilities() { public void loadFacilities() {
if (mMainView != null)
mMainView.showProgressBar(); mMainView.showProgressBar();
// Get WhatsOpenApi singleton // Get WhatsOpenApi singleton
...@@ -68,7 +70,6 @@ public class MainPresenter { ...@@ -68,7 +70,6 @@ public class MainPresenter {
public void onError(Throwable e) { public void onError(Throwable e) {
updateOpenStatus(); updateOpenStatus();
if(mMainView != null) { if(mMainView != null) {
mMainView.dismissProgressBar();
Toast.makeText(mMainView.getContext(), "Error getting data; " + Toast.makeText(mMainView.getContext(), "Error getting data; " +
"schedules may be out of date.", Toast.LENGTH_LONG).show(); "schedules may be out of date.", Toast.LENGTH_LONG).show();
} }
...@@ -143,7 +144,13 @@ public class MainPresenter { ...@@ -143,7 +144,13 @@ public class MainPresenter {
// Uses the device time to determine which facilities should be open // Uses the device time to determine which facilities should be open
public boolean getOpenStatus(Facility facility, Calendar now) { public boolean getOpenStatus(Facility facility, Calendar now) {
RealmList<OpenTimes> openTimesList = getActiveSchedule(facility, now); Schedule schedule = getActiveSchedule(facility, now);
if (schedule.isOpen24Hours()) {
return true;
}
RealmList<OpenTimes> openTimesList = schedule.getOpenTimesList();
// have to mess with the current day value, as Calender.DAY_OF_WEEK // have to mess with the current day value, as Calender.DAY_OF_WEEK
// starts with Sunday as 1 and the Whats Open Api starts with Monday at 0 // starts with Sunday as 1 and the Whats Open Api starts with Monday at 0
...@@ -154,18 +161,10 @@ public class MainPresenter { ...@@ -154,18 +161,10 @@ public class MainPresenter {
if (o.getStartDay() == currentDay && o.getEndDay() == currentDay) { if (o.getStartDay() == currentDay && o.getEndDay() == currentDay) {
currentOpenTimes = o; currentOpenTimes = o;
// for some reason in the Api this signifies a facility that's open 24/7, sometimes
// praying for that api v2
if (currentOpenTimes.getStartTime().equals("00:00:00")
&& currentOpenTimes.getEndTime().equals("00:00:00")) {
return true;
}
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
try { try {
Date startTime = sdf.parse(currentOpenTimes.getStartTime()); Date startTime = sdf.parse(currentOpenTimes.getStartTime());
Date endTime = sdf.parse(currentOpenTimes.getEndTime()); Date endTime = sdf.parse(currentOpenTimes.getEndTime());
// have to parse it from date to string to date. how fun
Date currentTime = sdf.parse(sdf.format(now.getTime())); Date currentTime = sdf.parse(sdf.format(now.getTime()));
if (currentTime.compareTo(startTime) > 0 && currentTime.compareTo(endTime) < 0) if (currentTime.compareTo(startTime) > 0 && currentTime.compareTo(endTime) < 0)
...@@ -182,7 +181,6 @@ public class MainPresenter { ...@@ -182,7 +181,6 @@ public class MainPresenter {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
try { try {
Date startTime = sdf.parse(currentOpenTimes.getStartTime()); Date startTime = sdf.parse(currentOpenTimes.getStartTime());
// have to parse it from date to string to date. how fun
Date currentTime = sdf.parse(sdf.format(now.getTime())); Date currentTime = sdf.parse(sdf.format(now.getTime()));
if (currentTime.compareTo(startTime) > 0) if (currentTime.compareTo(startTime) > 0)
...@@ -199,7 +197,6 @@ public class MainPresenter { ...@@ -199,7 +197,6 @@ public class MainPresenter {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
try { try {
Date endTime = sdf.parse(currentOpenTimes.getEndTime()); Date endTime = sdf.parse(currentOpenTimes.getEndTime());
// have to parse it from date to string to date. how fun
Date currentTime = sdf.parse(sdf.format(now.getTime())); Date currentTime = sdf.parse(sdf.format(now.getTime()));
if (currentTime.compareTo(endTime) < 0) if (currentTime.compareTo(endTime) < 0)
...@@ -216,7 +213,13 @@ public class MainPresenter { ...@@ -216,7 +213,13 @@ public class MainPresenter {
// Finds the next time the facility closes or opens and returns it // Finds the next time the facility closes or opens and returns it
public String getStatusDuration(Facility facility, Calendar now) { public String getStatusDuration(Facility facility, Calendar now) {
RealmList<OpenTimes> openTimesList = getActiveSchedule(facility, now); Schedule schedule = getActiveSchedule(facility, now);
if(schedule.isOpen24Hours()) {
return "Open 24/7";
}
RealmList<OpenTimes> openTimesList = schedule.getOpenTimesList();
if(openTimesList == null) if(openTimesList == null)
return ""; return "";
...@@ -228,10 +231,6 @@ public class MainPresenter { ...@@ -228,10 +231,6 @@ public class MainPresenter {
String durationMessage; String durationMessage;
if(facility.isOpen()) { if(facility.isOpen()) {
if(FacilityPresenter.facilityDoesNotClose(openTimesList)) {
return "Open 24/7";
}
if(getCurrentEndTime(openTimesList, currentDay).equals("23:59:59") && if(getCurrentEndTime(openTimesList, currentDay).equals("23:59:59") &&
getCurrentStartTime(openTimesList, (currentDay+1)%7).equals("00:00:00")) { getCurrentStartTime(openTimesList, (currentDay+1)%7).equals("00:00:00")) {
currentDay++; currentDay++;
...@@ -321,8 +320,8 @@ public class MainPresenter { ...@@ -321,8 +320,8 @@ public class MainPresenter {
} }
// Returns the active schedule given the current date // Returns the active schedule given the current date
private RealmList<OpenTimes> getActiveSchedule(Facility facility, Calendar now) { private Schedule getActiveSchedule(Facility facility, Calendar now) {
RealmList<OpenTimes> openTimesList = facility.getMainSchedule().getOpenTimesList(); Schedule schedule = facility.getMainSchedule();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try { try {
...@@ -333,8 +332,7 @@ public class MainPresenter { ...@@ -333,8 +332,7 @@ public class MainPresenter {
Date endDate = sdf.parse(s.getValidEnd()); Date endDate = sdf.parse(s.getValidEnd());
if(currentDate.compareTo(startDate) >= 0 && currentDate.compareTo(endDate) <= 0) { if(currentDate.compareTo(startDate) >= 0 && currentDate.compareTo(endDate) <= 0) {
openTimesList = s.getOpenTimesList(); return s;
return openTimesList;
} }
} }
} catch (ParseException pe) { } catch (ParseException pe) {
...@@ -342,6 +340,6 @@ public class MainPresenter { ...@@ -342,6 +340,6 @@ public class MainPresenter {
return null; return null;
} }
return openTimesList; return schedule;
} }
} }
...@@ -137,7 +137,7 @@ public class NotificationPresenter { ...@@ -137,7 +137,7 @@ public class NotificationPresenter {
NotificationSettings notificationSettings) { NotificationSettings notificationSettings) {
Realm realm = Realm.getDefaultInstance(); Realm realm = Realm.getDefaultInstance();
Facility facility = realm.where(Facility.class) Facility facility = realm.where(Facility.class)
.equalTo("mName", notificationSettings.name).findFirst(); .equalTo("name", notificationSettings.name).findFirst();
Schedule schedule = getActiveSchedule(facility, Calendar.getInstance()); Schedule schedule = getActiveSchedule(facility, Calendar.getInstance());
if(!schedule.equals(facility.getMainSchedule())) { if(!schedule.equals(facility.getMainSchedule())) {
......
...@@ -32,7 +32,7 @@ public class FacilityPresenterUnitTest { ...@@ -32,7 +32,7 @@ public class FacilityPresenterUnitTest {
openTimesList.add(o1); openTimesList.add(o1);
openTimesList.add(o2); openTimesList.add(o2);
MainSchedule mainSchedule = new MainSchedule(openTimesList, MainSchedule mainSchedule = new MainSchedule(openTimesList,
"2017-01-09", "2017-01-15"); "2017-01-09", "2017-01-15", false);
Location location = new Location("Whitetop Hall"); Location location = new Location("Whitetop Hall");
mFacility = new Facility("Chef's Table at Brooklyn Fare", location, mFacility = new Facility("Chef's Table at Brooklyn Fare", location,
...@@ -57,7 +57,7 @@ public class FacilityPresenterUnitTest { ...@@ -57,7 +57,7 @@ public class FacilityPresenterUnitTest {
@Test @Test
public void testFacilityScheduleNoSchedule() { public void testFacilityScheduleNoSchedule() {
mFacility.setMainSchedule(new MainSchedule(new RealmList<OpenTimes>(), mFacility.setMainSchedule(new MainSchedule(new RealmList<OpenTimes>(),
"2017-01-09", "2017-01-15")); "2017-01-09", "2017-01-15", false));
Schedule schedule = mPresenter.getActiveSchedule(mFacility, now); Schedule schedule = mPresenter.getActiveSchedule(mFacility, now);
String scheduleText = mPresenter.getScheduleText(schedule, now); String scheduleText = mPresenter.getScheduleText(schedule, now);
...@@ -71,9 +71,9 @@ public class FacilityPresenterUnitTest { ...@@ -71,9 +71,9 @@ public class FacilityPresenterUnitTest {
// Set SpecialSchedule // Set SpecialSchedule
SpecialSchedule s1 = new SpecialSchedule(openTimesList, SpecialSchedule s1 = new SpecialSchedule(openTimesList,
"2017-03-06", "2017-03-15"); "2017-03-06", "2017-03-15", false);
SpecialSchedule s2 = new SpecialSchedule(openTimesList, SpecialSchedule s2 = new SpecialSchedule(openTimesList,
"2017-06-09", "2017-07-15"); "2017-06-09", "2017-07-15", false);
RealmList<SpecialSchedule> specialSchedules = new RealmList<>(); RealmList<SpecialSchedule> specialSchedules = new RealmList<>();
specialSchedules.add(s1); specialSchedules.add(s1);
specialSchedules.add(s2); specialSchedules.add(s2);
...@@ -96,7 +96,7 @@ public class FacilityPresenterUnitTest { ...@@ -96,7 +96,7 @@ public class FacilityPresenterUnitTest {
openTimesList.add(new OpenTimes(0, 6, "00:00:00", "23:59:59")); openTimesList.add(new OpenTimes(0, 6, "00:00:00", "23:59:59"));
mFacility.setOpen(true); mFacility.setOpen(true);
mFacility.setMainSchedule(new MainSchedule(openTimesList, mFacility.setMainSchedule(new MainSchedule(openTimesList,
"2017-01-09", "2017-01-15")); "2017-01-09", "2017-01-15", true));
Schedule schedule = mPresenter.getActiveSchedule(mFacility, now); Schedule schedule = mPresenter.getActiveSchedule(mFacility, now);
String scheduleText = mPresenter.getScheduleText(schedule, now); String scheduleText = mPresenter.getScheduleText(schedule, now);
...@@ -110,7 +110,7 @@ public class FacilityPresenterUnitTest { ...@@ -110,7 +110,7 @@ public class FacilityPresenterUnitTest {
openTimesList.add(new OpenTimes(5, 5, "08:00:00", "09:00:00")); openTimesList.add(new OpenTimes(5, 5, "08:00:00", "09:00:00"));
openTimesList.add(new OpenTimes(6, 6, "08:00:00", "09:00:00")); openTimesList.add(new OpenTimes(6, 6, "08:00:00", "09:00:00"));
mFacility.setMainSchedule(new MainSchedule(openTimesList, mFacility.setMainSchedule(new MainSchedule(openTimesList,
"2017-01-09", "2017-01-15")); "2017-01-09", "2017-01-15", false));
Schedule schedule = mPresenter.getActiveSchedule(mFacility, now); Schedule schedule = mPresenter.getActiveSchedule(mFacility, now);
String scheduleText = mPresenter.getScheduleText(schedule, now); String scheduleText = mPresenter.getScheduleText(schedule, now);
......
...@@ -32,12 +32,12 @@ public class MainPresenterUnitTest { ...@@ -32,12 +32,12 @@ public class MainPresenterUnitTest {
openTimesList.add(o1); openTimesList.add(o1);
openTimesList.add(o2); openTimesList.add(o2);
MainSchedule mainSchedule = new MainSchedule(openTimesList, MainSchedule mainSchedule = new MainSchedule(openTimesList,
"2017-01-09", "2017-01-15"); "2017-01-09", "2017-01-15", false);
SpecialSchedule s1 = new SpecialSchedule(openTimesList, SpecialSchedule s1 = new SpecialSchedule(openTimesList,
"2017-03-06", "2017-03-15"); "2017-03-06", "2017-03-15", false);
SpecialSchedule s2 = new SpecialSchedule(openTimesList, SpecialSchedule s2 = new SpecialSchedule(openTimesList,
"2017-06-09", "2017-07-15"); "2017-06-09", "2017-07-15", false);
RealmList<SpecialSchedule> specialSchedules = new RealmList<>(); RealmList<SpecialSchedule> specialSchedules = new RealmList<>();
specialSchedules.add(s1); specialSchedules.add(s1);
specialSchedules.add(s2); specialSchedules.add(s2);
...@@ -167,7 +167,7 @@ public class MainPresenterUnitTest { ...@@ -167,7 +167,7 @@ public class MainPresenterUnitTest {
// Set date // Set date
now.set(2017, 0, 9, 13, 0); // Monday, 1/9/2017, 13:00:00 now.set(2017, 0, 9, 13, 0); // Monday, 1/9/2017, 13:00:00
mFacility.setMainSchedule(new MainSchedule(new RealmList<OpenTimes>(), mFacility.setMainSchedule(new MainSchedule(new RealmList<OpenTimes>(),
"2017-01-09", "2017-01-15")); "2017-01-09", "2017-01-15", false));
String statusDuration = mPresenter.getStatusDuration(mFacility, now); String statusDuration = mPresenter.getStatusDuration(mFacility, now);
...@@ -180,7 +180,7 @@ public class MainPresenterUnitTest { ...@@ -180,7 +180,7 @@ public class MainPresenterUnitTest {
openTimesList.add(new OpenTimes(0, 6, "00:00:00", "23:59:59")); openTimesList.add(new OpenTimes(0, 6, "00:00:00", "23:59:59"));
mFacility.setOpen(true); mFacility.setOpen(true);
mFacility.setMainSchedule(new MainSchedule(openTimesList, mFacility.setMainSchedule(new MainSchedule(openTimesList,
"2017-01-09", "2017-01-15")); "2017-01-09", "2017-01-15", true));
// Set date // Set date
now.set(2017, 0, 11, 10, 0); // Wednesday, 1/11/2017, 10:00:00 now.set(2017, 0, 11, 10, 0); // Wednesday, 1/11/2017, 10:00:00
...@@ -196,7 +196,7 @@ public class MainPresenterUnitTest { ...@@ -196,7 +196,7 @@ public class MainPresenterUnitTest {
openTimesList.add(new OpenTimes(5, 5, "08:00:00", "09:00:00")); openTimesList.add(new OpenTimes(5, 5, "08:00:00", "09:00:00"));
openTimesList.add(new OpenTimes(6, 6, "08:00:00", "09:00:00")); openTimesList.add(new OpenTimes(6, 6, "08:00:00", "09:00:00"));
mFacility.setMainSchedule(new MainSchedule(openTimesList, mFacility.setMainSchedule(new MainSchedule(openTimesList,
"2017-01-09", "2017-01-15")); "2017-01-09", "2017-01-15", false));
// Set date // Set date
now.set(2017, 0, 11, 10, 0); // Wednesday, 1/11/2017, 10:00:00 now.set(2017, 0, 11, 10, 0); // Wednesday, 1/11/2017, 10:00:00
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment