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

Fixed some bugs

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