Commit eef4c0ce authored by Robert Hitt's avatar Robert Hitt

Merge branch '26-special-schedule-text' into 'master'

Added text for the special schedules' duration

Closes #26

See merge request !9
parents 2abd3997 88e7719d
Pipeline #1343 failed with stages
in 2 minutes and 48 seconds
...@@ -19,6 +19,7 @@ import io.realm.RealmList; ...@@ -19,6 +19,7 @@ import io.realm.RealmList;
import srct.whatsopen.R; import srct.whatsopen.R;
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.views.FacilityView; import srct.whatsopen.views.FacilityView;
...@@ -73,8 +74,8 @@ public class FacilityPresenter { ...@@ -73,8 +74,8 @@ public class FacilityPresenter {
// Parses the schedule into an HTML string. // Parses the schedule into an HTML string.
// Kind of a hacky approach. That being said, this is certainly a lot simpler to test // Kind of a hacky approach. That being said, this is certainly a lot simpler to test
// than the alternative. // than the alternative.
public String getSchedule(Facility facility, Calendar now) { public String getScheduleText(Schedule schedule, Calendar now) {
RealmList<OpenTimes> openTimesList = getActiveSchedule(facility, now); 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(openTimesList.size() == 0) if(openTimesList.size() == 0)
...@@ -143,6 +144,19 @@ public class FacilityPresenter { ...@@ -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 // Parses an integer to a String of the day of the week
public static String parseIntToDay(int day) { public static String parseIntToDay(int day) {
switch(day) { switch(day) {
...@@ -166,8 +180,8 @@ public class FacilityPresenter { ...@@ -166,8 +180,8 @@ public class FacilityPresenter {
} }
// Returns the active schedule given the current date // Returns the active schedule given the current date
private RealmList<OpenTimes> getActiveSchedule(Facility facility, Calendar now) { public 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 {
...@@ -178,8 +192,7 @@ public class FacilityPresenter { ...@@ -178,8 +192,7 @@ public class FacilityPresenter {
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) {
...@@ -187,6 +200,6 @@ public class FacilityPresenter { ...@@ -187,6 +200,6 @@ public class FacilityPresenter {
return null; return null;
} }
return openTimesList; return schedule;
} }
} }
...@@ -35,6 +35,8 @@ import srct.whatsopen.MyApplication; ...@@ -35,6 +35,8 @@ import srct.whatsopen.MyApplication;
import srct.whatsopen.R; import srct.whatsopen.R;
import srct.whatsopen.model.Facility; import srct.whatsopen.model.Facility;
import srct.whatsopen.model.NotificationSettings; import srct.whatsopen.model.NotificationSettings;
import srct.whatsopen.model.Schedule;
import srct.whatsopen.model.SpecialSchedule;
import srct.whatsopen.views.FacilityView; import srct.whatsopen.views.FacilityView;
import srct.whatsopen.presenters.FacilityPresenter; import srct.whatsopen.presenters.FacilityPresenter;
import srct.whatsopen.views.fragments.NotificationDialogFragment; import srct.whatsopen.views.fragments.NotificationDialogFragment;
...@@ -51,6 +53,8 @@ public class DetailActivity extends AppCompatActivity implements FacilityView, ...@@ -51,6 +53,8 @@ public class DetailActivity extends AppCompatActivity implements FacilityView,
TextView locationTextView; TextView locationTextView;
@BindView(R.id.schedule_text) @BindView(R.id.schedule_text)
TextView scheduleTextView; TextView scheduleTextView;
@BindView(R.id.special_schedule_duration_text)
TextView specialScheduleDurationTextView;
@BindView(R.id.notification_button) @BindView(R.id.notification_button)
Button notificationButton; Button notificationButton;
...@@ -83,7 +87,7 @@ public class DetailActivity extends AppCompatActivity implements FacilityView, ...@@ -83,7 +87,7 @@ public class DetailActivity extends AppCompatActivity implements FacilityView,
private void setUpAnimations() { private void setUpAnimations() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Slide slide = new Slide(); Slide slide = new Slide();
slide.setSlideEdge(Gravity.LEFT); slide.setSlideEdge(Gravity.BOTTOM);
slide.setDuration(300); slide.setDuration(300);
getWindow().setEnterTransition(slide); getWindow().setEnterTransition(slide);
} }
...@@ -198,8 +202,18 @@ public class DetailActivity extends AppCompatActivity implements FacilityView, ...@@ -198,8 +202,18 @@ public class DetailActivity extends AppCompatActivity implements FacilityView,
locationTextView.setText(mFacility.getLocation()); locationTextView.setText(mFacility.getLocation());
scheduleTextView.setText(Html.fromHtml(mPresenter Calendar now = Calendar.getInstance();
.getSchedule(mFacility, 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 // Sets the notification button text to edit if a Notification exists
......
...@@ -129,6 +129,14 @@ ...@@ -129,6 +129,14 @@
android:textColor="@color/colorPrimary" android:textColor="@color/colorPrimary"
android:textSize="26sp"/> 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 <TextView
android:id="@+id/schedule_text" android:id="@+id/schedule_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
......
...@@ -129,6 +129,14 @@ ...@@ -129,6 +129,14 @@
android:textColor="@color/colorPrimary" android:textColor="@color/colorPrimary"
android:textSize="26sp"/> 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 <TextView
android:id="@+id/schedule_text" android:id="@+id/schedule_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
......
package srct.whatsopen; package srct.whatsopen;
import android.content.Context;
import android.graphics.Path;
import android.support.v7.app.AppCompatActivity;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -13,8 +9,8 @@ import io.realm.RealmList; ...@@ -13,8 +9,8 @@ import io.realm.RealmList;
import srct.whatsopen.model.Facility; import srct.whatsopen.model.Facility;
import srct.whatsopen.model.MainSchedule; import srct.whatsopen.model.MainSchedule;
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.views.FacilityView;
import srct.whatsopen.presenters.FacilityPresenter; import srct.whatsopen.presenters.FacilityPresenter;
import static org.junit.Assert.*; import static org.junit.Assert.*;
...@@ -49,10 +45,11 @@ public class FacilityPresenterUnitTest { ...@@ -49,10 +45,11 @@ public class FacilityPresenterUnitTest {
public void testFacilitySchedule() { public void testFacilitySchedule() {
// 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
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/>" + 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 @Test
...@@ -60,9 +57,10 @@ public class FacilityPresenterUnitTest { ...@@ -60,9 +57,10 @@ public class FacilityPresenterUnitTest {
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"));
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 @Test
...@@ -83,10 +81,11 @@ public class FacilityPresenterUnitTest { ...@@ -83,10 +81,11 @@ public class FacilityPresenterUnitTest {
// Set date // Set date
now.set(2017, 2, 9, 12, 0); // Thursday, 3/9/2017, 12:00:00 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/>" + 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 @Test
...@@ -97,9 +96,10 @@ public class FacilityPresenterUnitTest { ...@@ -97,9 +96,10 @@ public class FacilityPresenterUnitTest {
mFacility.setMainSchedule(new MainSchedule(openTimesList, mFacility.setMainSchedule(new MainSchedule(openTimesList,
"2017-01-09", "2017-01-15")); "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 @Test
...@@ -110,9 +110,10 @@ public class FacilityPresenterUnitTest { ...@@ -110,9 +110,10 @@ public class FacilityPresenterUnitTest {
mFacility.setMainSchedule(new MainSchedule(openTimesList, mFacility.setMainSchedule(new MainSchedule(openTimesList,
"2017-01-09", "2017-01-15")); "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/>" + 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