Search in sources :

Example 6 with ScheduleItem

use of com.instructure.canvasapi2.models.ScheduleItem in project instructure-android by instructure.

the class SyllabusRecyclerAdapter method populateAdapter.

private void populateAdapter(List<ScheduleItem> scheduleItems) {
    if (mCanvasContext.getType() == CanvasContext.Type.COURSE) {
        Course course = (Course) mCanvasContext;
        ScheduleItem syllabus = ScheduleItem.createSyllabus(course.getName(), course.getSyllabusBody());
        addOrUpdateItem(mSyllabus, syllabus);
    }
    Date curDate = new Date();
    // set a future date 7 days in the future, make it the end of the day to include every assignment within the next 7 days,
    // including assignments that are due at the end of the 7th day
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, 7);
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    Date weekFutureDate = calendar.getTime();
    for (ScheduleItem scheduleItem : scheduleItems) {
        // if it is hidden we don't want to show it. This can happen when an event has multiple sections
        if ((scheduleItem.isHidden())) {
            continue;
        }
        Date dueDate = scheduleItem.getStartAt();
        if (dueDate == null) {
            addOrUpdateItem(mNoDate, scheduleItem);
        } else if (dueDate.before(curDate)) {
            addOrUpdateItem(mPast, scheduleItem);
        } else if (((dueDate.after(curDate) && (dueDate.before(weekFutureDate))) || dueDate.equals(weekFutureDate))) {
            addOrUpdateItem(mNext7Days, scheduleItem);
        } else if (dueDate.after(weekFutureDate)) {
            addOrUpdateItem(mFuture, scheduleItem);
        }
    }
}
Also used : ScheduleItem(com.instructure.canvasapi2.models.ScheduleItem) Calendar(java.util.Calendar) Course(com.instructure.canvasapi2.models.Course) Date(java.util.Date)

Example 7 with ScheduleItem

use of com.instructure.canvasapi2.models.ScheduleItem in project instructure-android by instructure.

the class CalendarListRecyclerAdapterTest method testAreContentsTheSame_noAssignmentDifferentName.

@Test
public void testAreContentsTheSame_noAssignmentDifferentName() {
    ScheduleItem scheduleItem1 = new ScheduleItem();
    scheduleItem1.setTitle("ScheduleItem1a");
    Date date = new Date();
    scheduleItem1.setStartAt(date);
    ScheduleItem scheduleItem2 = new ScheduleItem();
    scheduleItem2.setTitle("ScheduleItem1b");
    scheduleItem2.setStartAt(date);
    assertFalse(mAdapter.createItemCallback().areContentsTheSame(scheduleItem1, scheduleItem2));
}
Also used : ScheduleItem(com.instructure.canvasapi2.models.ScheduleItem) Date(java.util.Date) Test(org.junit.Test)

Example 8 with ScheduleItem

use of com.instructure.canvasapi2.models.ScheduleItem in project instructure-android by instructure.

the class CalendarListRecyclerAdapterTest method testAreContentsTheSame_noAssignmentSame.

@Test
public void testAreContentsTheSame_noAssignmentSame() {
    ScheduleItem scheduleItem1 = new ScheduleItem();
    scheduleItem1.setTitle("ScheduleItem1");
    scheduleItem1.setStartAt(new Date());
    assertTrue(mAdapter.createItemCallback().areContentsTheSame(scheduleItem1, scheduleItem1));
}
Also used : ScheduleItem(com.instructure.canvasapi2.models.ScheduleItem) Date(java.util.Date) Test(org.junit.Test)

Example 9 with ScheduleItem

use of com.instructure.canvasapi2.models.ScheduleItem in project instructure-android by instructure.

the class CalendarListRecyclerAdapterTest method testAreContentsTheSame_sameAssignment.

@Test
public void testAreContentsTheSame_sameAssignment() {
    ScheduleItem scheduleItem1 = new ScheduleItem();
    scheduleItem1.setTitle("ScheduleItem1");
    scheduleItem1.setStartAt(new Date());
    Assignment assignment1 = new Assignment();
    assignment1.setDueAt(APIHelper.dateToString(new Date()));
    scheduleItem1.setAssignment(assignment1);
    assertTrue(mAdapter.createItemCallback().areContentsTheSame(scheduleItem1, scheduleItem1));
}
Also used : Assignment(com.instructure.canvasapi2.models.Assignment) ScheduleItem(com.instructure.canvasapi2.models.ScheduleItem) Date(java.util.Date) Test(org.junit.Test)

Example 10 with ScheduleItem

use of com.instructure.canvasapi2.models.ScheduleItem in project instructure-android by instructure.

the class SyllabusRecyclerAdapterTest method areContentsTheSame_NotNullSameDate.

@Test
public void areContentsTheSame_NotNullSameDate() {
    ScheduleItem item = new ScheduleItem();
    item.setTitle("item");
    item.setStartAt(new Date());
    assertTrue(mAdapter.createItemCallback().areContentsTheSame(item, item));
}
Also used : ScheduleItem(com.instructure.canvasapi2.models.ScheduleItem) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ScheduleItem (com.instructure.canvasapi2.models.ScheduleItem)29 Test (org.junit.Test)19 Date (java.util.Date)13 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)9 RestParams (com.instructure.canvasapi2.builders.RestParams)8 Assignment (com.instructure.canvasapi2.models.Assignment)7 ArrayList (java.util.ArrayList)5 View (android.view.View)3 Course (com.instructure.canvasapi2.models.Course)3 List (java.util.List)3 Drawable (android.graphics.drawable.Drawable)2 NonNull (android.support.annotation.NonNull)2 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 ToDo (com.instructure.canvasapi2.models.ToDo)2 Navigation (com.instructure.interactions.Navigation)2 DateTime (hirondelle.date4j.DateTime)2 Bundle (android.os.Bundle)1 TextView (android.widget.TextView)1 SyllabusRecyclerAdapter (com.instructure.candroid.adapter.SyllabusRecyclerAdapter)1