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);
}
}
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;
}
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());
}
}
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);
}
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());
}
}
Aggregations