Search in sources :

Example 6 with Submission

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;
}
Also used : Submission(com.instructure.canvasapi.model.Submission)

Example 7 with Submission

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;
}
Also used : User(com.instructure.canvasapi.model.User) Submission(com.instructure.canvasapi.model.Submission) ArrayList(java.util.ArrayList)

Example 8 with Submission

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());
    }
}
Also used : Submission(com.instructure.canvasapi.model.Submission)

Example 9 with Submission

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;
}
Also used : Submission(com.instructure.canvasapi.model.Submission)

Example 10 with Submission

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;
}
Also used : Group(com.instructure.canvasapi.model.Group) LongSparseArray(android.support.v4.util.LongSparseArray) User(com.instructure.canvasapi.model.User) Submission(com.instructure.canvasapi.model.Submission) ArrayList(java.util.ArrayList)

Aggregations

Submission (com.instructure.canvasapi.model.Submission)11 Drawable (android.graphics.drawable.Drawable)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 TextView (android.widget.TextView)2 Attachment (com.instructure.canvasapi.model.Attachment)2 User (com.instructure.canvasapi.model.User)2 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 LongSparseArray (android.support.v4.util.LongSparseArray)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SearchView (android.support.v7.widget.SearchView)1 ViewGroup (android.view.ViewGroup)1 Animation (android.view.animation.Animation)1 RotateAnimation (android.view.animation.RotateAnimation)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1 RadioGroup (android.widget.RadioGroup)1