use of com.instructure.canvasapi.model.Submission in project instructure-android by instructure.
the class DocumentActivity method createEmptySubmissionForUser.
// Dropdown students list needs to create an empty submission for all users so teachers can still grade them.
public Submission createEmptySubmissionForUser(User user) {
Submission emptyUserSubmission = new Submission();
emptyUserSubmission.setUser(user);
emptyUserSubmission.setId(mApp.getUniqueId());
emptyUserSubmission.setUser_id(user.getId());
emptyUserSubmission.setWorkflowState(Const.UNSUBMITTED);
return emptyUserSubmission;
}
use of com.instructure.canvasapi.model.Submission in project instructure-android by instructure.
the class DocumentActivity method addEmptySubmissionsForUsersAndGetGradedCount.
/**
* CanvasAPI will return a submission for students who have turned in an mAssignment. Given a list of all students
* in the course, we need to generate a dummy Submission object with a username that can be passed to our
* submissions adapter.
*
* @param submissions
* @param courseStudents
* @return
*/
public ArrayList<Submission> addEmptySubmissionsForUsersAndGetGradedCount(Submission[] submissions, User[] courseStudents) {
ArrayList<Submission> tempSubmissions = new ArrayList<>(Arrays.asList(submissions));
ArrayList<User> tempUsers = new ArrayList<>(Arrays.asList(courseStudents));
for (Submission submission : tempSubmissions) {
tempUsers.remove(submission.getUser());
if (UserSubmissionsListAdapter.isGraded(submission)) {
gradedCount++;
}
}
for (User user : tempUsers) {
tempSubmissions.add(createEmptySubmissionForUser(user));
}
return tempSubmissions;
}
use of com.instructure.canvasapi.model.Submission in project instructure-android by instructure.
the class DocumentActivity method onSubmissionListUpdated.
@Override
public void onSubmissionListUpdated() {
mAdapter.notifyDataSetChanged();
mViewpager.invalidate();
Submission currentSubmission = getCurrentSubmissionInViewpager();
if (currentSubmission != null && currentSubmission.getUser() != null) {
setStudentNameByPosition(mViewpager.getCurrentItem());
}
}
use of com.instructure.canvasapi.model.Submission in project instructure-android by instructure.
the class DocumentActivity method createEmptySubmissionForGroup.
public Submission createEmptySubmissionForGroup(Group group) {
Submission emptySubmission = createEmptySubmissionForUser(group.getUsers()[0]);
emptySubmission.setGroup(group);
return emptySubmission;
}
use of com.instructure.canvasapi.model.Submission in project instructure-android by instructure.
the class DocumentActivity method groupSubmissionsByGroupId.
public List<Submission> groupSubmissionsByGroupId(Submission[] submissions, User[] courseStudents) {
LongSparseArray<Group> groupMap = new LongSparseArray<>();
LongSparseArray<Group> studentGroupMap = new LongSparseArray<>();
// Map students to groups
for (Group group : mGroups) {
groupMap.put(group.getId(), group);
for (User user : group.getUsers()) {
studentGroupMap.put(user.getId(), group);
}
}
// Get list of unassigned students
LongSparseArray<User> unassignedStudents = new LongSparseArray<>();
for (User student : courseStudents) {
if (studentGroupMap.indexOfKey(student.getId()) < 0) {
unassignedStudents.put(student.getId(), student);
}
}
LongSparseArray<Submission> groupSubmissionMap = new LongSparseArray<>();
for (Group group : mGroups) groupSubmissionMap.put(group.getId(), null);
List<Submission> individualSubmissions = new ArrayList<>();
List<Submission> emptyGroupSubmissions = new ArrayList<>();
List<Submission> emptyIndividualSubmissions = new ArrayList<>();
for (Submission submission : submissions) {
// Group submissions by group ID
long groupId = submission.getGroup().getId();
// Check for and fix missing group info
if (groupId == 0) {
long userId = submission.getUser_id();
if (studentGroupMap.get(userId) != null) {
Group group = studentGroupMap.get(userId);
submission.setGroup(group);
groupId = group.getId();
}
}
if (groupSubmissionMap.get(groupId) == null) {
// check if we need to increment the graded count
if (UserSubmissionsListAdapter.isGraded(submission)) {
gradedCount++;
}
if (groupId != 0) {
groupSubmissionMap.put(groupId, submission);
} else {
// It's possible the submission belongs to a user who doesn't belong to a group
// in that case, we still want to add that submission to our results and display the username
individualSubmissions.add(submission);
unassignedStudents.remove(submission.getUser_id());
}
} else if (!UserSubmissionsListAdapter.isGraded(groupSubmissionMap.get(groupId)) && UserSubmissionsListAdapter.isGraded(submission)) {
groupSubmissionMap.put(groupId, submission);
}
}
List<Submission> result = new ArrayList<>();
// Add group submissions to result, create empty submissions as necessary
for (int i = 0; i < groupSubmissionMap.size(); i++) {
if (groupSubmissionMap.valueAt(i) != null) {
result.add(groupSubmissionMap.valueAt(i));
} else {
Group group = groupMap.get(groupSubmissionMap.keyAt(i));
emptyGroupSubmissions.add(createEmptySubmissionForGroup(group));
}
}
// Create empty submissions for students not assigned to a group
for (int i = 0; i < unassignedStudents.size(); i++) {
emptyIndividualSubmissions.add(createEmptySubmissionForUser(unassignedStudents.valueAt(i)));
}
result.addAll(individualSubmissions);
result.addAll(emptyGroupSubmissions);
result.addAll(emptyIndividualSubmissions);
return result;
}
Aggregations