Search in sources :

Example 6 with Assignment

use of com.instructure.canvasapi.model.Assignment in project instructure-android by instructure.

the class RubricFragment method getBundleData.

// /////////////////////////////////////////////////////////////////////////
// Intent Stuff
// /////////////////////////////////////////////////////////////////////////
@Override
public void getBundleData(Bundle bundle) {
    // Since the markGrades method will alter the rubric on an mAssignment. We need to copy the mAssignment, so that grading a mSubmission will not affect others
    Assignment newAssignment = bundle.getParcelable(Const.assignment);
    mOriginalAssignment = SerializationUtils.clone(newAssignment);
    mAssignment = SerializationUtils.clone(newAssignment);
    mSubmission = bundle.getParcelable(Const.submission);
    mAssignment.setLastSubmission(mSubmission);
    originalRubricAssessment = SerializationUtils.clone(mSubmission.getRubricAssessment());
    if (mSubmission.getAttachments() != null) {
        currentAttachment = mSubmission.getAttachments().get(0);
    }
}
Also used : Assignment(com.instructure.canvasapi.model.Assignment)

Example 7 with Assignment

use of com.instructure.canvasapi.model.Assignment in project instructure-android by instructure.

the class ToDoAPI method mergeToDoUpcoming.

// ///////////////////////////////////////////////////////////////////////////
// Helper Methods
// ///////////////////////////////////////////////////////////////////////////
public static ArrayList<ToDo> mergeToDoUpcoming(ArrayList<ToDo> todos, ArrayList<ToDo> upcomingEvents) {
    if (todos == null && upcomingEvents == null) {
        return null;
    }
    if (todos == null) {
        todos = new ArrayList<ToDo>();
    }
    if (upcomingEvents == null) {
        upcomingEvents = new ArrayList<ToDo>();
    }
    // Add all Assignment ids from TODO
    HashMap<Long, Boolean> assignmentIds = new HashMap<Long, Boolean>();
    for (ToDo toDo : todos) {
        if (toDo.getAssignment() != null) {
            assignmentIds.put(toDo.getAssignment().getId(), true);
        }
    }
    // If the hashmap contains any assignment ids from Upcoming, it's a duplicate
    Iterator<ToDo> iterator = upcomingEvents.iterator();
    while (iterator.hasNext()) {
        ToDo current = iterator.next();
        Assignment assignment = current.getScheduleItem().getAssignment();
        if (assignment != null && assignmentIds.containsKey(assignment.getId())) {
            // We already have it in ToDo so remove the item.
            iterator.remove();
        }
    }
    int todoIndex = 0;
    int upcomingIndex = 0;
    ArrayList<ToDo> merged = new ArrayList<ToDo>();
    while (todoIndex < todos.size() || upcomingIndex < upcomingEvents.size()) {
        // We only have upcoming left.
        if (todoIndex >= todos.size()) {
            List<ToDo> subset = upcomingEvents.subList(upcomingIndex, upcomingEvents.size());
            for (ToDo upcomming : subset) {
                merged.add(upcomming);
            }
            return merged;
        }
        // We only have todo left.
        if (upcomingIndex >= upcomingEvents.size()) {
            List<ToDo> subset = todos.subList(todoIndex, todos.size());
            for (ToDo td : subset) {
                merged.add(td);
            }
            return merged;
        }
        // We need to determine which one comes sooner.
        Date toDoDate;
        if (todos.get(todoIndex).getAssignment() == null) {
            toDoDate = null;
        } else {
            toDoDate = todos.get(todoIndex).getAssignment().getDueDate();
        }
        Date upcomingDate = upcomingEvents.get(upcomingIndex).getScheduleItem().getStartDate();
        // handle null cases first
        if (toDoDate == null) {
            merged.add(upcomingEvents.get(upcomingIndex));
            upcomingIndex++;
        } else if (upcomingDate == null) {
            merged.add(todos.get(todoIndex));
            todoIndex++;
        } else if (toDoDate.before(upcomingDate)) {
            merged.add(todos.get(todoIndex));
            todoIndex++;
        } else {
            merged.add(upcomingEvents.get(upcomingIndex));
            upcomingIndex++;
        }
    }
    // Should never get here.
    return merged;
}
Also used : Assignment(com.instructure.canvasapi.model.Assignment) ToDo(com.instructure.canvasapi.model.ToDo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 8 with Assignment

use of com.instructure.canvasapi.model.Assignment in project instructure-android by instructure.

the class AssignmentUnitTest method testLockedAssignment.

@Test
public void testLockedAssignment() {
    Gson gson = CanvasRestAdapter.getGSONParser();
    Assignment lockInfoAssignment = gson.fromJson(lockInfoJSON, Assignment.class);
    // If the assignment is locked for the user, make sure the lock_info & explanation aren't empty/null
    if (lockInfoAssignment.isLockedForUser()) {
        assertTrue(!lockInfoAssignment.getLockInfo().isEmpty());
        assertNotNull(lockInfoAssignment.getLock_explanation());
    }
    LockInfo lockInfo = lockInfoAssignment.getLockInfo();
    assertNotNull(lockInfo);
    // The lock_info should have a context_module
    LockedModule lockedModule = lockInfo.getContext_module();
    assertNotNull(lockedModule);
    assertNotNull(lockedModule.getId());
    assertNotNull(lockedModule.getContext_id());
    assertNotNull(lockedModule.getContextType());
    assertNotNull(lockedModule.getName());
    assertNotNull(lockedModule.getUnlock_at());
    assertNotNull(lockedModule.isRequireSequentialProgress());
    List<ModuleCompletionRequirement> completionRequirements = lockedModule.getCompletionRequirements();
    assertNotNull(completionRequirements);
    assertEquals(9, completionRequirements.size());
    for (ModuleCompletionRequirement requirement : completionRequirements) {
        assertNotNull(requirement.getId());
        assertNotNull(requirement.getType());
    }
}
Also used : Assignment(com.instructure.canvasapi.model.Assignment) LockedModule(com.instructure.canvasapi.model.LockedModule) Gson(com.google.gson.Gson) LockInfo(com.instructure.canvasapi.model.LockInfo) ModuleCompletionRequirement(com.instructure.canvasapi.model.ModuleCompletionRequirement) Test(org.junit.Test)

Example 9 with Assignment

use of com.instructure.canvasapi.model.Assignment in project instructure-android by instructure.

the class AssignmentUnitTest method testAssignment.

@Test
public void testAssignment() {
    Gson gson = CanvasRestAdapter.getGSONParser();
    Assignment assignment = gson.fromJson(assignmentJSON, Assignment.class);
    assertTrue(assignment.getId() > 0);
    assertEquals(assignment.getPointsPossible(), 30.0);
    assertEquals(assignment.getSubmissionTypes().size(), 3);
    assertTrue(assignment.getSubmissionTypes().get(0).toString().equalsIgnoreCase("online_upload"));
    assertTrue(assignment.getSubmissionTypes().get(1).toString().equalsIgnoreCase("online_text_entry"));
    assertTrue(assignment.getSubmissionTypes().get(2).toString().equalsIgnoreCase("media_recording"));
    assertEquals(assignment.getAllowedExtensions().size(), 3);
    assertTrue(assignment.getAllowedExtensions().get(0).equalsIgnoreCase("doc"));
    assertTrue(assignment.getAllowedExtensions().get(1).equalsIgnoreCase("pdf"));
    assertTrue(assignment.getAllowedExtensions().get(2).equalsIgnoreCase("txt"));
    assertEquals(assignment.getCourseId(), 833052);
    assertNotNull(assignment.getDescription());
    assertNotNull(assignment.getDueDate());
    assertNotNull(assignment.getName());
    assertNotNull(assignment.getLastSubmission());
    assertEquals(assignment.getAssignmentGroupId(), 534100);
}
Also used : Assignment(com.instructure.canvasapi.model.Assignment) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 10 with Assignment

use of com.instructure.canvasapi.model.Assignment in project instructure-android by instructure.

the class AssignmentUnitTest method testAssignmentDueDate.

@Test
public void testAssignmentDueDate() {
    Gson gson = CanvasRestAdapter.getGSONParser();
    Assignment assignment = gson.fromJson(assignmentDueDates, Assignment.class);
    List<AssignmentDueDate> allDates = assignment.getDueDates();
    assertEquals(allDates.size(), 2);
    for (AssignmentDueDate dueDate : allDates) {
        assertNotNull(dueDate.getDueDate());
    }
}
Also used : Assignment(com.instructure.canvasapi.model.Assignment) AssignmentDueDate(com.instructure.canvasapi.model.AssignmentDueDate) Gson(com.google.gson.Gson) Test(org.junit.Test)

Aggregations

Assignment (com.instructure.canvasapi.model.Assignment)15 Gson (com.google.gson.Gson)7 Test (org.junit.Test)7 AssignmentGroup (com.instructure.canvasapi.model.AssignmentGroup)2 ToDo (com.instructure.canvasapi.model.ToDo)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 CheckBox (android.widget.CheckBox)1 AssignmentDueDate (com.instructure.canvasapi.model.AssignmentDueDate)1 LockInfo (com.instructure.canvasapi.model.LockInfo)1 LockedModule (com.instructure.canvasapi.model.LockedModule)1 MasteryPathAssignment (com.instructure.canvasapi.model.MasteryPathAssignment)1 ModuleCompletionRequirement (com.instructure.canvasapi.model.ModuleCompletionRequirement)1 RubricCriterion (com.instructure.canvasapi.model.RubricCriterion)1 ScheduleItem (com.instructure.canvasapi.model.ScheduleItem)1 Section (com.instructure.canvasapi.model.Section)1 HomeActivity (com.instructure.speedgrader.activities.HomeActivity)1 AssignmentGroupListRecyclerAdapter (com.instructure.speedgrader.adapters.AssignmentGroupListRecyclerAdapter)1 AssignmentAdapterToFragmentCallback (com.instructure.speedgrader.interfaces.AssignmentAdapterToFragmentCallback)1