Search in sources :

Example 1 with Submission

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

the class SubmissionUnitTest method testSubmission.

@Test
public void testSubmission() {
    Gson gson = CanvasRestAdapter.getGSONParser();
    Submission submission = gson.fromJson(submissionJson, Submission.class);
    assertNotNull(submission);
    assertTrue(submission.getId() > 0);
    assertNotNull(submission.getBody());
    assertNotNull(submission.getGrade());
    assertTrue(submission.getScore() > 0);
    assertNotNull(submission.getPreviewUrl());
    assertNotNull(submission.getSubmissionType());
    assertNotNull(submission.getUrl());
    assertNotNull(submission.getWorkflowState());
    assertNotNull(submission.getComments());
    SubmissionComment comment = submission.getComments().get(0);
    isCommentValid(comment);
    assertNotNull(submission.getAttachments());
    Attachment attachment = submission.getAttachments().get(0);
    isValidAttachment(attachment);
}
Also used : Submission(com.instructure.canvasapi.model.Submission) Gson(com.google.gson.Gson) Attachment(com.instructure.canvasapi.model.Attachment) SubmissionComment(com.instructure.canvasapi.model.SubmissionComment) Test(org.junit.Test)

Example 2 with Submission

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

the class RubricHeaderViewHolder method getVersionSelectListener.

private AdapterView.OnItemSelectedListener getVersionSelectListener() {
    return new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Submission submission = ((SubmissionsAdapter) submissionSpinner.getAdapter()).getItem(position);
            if (mSubmission.getAttempt() != submission.getAttempt()) {
                mSubmission = submission;
                currentAttempt = submission.getAttempt();
                mSubmissionListener.onSubmissionSelected(submission);
                populateAttachments(submission.getAttachments());
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    };
}
Also used : Submission(com.instructure.canvasapi.model.Submission) SubmissionsAdapter(com.instructure.speedgrader.adapters.SubmissionsAdapter) AdapterView(android.widget.AdapterView) HelveticaTextView(com.instructure.speedgrader.views.HelveticaTextView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 3 with Submission

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

the class StudentListView method initListView.

private void initListView(View popupView) {
    // get the listview inside our popupwindow and set our adapter to it
    mListView = (ListView) popupView.findViewById(R.id.studentList);
    mSubmissionsAdapter = new UserSubmissionsListAdapter(mActivity.getApplicationContext(), mSubmissionsList, mAssignment, mListView, ((App) mActivity.getApplication()).showStudentNames(), mListener);
    if (isSortByName) {
        mSubmissionsAdapter.sortSubmissionsByName(((App) mActivity.getApplication()).showUngradedStudentsFirst());
    } else {
        mSubmissionsAdapter.sortSubmissionsByGrade();
    }
    final ViewGroup header = (ViewGroup) LayoutInflater.from(mActivity).inflate(R.layout.student_list_headerview, mListView, false);
    final RelativeLayout row = (RelativeLayout) header.findViewById(R.id.row);
    final LinearLayout dropDown = (LinearLayout) header.findViewById(R.id.rowDropdown);
    final RadioGroup radioGroup = (RadioGroup) header.findViewById(R.id.radioGroup);
    final ImageView expandArrow = (ImageView) header.findViewById(R.id.expandArrow);
    final TextView sectionTitle = (TextView) header.findViewById(R.id.sectionTitle);
    row.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ExpandCollapseAnimation.setHeightForWrapContent(mActivity, dropDown);
            ExpandCollapseAnimation expandCollapseAnimation = new ExpandCollapseAnimation(dropDown, 200);
            expandCollapseAnimation.setAnimationListener(new Animation.AnimationListener() {

                @Override
                public void onAnimationStart(Animation animation) {
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    RotateAnimation rotationAnim;
                    if (dropDown.getHeight() < 50) {
                        // For some reason, onAnimatinoEnd is getting called slightly before the animation actually ends, causing the height to be a value something greater than 0.
                        // currently closed
                        rotationAnim = new RotateAnimation(180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                    } else {
                        // currently open
                        rotationAnim = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                    }
                    rotationAnim.setDuration(100);
                    rotationAnim.setFillAfter(true);
                    expandArrow.startAnimation(rotationAnim);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }
            });
            dropDown.startAnimation(expandCollapseAnimation);
        }
    });
    // Set our arrow to gray
    final Drawable d = CanvasContextColor.getColoredDrawable(mApplicationContext, R.drawable.ic_cv_arrow_down_fill, ContextCompat.getColor(mActivity.getApplicationContext(), R.color.lightGray));
    expandArrow.setImageDrawable(d);
    mListView.addHeaderView(header);
    mListView.setTextFilterEnabled(true);
    mListView.setAdapter(mSubmissionsAdapter);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // show the submission clicked
            dismiss();
            int positionInList = mSubmissionsAdapter.getPositionForSubmission((Submission) mListView.getItemAtPosition(position));
            mListener.onCurrentSubmission(positionInList);
        }
    });
    initSectionsRadioGroup(radioGroup, sectionTitle, header);
}
Also used : App(com.instructure.speedgrader.util.App) RadioGroup(android.widget.RadioGroup) Submission(com.instructure.canvasapi.model.Submission) UserSubmissionsListAdapter(com.instructure.speedgrader.adapters.UserSubmissionsListAdapter) ViewGroup(android.view.ViewGroup) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) SearchView(android.support.v7.widget.SearchView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) RotateAnimation(android.view.animation.RotateAnimation) RelativeLayout(android.widget.RelativeLayout) ExpandCollapseAnimation(com.instructure.speedgrader.util.ExpandCollapseAnimation) ExpandCollapseAnimation(com.instructure.speedgrader.util.ExpandCollapseAnimation) Animation(android.view.animation.Animation) RotateAnimation(android.view.animation.RotateAnimation) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Example 4 with Submission

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

the class DocumentPagerAdapter method getSubmissionFragment.

/**
 * Function    : getSubmissionFragment
 * Description : This is a static method that takes a submission and an assignment and generates the corresponding document fragment.
 *               Used to generate our Viewpager, and also to swap out a fragment if necessary.
 */
public Fragment getSubmissionFragment(Submission tempSubmission, Assignment assignment, CanvasContext canvasContext, long currentAttempt) {
    // Check the submission type
    final Submission submissionAttempt = getCurrentAttemptSubmission(tempSubmission, currentAttempt);
    final String submissionType = submissionAttempt.getSubmissionType();
    Attachment attachment = getCurrentAttemptAttachment(submissionAttempt);
    tempSubmission.setAssignment(assignment);
    if (isEmptySubmission(submissionAttempt)) {
        // Check for empty submissions
        boolean isGroupAssignment = assignment.getGroupCategoryId() != 0 && !assignment.isGradeGroupsIndividually();
        boolean useGroupMessage = isGroupAssignment && (tempSubmission.getGroup() != null && tempSubmission.getGroup().getId() != 0);
        int messageResId = useGroupMessage ? R.string.noGroupSubmission : R.string.noSubmission;
        return ParentFragment.newInstance(EmptyViewFragment.class, EmptyViewFragment.createBundle(canvasContext, tempSubmission, messageResId));
    } else // online url
    if (submissionAttempt.getSubmissionType() != null && submissionType.equals(onlineURL)) {
        return ParentFragment.newInstance(OnlineURLFragment.class, BaseSubmissionView.createBundle(canvasContext, tempSubmission, currentAttempt));
    } else // discussion topic
    if (submissionAttempt.getSubmissionType() != null && submissionType.equals(discussionTopic)) {
        return ParentFragment.newInstance(DiscussionSubmissionFragment.class, BaseSubmissionView.createBundle(canvasContext, tempSubmission, currentAttempt));
    } else // media upload
    if (submissionAttempt.getSubmissionType() != null && submissionType.equals(mediaUpload)) {
        return ParentFragment.newInstance(MediaUploadFragment.class, BaseSubmissionView.createBundle(canvasContext, submissionAttempt, currentAttempt));
    } else if (submissionType.equals(Assignment.submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.ONLINE_UPLOAD)) && attachment != null && attachment.getMimeType().contains("pdf")) {
        return ParentFragment.newInstance(PdfSubmissionFragment.class, BaseSubmissionView.createBundle(canvasContext, submissionAttempt, currentAttempt));
    } else {
        // online upload & online text
        return ParentFragment.newInstance(SubmissionWebViewFragment.class, BaseSubmissionView.createBundle(canvasContext, tempSubmission, currentAttempt));
    }
}
Also used : Submission(com.instructure.canvasapi.model.Submission) OnlineURLFragment(com.instructure.speedgrader.fragments.OnlineURLFragment) Attachment(com.instructure.canvasapi.model.Attachment) MediaUploadFragment(com.instructure.speedgrader.fragments.MediaUploadFragment)

Example 5 with Submission

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

the class UserSubmissionsListAdapter method getCustomView.

public View getCustomView(int position, View convertView, ViewGroup parent, boolean isDropDown) {
    ViewHolder viewHolder;
    if (convertView == null) {
        viewHolder = new ViewHolder();
        convertView = li.inflate(R.layout.list_item_student_grades, parent, false);
        viewHolder.rootView = convertView.findViewById(R.id.rootView);
        viewHolder.sectionTitle = (HelveticaTextView) convertView.findViewById(R.id.gradeTitle);
        viewHolder.checkmark = (ImageView) convertView.findViewById(R.id.checkmark);
        viewHolder.score = (HelveticaTextView) convertView.findViewById(R.id.score);
        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }
    // set user name
    if (showStudentNames) {
        viewHolder.sectionTitle.setText(DocumentActivity.getDisplayNameBySubmission(submissions.get(position), isGroupAssignment, isGradeIndividually));
    } else {
        viewHolder.sectionTitle.setText(context.getString(R.string.student) + " " + String.valueOf(position + 1));
    }
    if (DocumentPagerAdapter.isEmptySubmission(submissions.get(position))) {
        viewHolder.sectionTitle.setTextColor(context.getResources().getColor(R.color.lightGray));
    } else {
        viewHolder.sectionTitle.setTextColor(context.getResources().getColor(R.color.sg_darkText));
    }
    // get the submission
    Submission userSubmission = submissions.get(position);
    // display grade and isGraded checkmark
    // format the score to remove trailing zeros
    DecimalFormat format = new DecimalFormat("0.#");
    if (userSubmission.getGraderID() != 0 || userSubmission.getGrade() != null) {
        if (isGraded(userSubmission)) {
            // set the checkmark if the submission has been graded. It's possible that the user has a grade for the submission,
            // has resbumitted the assignment after receiving a grade. In this case, we want to regrade the submission, but still show the last grade.
            Drawable checkmark = CanvasContextColor.getColoredDrawable(context, R.drawable.ic_cv_checkmark_fill, context.getResources().getColor(R.color.sg_checkmark_green));
            viewHolder.checkmark.setImageDrawable(checkmark);
            viewHolder.checkmark.setVisibility(View.VISIBLE);
        } else {
            viewHolder.checkmark.setVisibility(View.INVISIBLE);
            viewHolder.score.setText(context.getString(R.string.slash) + format.format(assignment.getPointsPossible()));
        }
        String grade = format.format(userSubmission.getScore()) + "/" + format.format(assignment.getPointsPossible());
        viewHolder.score.setText(grade);
    } else {
        viewHolder.checkmark.setVisibility(View.INVISIBLE);
        viewHolder.score.setText(context.getString(R.string.slash) + format.format(assignment.getPointsPossible()));
    }
    return convertView;
}
Also used : Submission(com.instructure.canvasapi.model.Submission) DecimalFormat(java.text.DecimalFormat) Drawable(android.graphics.drawable.Drawable)

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