Commit 88e7719d authored by Robert Hitt's avatar Robert Hitt

Added text for the special schedules' duration

- Also refactored some FacilityPresenter methods
- Closes issue#26
parent 2abd3997
Pipeline #1342 failed with stages
in 3 minutes and 1 second
......@@ -19,6 +19,7 @@ import io.realm.RealmList;
import srct.whatsopen.R;
import srct.whatsopen.model.Facility;
import srct.whatsopen.model.OpenTimes;
import srct.whatsopen.model.Schedule;
import srct.whatsopen.model.SpecialSchedule;
import srct.whatsopen.views.FacilityView;
......@@ -73,8 +74,8 @@ public class FacilityPresenter {
// Parses the schedule into an HTML string.
// Kind of a hacky approach. That being said, this is certainly a lot simpler to test
// than the alternative.
public String getSchedule(Facility facility, Calendar now) {
RealmList<OpenTimes> openTimesList = getActiveSchedule(facility, now);
public String getScheduleText(Schedule schedule, Calendar now) {
RealmList<OpenTimes> openTimesList = schedule.getOpenTimesList();
int currentDay = (5 + now.get(Calendar.DAY_OF_WEEK)) % 7;
if(openTimesList.size() == 0)
......@@ -143,6 +144,19 @@ public class FacilityPresenter {
}
}
// Parses String with format YYYY-MM-DD to MM/DD
public static String parseYMDtoMDY(String time) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
final Date date = sdf.parse(time);
return new SimpleDateFormat("MM/dd/yy").format(date);
} catch (ParseException pe) {
pe.printStackTrace();
return null;
}
}
// Parses an integer to a String of the day of the week
public static String parseIntToDay(int day) {
switch(day) {
......@@ -166,8 +180,8 @@ public class FacilityPresenter {
}
// Returns the active schedule given the current date
private RealmList<OpenTimes> getActiveSchedule(Facility facility, Calendar now) {
RealmList<OpenTimes> openTimesList = facility.getMainSchedule().getOpenTimesList();
public Schedule getActiveSchedule(Facility facility, Calendar now) {
Schedule schedule = facility.getMainSchedule();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
......@@ -178,8 +192,7 @@ public class FacilityPresenter {
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) {
......@@ -187,6 +200,6 @@ public class FacilityPresenter {
return null;
}
return openTimesList;
return schedule;
}
}
......@@ -35,6 +35,8 @@ import srct.whatsopen.MyApplication;
import srct.whatsopen.R;
import srct.whatsopen.model.Facility;
import srct.whatsopen.model.NotificationSettings;
import srct.whatsopen.model.Schedule;
import srct.whatsopen.model.SpecialSchedule;
import srct.whatsopen.views.FacilityView;
import srct.whatsopen.presenters.FacilityPresenter;
import srct.whatsopen.views.fragments.NotificationDialogFragment;
......@@ -51,6 +53,8 @@ public class DetailActivity extends AppCompatActivity implements FacilityView,
TextView locationTextView;
@BindView(R.id.schedule_text)
TextView scheduleTextView;
@BindView(R.id.special_schedule_duration_text)
TextView specialScheduleDurationTextView;
@BindView(R.id.notification_button)
Button notificationButton;
......@@ -83,7 +87,7 @@ public class DetailActivity extends AppCompatActivity implements FacilityView,
private void setUpAnimations() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Slide slide = new Slide();
slide.setSlideEdge(Gravity.LEFT);
slide.setSlideEdge(Gravity.BOTTOM);
slide.setDuration(300);
getWindow().setEnterTransition(slide);
}
......@@ -198,8 +202,18 @@ public class DetailActivity extends AppCompatActivity implements FacilityView,
locationTextView.setText(mFacility.getLocation());
scheduleTextView.setText(Html.fromHtml(mPresenter
.getSchedule(mFacility, Calendar.getInstance())));
Calendar now = Calendar.getInstance();
Schedule currentSchedule = mPresenter.getActiveSchedule(mFacility, now);
scheduleTextView.setText(Html.fromHtml(mPresenter.getScheduleText(currentSchedule, now)));
// Show the SpecialSchedule duration if necessary
if(currentSchedule instanceof SpecialSchedule) {
specialScheduleDurationTextView.setVisibility(View.VISIBLE);
String endDate = FacilityPresenter.parseYMDtoMDY(currentSchedule.getValidEnd());
specialScheduleDurationTextView.setText("Lasts until " + endDate);
} else {
specialScheduleDurationTextView.setVisibility(View.GONE);
}
}
// Sets the notification button text to edit if a Notification exists
......
......@@ -129,6 +129,14 @@
android:textColor="@color/colorPrimary"
android:textSize="26sp"/>
<TextView
android:id="@+id/special_schedule_duration_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimary"
android:visibility="gone"
android:textSize="19sp"/>
<TextView
android:id="@+id/schedule_text"
android:layout_width="wrap_content"
......
......@@ -129,6 +129,14 @@
android:textColor="@color/colorPrimary"
android:textSize="26sp"/>
<TextView
android:id="@+id/special_schedule_duration_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimary"
android:visibility="gone"
android:textSize="19sp"/>
<TextView
android:id="@+id/schedule_text"
android:layout_width="wrap_content"
......
package srct.whatsopen;
import android.content.Context;
import android.graphics.Path;
import android.support.v7.app.AppCompatActivity;
import org.junit.Before;
import org.junit.Test;
......@@ -13,8 +9,8 @@ import io.realm.RealmList;
import srct.whatsopen.model.Facility;
import srct.whatsopen.model.MainSchedule;
import srct.whatsopen.model.OpenTimes;
import srct.whatsopen.model.Schedule;
import srct.whatsopen.model.SpecialSchedule;
import srct.whatsopen.views.FacilityView;
import srct.whatsopen.presenters.FacilityPresenter;
import static org.junit.Assert.*;
......@@ -49,10 +45,11 @@ public class FacilityPresenterUnitTest {
public void testFacilitySchedule() {
// Set date
now.set(2017, 0, 9, 13, 0); // Monday, 1/9/2017, 13:00:00
String schedule = mPresenter.getSchedule(mFacility, now);
Schedule schedule = mPresenter.getActiveSchedule(mFacility, now);
String scheduleText = mPresenter.getScheduleText(schedule, now);
assertEquals("<strong><b>Monday</b>: 11:00 AM - 6:00 PM</strong><br/>" +
"<b>Tuesday</b>: 1:00 PM - 6:00 PM", schedule);
"<b>Tuesday</b>: 1:00 PM - 6:00 PM", scheduleText);
}
@Test
......@@ -60,9 +57,10 @@ public class FacilityPresenterUnitTest {
mFacility.setMainSchedule(new MainSchedule(new RealmList<OpenTimes>(),
"2017-01-09", "2017-01-15"));
String schedule = mPresenter.getSchedule(mFacility, now);
Schedule schedule = mPresenter.getActiveSchedule(mFacility, now);
String scheduleText = mPresenter.getScheduleText(schedule, now);
assertEquals("No schedule available", schedule);
assertEquals("No schedule available", scheduleText);
}
@Test
......@@ -83,10 +81,11 @@ public class FacilityPresenterUnitTest {
// Set date
now.set(2017, 2, 9, 12, 0); // Thursday, 3/9/2017, 12:00:00
String schedule = mPresenter.getSchedule(mFacility, now);
Schedule schedule = mPresenter.getActiveSchedule(mFacility, now);
String scheduleText = mPresenter.getScheduleText(schedule, now);
assertEquals("<b>Monday</b>: 11:00 AM - 6:00 PM<br/>" +
"<b>Tuesday</b>: 1:00 PM - 6:00 PM", schedule);
"<b>Tuesday</b>: 1:00 PM - 6:00 PM", scheduleText);
}
@Test
......@@ -97,9 +96,10 @@ public class FacilityPresenterUnitTest {
mFacility.setMainSchedule(new MainSchedule(openTimesList,
"2017-01-09", "2017-01-15"));
String schedule = mPresenter.getSchedule(mFacility, now);
Schedule schedule = mPresenter.getActiveSchedule(mFacility, now);
String scheduleText = mPresenter.getScheduleText(schedule, now);
assertEquals("This facility is always open", schedule);
assertEquals("This facility is always open", scheduleText);
}
@Test
......@@ -110,9 +110,10 @@ public class FacilityPresenterUnitTest {
mFacility.setMainSchedule(new MainSchedule(openTimesList,
"2017-01-09", "2017-01-15"));
String schedule = mPresenter.getSchedule(mFacility, now);
Schedule schedule = mPresenter.getActiveSchedule(mFacility, now);
String scheduleText = mPresenter.getScheduleText(schedule, now);
assertEquals("<b>Saturday</b>: 8:00 AM - 9:00 AM<br/>" +
"<b>Sunday</b>: 8:00 AM - 9:00 AM", schedule);
"<b>Sunday</b>: 8:00 AM - 9:00 AM", scheduleText);
}
}
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