use of com.instructure.candroid.model.DateWindow in project instructure-android by instructure.
the class CalendarListViewFragment method weekClick.
private void weekClick(MenuItem item) {
currentCalendarView = CalendarView.WEEK_VIEW;
if (mRecyclerAdapter.getSelectedDay() != null) {
DateWindow dateWindow = CanvasCalendarUtils.setSelectedWeekWindow(new Date(mRecyclerAdapter.getSelectedDay().getMilliseconds(TimeZone.getDefault())), mRecyclerAdapter.isStartDayMonday());
mCalendarFragment.setSelectedDates(dateWindow.getStart(), dateWindow.getEnd());
}
mRecyclerAdapter.refreshListView();
mCalendarFragment.refreshView();
if (mCalendarContainer.getVisibility() == View.GONE) {
expandOrCollapseCalendar(mCalendarContainer, true);
}
item.setChecked(true);
}
use of com.instructure.candroid.model.DateWindow in project instructure-android by instructure.
the class CanvasCalendarUtils method setSelectedWeekWindow.
/**
* Another helper method, used to determine and select the date window to select to properly
* highlight a full week in the calendar grid.
*
* @param date - selected date
* @return DateWindow object
*/
public static DateWindow setSelectedWeekWindow(Date date, boolean isStartDayMonday) {
DateTime start = DateTime.forInstant(date.getTime(), TimeZone.getDefault());
DateTime end = DateTime.forInstant(date.getTime(), TimeZone.getDefault());
DateTime s1 = start;
DateTime e1 = end;
if (isStartDayMonday) {
// returns 1 - 7, sun - sat
int s = start.getWeekDay();
switch(s) {
case 1:
s1 = start.minus(0, 0, 6, 0, 0, 0, 0, DateTime.DayOverflow.FirstDay);
break;
case 2:
e1 = start.plus(0, 0, 6, 0, 0, 0, 0, DateTime.DayOverflow.FirstDay);
break;
case 3:
s1 = start.minus(0, 0, 1, 0, 0, 0, 0, DateTime.DayOverflow.FirstDay);
e1 = end.plus(0, 0, 5, 0, 0, 0, 0, DateTime.DayOverflow.LastDay);
break;
case 4:
s1 = start.minus(0, 0, 2, 0, 0, 0, 0, DateTime.DayOverflow.FirstDay);
e1 = end.plus(0, 0, 4, 0, 0, 0, 0, DateTime.DayOverflow.LastDay);
break;
case 5:
s1 = start.minus(0, 0, 3, 0, 0, 0, 0, DateTime.DayOverflow.FirstDay);
e1 = end.plus(0, 0, 3, 0, 0, 0, 0, DateTime.DayOverflow.LastDay);
break;
case 6:
s1 = start.minus(0, 0, 4, 0, 0, 0, 0, DateTime.DayOverflow.FirstDay);
e1 = end.plus(0, 0, 2, 0, 0, 0, 0, DateTime.DayOverflow.LastDay);
break;
case 7:
s1 = start.minus(0, 0, 5, 0, 0, 0, 0, DateTime.DayOverflow.FirstDay);
e1 = end.plus(0, 0, 1, 0, 0, 0, 0, DateTime.DayOverflow.LastDay);
break;
}
} else {
// returns 1 - 7, sun - sat
int s = start.getWeekDay();
switch(s) {
case 1:
e1 = start.plus(0, 0, 6, 0, 0, 0, 0, DateTime.DayOverflow.FirstDay);
break;
case 2:
s1 = start.minus(0, 0, 1, 0, 0, 0, 0, DateTime.DayOverflow.FirstDay);
e1 = end.plus(0, 0, 5, 0, 0, 0, 0, DateTime.DayOverflow.LastDay);
break;
case 3:
s1 = start.minus(0, 0, 2, 0, 0, 0, 0, DateTime.DayOverflow.FirstDay);
e1 = end.plus(0, 0, 4, 0, 0, 0, 0, DateTime.DayOverflow.LastDay);
break;
case 4:
s1 = start.minus(0, 0, 3, 0, 0, 0, 0, DateTime.DayOverflow.FirstDay);
e1 = end.plus(0, 0, 3, 0, 0, 0, 0, DateTime.DayOverflow.LastDay);
break;
case 5:
s1 = start.minus(0, 0, 4, 0, 0, 0, 0, DateTime.DayOverflow.FirstDay);
e1 = end.plus(0, 0, 2, 0, 0, 0, 0, DateTime.DayOverflow.LastDay);
break;
case 6:
s1 = start.minus(0, 0, 5, 0, 0, 0, 0, DateTime.DayOverflow.FirstDay);
e1 = end.plus(0, 0, 1, 0, 0, 0, 0, DateTime.DayOverflow.LastDay);
break;
case 7:
s1 = start.minus(0, 0, 6, 0, 0, 0, 0, DateTime.DayOverflow.FirstDay);
break;
}
}
Date startDate = new Date(s1.getEndOfDay().getMilliseconds(TimeZone.getDefault()));
Date endDate = new Date(e1.getEndOfDay().getMilliseconds(TimeZone.getDefault()));
return new DateWindow(startDate, endDate);
}
use of com.instructure.candroid.model.DateWindow in project instructure-android by instructure.
the class CalendarUtilsTest method testWeekWindow.
@Test
public void testWeekWindow() {
boolean startDayMonday;
// Test cases for start day Sunday
startDayMonday = false;
// Sunday
DateTime dateTime1 = new DateTime("2014-12-28");
Date date1 = new Date(dateTime1.getMilliseconds(TimeZone.getDefault()));
// Sunday
DateTime startTime = new DateTime("2014-12-28");
// Saturday
DateTime endTime = new DateTime("2015-01-03");
DateWindow dateWindow1 = CanvasCalendarUtils.setSelectedWeekWindow(date1, startDayMonday);
DateTime endTimeResult1 = DateTime.forInstant(dateWindow1.getEnd().getTime(), TimeZone.getDefault());
DateTime startTimeResult1 = DateTime.forInstant(dateWindow1.getStart().getTime(), TimeZone.getDefault());
assertTrue(startTimeResult1.getEndOfDay().compareTo(startTime.getEndOfDay()) == 0);
assertTrue(endTimeResult1.getEndOfDay().compareTo(endTime.getEndOfDay()) == 0);
assertTrue(CanvasCalendarUtils.isWithinWeekWindow(date1, dateWindow1.getStart(), dateWindow1.getStart()));
// Monday
DateTime dateTime2 = new DateTime("2014-12-29");
Date date2 = new Date(dateTime2.getMilliseconds(TimeZone.getDefault()));
DateWindow dateWindow2 = CanvasCalendarUtils.setSelectedWeekWindow(date2, startDayMonday);
DateTime endTimeResult2 = DateTime.forInstant(dateWindow2.getEnd().getTime(), TimeZone.getDefault());
DateTime startTimeResult2 = DateTime.forInstant(dateWindow2.getStart().getTime(), TimeZone.getDefault());
assertTrue(startTimeResult2.getEndOfDay().compareTo(startTime.getEndOfDay()) == 0);
assertTrue(endTimeResult2.getEndOfDay().compareTo(endTime.getEndOfDay()) == 0);
assertTrue(CanvasCalendarUtils.isWithinWeekWindow(date2, dateWindow2.getStart(), dateWindow2.getEnd()));
// Tuesday
DateTime dateTime3 = new DateTime("2014-12-30");
Date date3 = new Date(dateTime3.getMilliseconds(TimeZone.getDefault()));
DateWindow dateWindow3 = CanvasCalendarUtils.setSelectedWeekWindow(date3, startDayMonday);
DateTime endTimeResult3 = DateTime.forInstant(dateWindow3.getEnd().getTime(), TimeZone.getDefault());
DateTime startTimeResult3 = DateTime.forInstant(dateWindow3.getStart().getTime(), TimeZone.getDefault());
assertTrue(startTimeResult3.getEndOfDay().compareTo(startTime.getEndOfDay()) == 0);
assertTrue(endTimeResult3.getEndOfDay().compareTo(endTime.getEndOfDay()) == 0);
assertTrue(CanvasCalendarUtils.isWithinWeekWindow(date3, dateWindow3.getStart(), dateWindow3.getEnd()));
// Wednesday
DateTime dateTime4 = new DateTime("2014-12-31");
Date date4 = new Date(dateTime4.getMilliseconds(TimeZone.getDefault()));
DateWindow dateWindow4 = CanvasCalendarUtils.setSelectedWeekWindow(date4, startDayMonday);
DateTime endTimeResult4 = DateTime.forInstant(dateWindow4.getEnd().getTime(), TimeZone.getDefault());
DateTime startTimeResult4 = DateTime.forInstant(dateWindow4.getStart().getTime(), TimeZone.getDefault());
assertTrue(startTimeResult4.getEndOfDay().compareTo(startTime.getEndOfDay()) == 0);
assertTrue(endTimeResult4.getEndOfDay().compareTo(endTime.getEndOfDay()) == 0);
assertTrue(CanvasCalendarUtils.isWithinWeekWindow(date4, dateWindow4.getStart(), dateWindow4.getEnd()));
// Thursday
DateTime dateTime5 = new DateTime("2015-01-01");
Date date5 = new Date(dateTime5.getMilliseconds(TimeZone.getDefault()));
DateWindow dateWindow5 = CanvasCalendarUtils.setSelectedWeekWindow(date5, startDayMonday);
DateTime endTimeResult5 = DateTime.forInstant(dateWindow5.getEnd().getTime(), TimeZone.getDefault());
DateTime startTimeResult5 = DateTime.forInstant(dateWindow5.getStart().getTime(), TimeZone.getDefault());
assertTrue(startTimeResult5.getEndOfDay().compareTo(startTime.getEndOfDay()) == 0);
assertTrue(endTimeResult5.getEndOfDay().compareTo(endTime.getEndOfDay()) == 0);
assertTrue(CanvasCalendarUtils.isWithinWeekWindow(date5, dateWindow5.getStart(), dateWindow5.getEnd()));
// Friday
DateTime dateTime6 = new DateTime("2015-01-02");
Date date6 = new Date(dateTime6.getMilliseconds(TimeZone.getDefault()));
DateWindow dateWindow6 = CanvasCalendarUtils.setSelectedWeekWindow(date6, startDayMonday);
DateTime endTimeResult6 = DateTime.forInstant(dateWindow6.getEnd().getTime(), TimeZone.getDefault());
DateTime startTimeResult6 = DateTime.forInstant(dateWindow6.getStart().getTime(), TimeZone.getDefault());
assertTrue(startTimeResult6.getEndOfDay().compareTo(startTime.getEndOfDay()) == 0);
assertTrue(endTimeResult6.getEndOfDay().compareTo(endTime.getEndOfDay()) == 0);
assertTrue(CanvasCalendarUtils.isWithinWeekWindow(date6, dateWindow6.getStart(), dateWindow6.getEnd()));
// saturday
DateTime dateTime7 = new DateTime("2015-01-02");
Date date7 = new Date(dateTime7.getMilliseconds(TimeZone.getDefault()));
DateWindow dateWindow7 = CanvasCalendarUtils.setSelectedWeekWindow(date4, startDayMonday);
DateTime endTimeResult7 = DateTime.forInstant(dateWindow7.getEnd().getTime(), TimeZone.getDefault());
DateTime startTimeResult7 = DateTime.forInstant(dateWindow7.getStart().getTime(), TimeZone.getDefault());
assertTrue(startTimeResult7.getEndOfDay().compareTo(startTime.getEndOfDay()) == 0);
assertTrue(endTimeResult7.getEndOfDay().compareTo(endTime.getEndOfDay()) == 0);
assertTrue(CanvasCalendarUtils.isWithinWeekWindow(date7, dateWindow7.getStart(), dateWindow7.getEnd()));
// ///////////////////////////////////
// Test cases for start day Monday //
// ///////////////////////////////////
startDayMonday = true;
// Monday
DateTime dateTime1m = new DateTime("2014-12-29");
Date date1m = new Date(dateTime1m.getMilliseconds(TimeZone.getDefault()));
// Monday
DateTime startTimeM = new DateTime("2014-12-29");
// Sunday
DateTime endTimeM = new DateTime("2015-01-04");
DateWindow dateWindow1m = CanvasCalendarUtils.setSelectedWeekWindow(date1m, startDayMonday);
DateTime endTimeResult1m = DateTime.forInstant(dateWindow1m.getEnd().getTime(), TimeZone.getDefault());
DateTime startTimeResult1m = DateTime.forInstant(dateWindow1m.getStart().getTime(), TimeZone.getDefault());
assertTrue(startTimeResult1m.getEndOfDay().compareTo(startTimeM.getEndOfDay()) == 0);
assertTrue(endTimeResult1m.getEndOfDay().compareTo(endTimeM.getEndOfDay()) == 0);
assertTrue(CanvasCalendarUtils.isWithinWeekWindow(date1m, dateWindow1.getStart(), dateWindow1m.getEnd()));
// Tuesday
DateTime dateTime2m = new DateTime("2014-12-30");
Date date2m = new Date(dateTime2.getMilliseconds(TimeZone.getDefault()));
DateWindow dateWindow2m = CanvasCalendarUtils.setSelectedWeekWindow(date2m, startDayMonday);
DateTime endTimeResult2m = DateTime.forInstant(dateWindow2m.getEnd().getTime(), TimeZone.getDefault());
DateTime startTimeResult2m = DateTime.forInstant(dateWindow2m.getStart().getTime(), TimeZone.getDefault());
assertTrue(startTimeResult2m.getEndOfDay().compareTo(startTimeM.getEndOfDay()) == 0);
assertTrue(endTimeResult2m.getEndOfDay().compareTo(endTimeM.getEndOfDay()) == 0);
assertTrue(CanvasCalendarUtils.isWithinWeekWindow(date2m, dateWindow2m.getStart(), dateWindow2m.getEnd()));
// Wednesday
DateTime dateTime3m = new DateTime("2014-12-31");
Date date3m = new Date(dateTime3m.getMilliseconds(TimeZone.getDefault()));
DateWindow dateWindow3m = CanvasCalendarUtils.setSelectedWeekWindow(date3m, startDayMonday);
DateTime endTimeResult3m = DateTime.forInstant(dateWindow3m.getEnd().getTime(), TimeZone.getDefault());
DateTime startTimeResult3m = DateTime.forInstant(dateWindow3m.getStart().getTime(), TimeZone.getDefault());
assertTrue(startTimeResult3m.getEndOfDay().compareTo(startTimeM.getEndOfDay()) == 0);
assertTrue(endTimeResult3m.getEndOfDay().compareTo(endTimeM.getEndOfDay()) == 0);
assertTrue(CanvasCalendarUtils.isWithinWeekWindow(date3m, dateWindow3m.getStart(), dateWindow3m.getEnd()));
// Thursday
DateTime dateTime4m = new DateTime("2015-01-01");
Date date4m = new Date(dateTime4m.getMilliseconds(TimeZone.getDefault()));
DateWindow dateWindow4m = CanvasCalendarUtils.setSelectedWeekWindow(date4m, startDayMonday);
DateTime endTimeResult4m = DateTime.forInstant(dateWindow4m.getEnd().getTime(), TimeZone.getDefault());
DateTime startTimeResult4m = DateTime.forInstant(dateWindow4m.getStart().getTime(), TimeZone.getDefault());
assertTrue(startTimeResult4m.getEndOfDay().compareTo(startTimeM.getEndOfDay()) == 0);
assertTrue(endTimeResult4m.getEndOfDay().compareTo(endTimeM.getEndOfDay()) == 0);
assertTrue(CanvasCalendarUtils.isWithinWeekWindow(date4m, dateWindow4m.getStart(), dateWindow4m.getEnd()));
// Friday
DateTime dateTime5m = new DateTime("2015-01-02");
Date date5m = new Date(dateTime5m.getMilliseconds(TimeZone.getDefault()));
DateWindow dateWindow5m = CanvasCalendarUtils.setSelectedWeekWindow(date5, startDayMonday);
DateTime endTimeResult5m = DateTime.forInstant(dateWindow5m.getEnd().getTime(), TimeZone.getDefault());
DateTime startTimeResult5m = DateTime.forInstant(dateWindow5m.getStart().getTime(), TimeZone.getDefault());
assertTrue(startTimeResult5m.getEndOfDay().compareTo(startTimeM.getEndOfDay()) == 0);
assertTrue(endTimeResult5m.getEndOfDay().compareTo(endTimeM.getEndOfDay()) == 0);
assertTrue(CanvasCalendarUtils.isWithinWeekWindow(date5m, dateWindow5m.getStart(), dateWindow5m.getEnd()));
// Saturday
DateTime dateTime6m = new DateTime("2015-01-03");
Date date6m = new Date(dateTime6m.getMilliseconds(TimeZone.getDefault()));
DateWindow dateWindow6m = CanvasCalendarUtils.setSelectedWeekWindow(date6m, startDayMonday);
DateTime endTimeResult6m = DateTime.forInstant(dateWindow6m.getEnd().getTime(), TimeZone.getDefault());
DateTime startTimeResult6m = DateTime.forInstant(dateWindow6m.getStart().getTime(), TimeZone.getDefault());
assertTrue(startTimeResult6m.getEndOfDay().compareTo(startTimeM.getEndOfDay()) == 0);
assertTrue(endTimeResult6m.getEndOfDay().compareTo(endTimeM.getEndOfDay()) == 0);
assertTrue(CanvasCalendarUtils.isWithinWeekWindow(date6m, dateWindow6m.getStart(), dateWindow6m.getEnd()));
// Sunday
DateTime dateTime7m = new DateTime("2015-01-04");
Date date7m = new Date(dateTime7m.getMilliseconds(TimeZone.getDefault()));
DateWindow dateWindow7m = CanvasCalendarUtils.setSelectedWeekWindow(date7m, startDayMonday);
DateTime endTimeResult7m = DateTime.forInstant(dateWindow7m.getEnd().getTime(), TimeZone.getDefault());
DateTime startTimeResult7m = DateTime.forInstant(dateWindow7m.getStart().getTime(), TimeZone.getDefault());
assertTrue(startTimeResult7m.getEndOfDay().compareTo(startTimeM.getEndOfDay()) == 0);
assertTrue(endTimeResult7m.getEndOfDay().compareTo(endTimeM.getEndOfDay()) == 0);
assertTrue(CanvasCalendarUtils.isWithinWeekWindow(date7m, dateWindow7m.getStart(), dateWindow7m.getEnd()));
}
use of com.instructure.candroid.model.DateWindow in project instructure-android by instructure.
the class CalendarListViewFragment method setUpListeners.
private void setUpListeners() {
final CaldroidListener listener = new CaldroidListener() {
@Override
public void onSelectDate(Date date, View view) {
// New date selected, clear out prior
mCalendarFragment.clearSelectedDates();
mRecyclerAdapter.setSelectedDay(DateTime.forInstant(date.getTime(), TimeZone.getDefault()));
if (currentCalendarView == CalendarView.DAY_VIEW) {
mCalendarFragment.setSelectedDates(date, date);
} else if (currentCalendarView == CalendarView.WEEK_VIEW) {
DateWindow dateWindow = CanvasCalendarUtils.setSelectedWeekWindow(date, mRecyclerAdapter.isStartDayMonday());
mCalendarFragment.setSelectedDates(dateWindow.getStart(), dateWindow.getEnd());
}
mCalendarFragment.refreshView();
mRecyclerAdapter.refreshListView();
}
@Override
public void onCaldroidViewCreated() {
super.onCaldroidViewCreated();
// Removing styling for upper buttons
Button leftButton = mCalendarFragment.getLeftArrowButton();
Button rightButton = mCalendarFragment.getRightArrowButton();
TextView textView = mCalendarFragment.getMonthTitleTextView();
leftButton.setVisibility(View.GONE);
rightButton.setVisibility(View.GONE);
textView.setVisibility(View.GONE);
// Initialize post view created mCalendarFragment elements
InfiniteViewPager viewPager = mCalendarFragment.getDateViewPager();
viewPager.setPageMargin((int) ViewUtils.convertDipsToPixels(32, getContext()));
if (mRecyclerAdapter.getSelectedDay() == null) {
mRecyclerAdapter.setSelectedDay(DateTime.today(TimeZone.getDefault()));
Date today = new Date(mRecyclerAdapter.getSelectedDay().getMilliseconds(TimeZone.getDefault()));
mCalendarFragment.setSelectedDates(today, today);
}
mRecyclerAdapter.setCalendarViewCreated(true);
applyTheme();
}
@Override
public void onChangeMonth(int month, int year, boolean fromCreation) {
super.onChangeMonth(month, year, fromCreation);
if (mRecyclerAdapter != null && mRecyclerAdapter.getSelectedDay() != null && month == mRecyclerAdapter.getSelectedDay().getMonth()) {
// listener. We don't want to trigger the month change logic if the month is not changing.
return;
}
if (mMonthText != null) {
if (fromCreation || hasOrientationChanged()) {
hidePanda();
return;
}
// Update Actionbar
mMonthText.setText(new DateFormatSymbols().getMonths()[month - 1] + " " + year);
}
// First time loading the calendar will trigger this, but the API calls have already been made
if (!mRecyclerAdapter.isTodayPressed() && !fromCreation) {
// Refresh for month, unless this was triggered by "today" button
mCalendarFragment.clearSelectedDates();
DateTime today = DateTime.today(TimeZone.getDefault());
if (today.getMonth() == month && today.getYear() == year) {
mRecyclerAdapter.setSelectedDay(today);
} else {
mRecyclerAdapter.setSelectedDay(new DateTime(year, month, 1, null, null, null, null));
}
mRecyclerAdapter.refreshCalendar();
}
}
};
mCalendarFragment.setCaldroidListener(listener);
}
use of com.instructure.candroid.model.DateWindow in project instructure-android by instructure.
the class CalendarListRecyclerAdapter method selectDateAfterLoad.
private void selectDateAfterLoad() {
if (mSelectedDay != null) {
Date selected = new Date(mSelectedDay.getMilliseconds(TimeZone.getDefault()));
CalendarListViewFragment.CalendarView currentCalendarView = CalendarListViewFragment.CalendarView.fromInteger(mAdapterToCalendarCallback.getCurrentCalendarView());
if (currentCalendarView == CalendarListViewFragment.CalendarView.DAY_VIEW) {
mAdapterToCalendarCallback.setSelectedDates(selected, selected);
} else if (currentCalendarView == CalendarListViewFragment.CalendarView.WEEK_VIEW) {
DateWindow dateWindow = CanvasCalendarUtils.setSelectedWeekWindow(selected, mIsStartDayMonday);
mAdapterToCalendarCallback.setSelectedDates(dateWindow.getStart(), dateWindow.getEnd());
}
refreshListView();
}
}
Aggregations