Search in sources :

Example 6 with DateWindow

use of com.instructure.candroid.model.DateWindow in project instructure-android by instructure.

the class CalendarListRecyclerAdapter method addItemForViewType.

/**
 * A small helper method to make adding items to our adapter simpler
 *
 * @param s
 * @return
 */
private boolean addItemForViewType(ScheduleItem s) {
    Date d = s.getStartAt();
    if (d == null) {
        return false;
    }
    DateTime dateTime = DateTime.forInstant(d.getTime(), TimeZone.getDefault());
    CalendarListViewFragment.CalendarView currentCalendarView = CalendarListViewFragment.CalendarView.fromInteger(mAdapterToCalendarCallback.getCurrentCalendarView());
    if (currentCalendarView == CalendarListViewFragment.CalendarView.DAY_VIEW && mSelectedDay != null) {
        if (dateTime.getDay().equals(mSelectedDay.getDay()) && dateTime.getMonth().equals(mSelectedDay.getMonth())) {
            addOrUpdateItem(DateHelper.getCleanDate(d.getTime()), s);
        }
    } else if (currentCalendarView == CalendarListViewFragment.CalendarView.WEEK_VIEW && mSelectedDay != null) {
        Date selectedDate = new Date(mSelectedDay.getMilliseconds(TimeZone.getDefault()));
        DateWindow dateWindow = CanvasCalendarUtils.setSelectedWeekWindow(selectedDate, mIsStartDayMonday);
        if (CanvasCalendarUtils.isWithinWeekWindow(d, dateWindow.getStart(), dateWindow.getEnd())) {
            addOrUpdateItem(DateHelper.getCleanDate(d.getTime()), s);
        }
    } else if (currentCalendarView == CalendarListViewFragment.CalendarView.MONTH_VIEW) {
        addOrUpdateItem(DateHelper.getCleanDate(d.getTime()), s);
    }
    return true;
}
Also used : DateWindow(com.instructure.candroid.model.DateWindow) CalendarListViewFragment(com.instructure.candroid.fragment.CalendarListViewFragment) Date(java.util.Date) DateTime(hirondelle.date4j.DateTime)

Aggregations

DateWindow (com.instructure.candroid.model.DateWindow)6 Date (java.util.Date)6 DateTime (hirondelle.date4j.DateTime)4 CalendarListViewFragment (com.instructure.candroid.fragment.CalendarListViewFragment)2 View (android.view.View)1 Button (android.widget.Button)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 InfiniteViewPager (com.antonyt.infiniteviewpager.InfiniteViewPager)1 PageView (com.instructure.canvasapi2.utils.pageview.PageView)1 CaldroidListener (com.roomorama.caldroid.CaldroidListener)1 DateFormatSymbols (java.text.DateFormatSymbols)1 Test (org.junit.Test)1