Search in sources :

Example 6 with Submission

use of com.instructure.canvasapi2.models.Submission in project instructure-android by instructure.

the class RubricRecyclerAdapter method addTotalPointsFromRange.

/**
 * We only want to add a score if the rubric uses a range, otherwise they already know their score
 * @param rubricCriterion
 */
private int addTotalPointsFromRange(RubricCriterion rubricCriterion, int insertCount) {
    if (!rubricCriterion.getCriterionUseRange())
        return insertCount;
    Submission lastSubmission = mAssignment.getSubmission();
    if (lastSubmission != null) {
        RubricCriterionAssessment rating = lastSubmission.getRubricAssessment().get(rubricCriterion.getId());
        if (rating != null) {
            RubricCriterionRating rubricCriterionRating = new RubricCriterionRating();
            rubricCriterionRating.setDescription(getContext().getString(R.string.score));
            if (rating.getPoints() != null) {
                rubricCriterionRating.setPoints(rating.getPoints());
            }
            rubricCriterionRating.setId("null" + (rubricCriterion.getId()));
            mInsertedOrderHash.put(rubricCriterion.getId(), ++insertCount);
            addOrUpdateItem(rubricCriterion, new RubricRatingItem(rubricCriterionRating));
        }
    }
    return insertCount;
}
Also used : RubricRatingItem(com.instructure.candroid.model.RubricRatingItem) RubricCriterionRating(com.instructure.canvasapi2.models.RubricCriterionRating) Submission(com.instructure.canvasapi2.models.Submission) RubricCriterionAssessment(com.instructure.canvasapi2.models.RubricCriterionAssessment)

Example 7 with Submission

use of com.instructure.canvasapi2.models.Submission in project instructure-android by instructure.

the class GradeBinder method bind.

public static void bind(final GradeViewHolder holder, final Context context, final int courseColor, final Assignment assignment, final Course course, final boolean isEdit, final WhatIfDialogStyled.WhatIfDialogCallback dialogStyled, final AdapterToFragmentCallback<Assignment> adapterToFragmentCallback, final GradesListRecyclerAdapter.SetSelectedItemCallback selectedItemCallback) {
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            adapterToFragmentCallback.onRowClicked(assignment, holder.getAdapterPosition(), true);
            selectedItemCallback.setSelected(holder.getAdapterPosition());
        }
    });
    holder.title.setText(assignment.getName());
    final int drawable = getAssignmentIcon(assignment);
    holder.icon.setImageDrawable(ColorKeeper.getColoredDrawable(context, drawable, courseColor));
    holder.pendingReviewIcon.setVisibility(View.GONE);
    if (assignment.isMuted()) {
        // mute that score
        holder.points.setVisibility(View.GONE);
    } else {
        Submission submission = assignment.getSubmission();
        if (submission != null && Const.PENDING_REVIEW.equals(submission.getWorkflowState())) {
            holder.points.setVisibility(View.GONE);
            holder.pendingReviewIcon.setVisibility(View.VISIBLE);
            holder.pendingReviewIcon.setColorFilter(courseColor);
        } else {
            holder.points.setVisibility(View.VISIBLE);
            setupGradeText(context, holder.points, assignment, submission, courseColor);
        }
    }
    // configures whatIf editing boxes and listener for dialog
    if (isEdit) {
        holder.edit.setImageDrawable(ColorKeeper.getColoredDrawable(context, R.drawable.vd_edit, Color.BLACK));
        holder.edit.setVisibility(View.VISIBLE);
        holder.edit.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                WhatIfDialogStyled.show((FragmentActivity) context, assignment.getPointsPossible(), dialogStyled, assignment, ColorKeeper.getOrGenerateColor(course), holder.getAdapterPosition());
            }
        });
    } else {
        holder.edit.setVisibility(View.GONE);
    }
    if (assignment.getDueAt() != null) {
        holder.date.setText(DateHelper.getDayMonthDateString(context, assignment.getDueAt()));
    } else {
        holder.date.setText("");
    }
}
Also used : FragmentActivity(android.support.v4.app.FragmentActivity) Submission(com.instructure.canvasapi2.models.Submission) View(android.view.View)

Example 8 with Submission

use of com.instructure.canvasapi2.models.Submission in project instructure-android by instructure.

the class AssignmentDateListRecyclerAdapter method addAndSortAssignments.

private void addAndSortAssignments(List<AssignmentGroup> assignmentGroups) {
    Date today = new Date();
    for (AssignmentGroup assignmentGroup : assignmentGroups) {
        // endtodo
        for (Assignment assignment : assignmentGroup.getAssignments()) {
            Date dueDate = assignment.getDueAt();
            Submission submission = assignment.getSubmission();
            assignment.setSubmission(submission);
            boolean isWithoutGradedSubmission = submission == null || submission.isWithoutGradedSubmission();
            boolean isOverdue = assignment.isAllowedToSubmit() && isWithoutGradedSubmission;
            if (dueDate == null) {
                addOrUpdateItem(mUndated, assignment);
            } else {
                if (today.before(dueDate)) {
                    addOrUpdateItem(mUpcoming, assignment);
                } else if (isOverdue) {
                    addOrUpdateItem(mOverdue, assignment);
                } else {
                    addOrUpdateItem(mPast, assignment);
                }
            }
        }
    }
    setAllPagesLoaded(true);
}
Also used : Assignment(com.instructure.canvasapi2.models.Assignment) Submission(com.instructure.canvasapi2.models.Submission) AssignmentGroup(com.instructure.canvasapi2.models.AssignmentGroup) Date(java.util.Date)

Example 9 with Submission

use of com.instructure.canvasapi2.models.Submission in project instructure-android by instructure.

the class SubmissionDetailsFragment method populateAdapter.

private void populateAdapter(Submission result) {
    // no connection
    if (result == null) {
        hasSubmissions = false;
        showToast(R.string.noDataConnection);
        return;
    }
    hasSubmissions = result.hasRealSubmission();
    if (result.getGrade() != null && !result.getGrade().equals("null")) {
        hasGrade = true;
        grade = result.getGrade();
    }
    // update the parent assignment with the new submission
    if (result.getSubmittedAt() != null) {
        // "xml" should hold the latest submission
        if (submissionDetailsFragmentCallback != null) {
            submissionDetailsFragmentCallback.updateSubmissionDate(result.getSubmittedAt());
        }
    }
    adapter.subList.clear();
    // a submission history is just a submission
    for (Submission submission : result.getSubmissionHistory()) {
        // we don't want to include submissions that aren't actually submitted.  For instance, when a comment
        // is made there is a submission created, even though the submission is basically empty
        // also, we don't want to include an assignment if there is no submission date or type.
        // Canvas creates a dummy submission to show the grade, but if there isn't a type or a date, it's pointless to show it in the list as there is nothing to show.
        boolean hasNoSubmission = submission == null || submission.getSubmittedAt() == null || submission.getSubmissionType() == null;
        if (!hasNoSubmission && !"unsubmitted".equals(submission.getWorkflowState())) {
            adapter.subList.add(submission);
        }
    }
    for (int i = 0; i < result.getSubmissionComments().size(); i++) {
        Submission newSub = new Submission();
        ArrayList<SubmissionComment> comments = new ArrayList<SubmissionComment>();
        comments.add(result.getSubmissionComments().get(i));
        newSub.setSubmittedAt(result.getSubmissionComments().get(i).getCreatedAt());
        newSub.setSubmissionComments(comments);
        adapter.subList.add(newSub);
    }
    // now sort the list so comments and submissions are interleaved
    Collections.sort(adapter.subList, new Comparator<Submission>() {

        @Override
        public int compare(Submission lhs, Submission rhs) {
            if (lhs.getSubmittedAt() == null && rhs.getSubmittedAt() == null)
                return 0;
            if (lhs.getSubmittedAt() == null && rhs.getSubmittedAt() != null)
                return -1;
            if (lhs.getSubmittedAt() != null && rhs.getSubmittedAt() == null)
                return 1;
            return rhs.getSubmittedAt().compareTo(lhs.getSubmittedAt());
        }
    });
    adapter.notifyDataSetChanged();
}
Also used : Submission(com.instructure.canvasapi2.models.Submission) GradeableStudentSubmission(com.instructure.canvasapi2.models.GradeableStudentSubmission) ArrayList(java.util.ArrayList) Paint(android.graphics.Paint) SubmissionComment(com.instructure.canvasapi2.models.SubmissionComment)

Example 10 with Submission

use of com.instructure.canvasapi2.models.Submission in project instructure-android by instructure.

the class SubmissionDetailsFragment method setupListeners.

private void setupListeners() {
    if (addSubmission != null) {
        addSubmission.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO  Open Submission view, "Go To Discussion" or "Go To Quiz"
                if (// Allow the user to go to the discussion.
                assignment.getDiscussionTopicHeader() != null && assignment.getDiscussionTopicHeader().getId() > 0 && assignment.getCourseId() > 0) {
                    String url = DiscussionTopic.getDiscussionURL(ApiPrefs.getProtocol(), ApiPrefs.getDomain(), assignment.getCourseId(), assignment.getDiscussionTopicHeader().getId());
                    if (!RouterUtils.canRouteInternally(getActivity(), url, ApiPrefs.getDomain(), true)) {
                        Intent intent = new Intent(getActivity(), InternalWebViewActivity.class);
                        getActivity().startActivity(intent);
                    }
                } else if (assignment.getQuizId() > 0) {
                    String url = getQuizURL(getActivity(), assignment.getCourseId(), assignment.getQuizId());
                    if (!RouterUtils.canRouteInternally(getActivity(), url, ApiPrefs.getDomain(), true)) {
                        Intent intent = new Intent(getActivity(), InternalWebViewActivity.class);
                        getActivity().startActivity(intent);
                    }
                } else if (assignment.getTurnInType() == Assignment.TURN_IN_TYPE.EXTERNAL_TOOL) {
                    // TODO stream doesn't pass the LTI url. Grab it now if we need it
                    String authenticationURL = assignment.getUrl();
                    if (authenticationURL == null || authenticationURL.equalsIgnoreCase("null")) {
                        // get the assignment
                        AssignmentManager.getAssignment(assignment.getId(), course.getId(), true, canvasCallbackAssignment);
                        return;
                    } else {
                        SubmissionManager.getLtiFromAuthenticationUrl(assignment.getUrl(), canvasCallbackLTITool, true);
                    }
                } else {
                    if (!APIHelper.hasNetworkConnection()) {
                        Toast.makeText(getContext(), getContext().getString(R.string.notAvailableOffline), Toast.LENGTH_SHORT).show();
                        return;
                    }
                    // open add submission view
                    // start it for xml so we can update the results if we need to. Need to call it on the parent fragment
                    // and it will call onActivityResult in the current child fragment.
                    Navigation navigation = getNavigation();
                    if (navigation != null) {
                        Bundle bundle = AddSubmissionFragment.createBundle((Course) getCanvasContext(), assignment, isOnlineTextAllowed, isUrlEntryAllowed, isFileEntryAllowed, isMediaRecording);
                        navigation.addFragment(FragUtils.getFrag(AddSubmissionFragment.class, bundle));
                    }
                }
            }
        });
    }
    // Handle pressing of the send button.
    if (submitComment != null) {
        submitComment.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // try to submit the comment
                if (!APIHelper.hasNetworkConnection()) {
                    Toast.makeText(getContext(), getContext().getString(R.string.notAvailableOffline), Toast.LENGTH_SHORT).show();
                    return;
                }
                sendMessage(assignment.getId());
            }
        });
        mediaComment.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                ListView listView = new ListView(getActivity());
                AttachmentAdapter adapter = new AttachmentAdapter(getActivity(), android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.discussion_attachments));
                listView.setAdapter(adapter);
                listView.setDivider(null);
                listView.setPadding((int) Utils.dpToPx(getActivity(), 10), (int) Utils.dpToPx(getActivity(), 10), (int) Utils.dpToPx(getActivity(), 10), (int) Utils.dpToPx(getActivity(), 16));
                final AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.commentUpload).setView(listView).create();
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        switch(position) {
                            case 0:
                                // Use File Upload Dialog
                                showUploadFileDialog();
                                dialog.dismiss();
                                break;
                            case 1:
                                if (message.getText().toString().trim().length() != 0 || attachmentIds.size() > 0) {
                                    Toast.makeText(getContext(), R.string.unableToUploadMediaComment, Toast.LENGTH_SHORT).show();
                                } else {
                                    // Use Notorious
                                    Intent intent = NotoriousMediaUploadPicker.createIntentForSubmissionComment(getContext(), assignment);
                                    assignmentFragment.get().startActivityForResult(intent, RequestCodes.NOTORIOUS_REQUEST);
                                    dialog.dismiss();
                                }
                                break;
                            default:
                                break;
                        }
                    }
                });
                dialog.show();
            }
        });
    }
    // Handle if they hit the send button in landscape mode.
    message.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
            // Try to send the message.
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                sendMessage(assignment.getId());
                // Hide keyboard
                InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(message.getWindowToken(), 0);
                return true;
            }
            return false;
        }
    });
    if (listView != null) {
        listView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
                Submission submission = (Submission) adapter.getAdapter().getItem(position);
                // it has the details that we need
                if (submission.getSubmissionComments().size() == 0) {
                    if (submission.getSubmissionType().equals("online_upload") || submission.getSubmissionType().equals("media_recording")) {
                        if (submission.getAttachments().size() == 1) {
                            // makes more sense to open the file since they should already have it on their device
                            if (submission.getAttachments().get(0).getContentType().contains("pdf")) {
                                startActivity(StudentSubmissionActivity.createIntent(getActivity(), course, assignment, new GradeableStudentSubmission(new StudentAssignee(ApiPrefs.getUser(), ApiPrefs.getUser().getId(), ApiPrefs.getUser().getName()), null, false)));
                            } else {
                                openMedia(submission.getAttachments().get(0).getContentType(), submission.getAttachments().get(0).getUrl(), submission.getAttachments().get(0).getFilename());
                            }
                        } else if (submission.getMediaComment() != null) {
                            MediaComment mediaComment = submission.getMediaComment();
                            openMedia(mediaComment.getContentType(), mediaComment.getUrl(), mediaComment.get_fileName());
                        } else {
                            // show a list dialog of the files to download.
                            showFileList(submission.getAttachments());
                        }
                    } else if (submission.getSubmissionType().equals("online_text_entry")) {
                        Navigation navigation = getNavigation();
                        if (navigation != null) {
                            Bundle bundle = InternalWebviewFragment.Companion.createBundleHTML(getCanvasContext(), submission.getBody());
                            navigation.addFragment(FragUtils.getFrag(InternalWebviewFragment.class, bundle));
                        }
                    } else if (submission.getSubmissionType().equals("online_url")) {
                        // Take the user to viewing the online url submission. If the image hasn't processed yet they'll see a toast and it
                        // will match what the web does - show the url and say it might be different from when they submitted.
                        Navigation navigation = getNavigation();
                        if (navigation != null) {
                            Bundle bundle = SubmissionViewOnlineURLFragment.createBundle(getCanvasContext(), submission);
                            navigation.addFragment(FragUtils.getFrag(SubmissionViewOnlineURLFragment.class, bundle));
                        }
                        if (submission.getAttachments().size() == 0) {
                            // the server hasn't processed the image for the submitted url yet, show a crouton and reload
                            showToast(R.string.itemStillProcessing);
                            loadData(assignment.getId(), false, false);
                        }
                    }
                }
            }
        });
    }
    addComment.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!APIHelper.hasNetworkConnection()) {
                Toast.makeText(getContext(), getContext().getString(R.string.notAvailableOffline), Toast.LENGTH_SHORT).show();
                return;
            }
            // Only show the header if it hasn't been added prior.
            if (listView.getHeaderViewsCount() == 1) {
                listView.addHeaderView(composeHeaderView, null, false);
            }
            // add the compose header (the comment box)
            composeHeaderView.setVisibility(View.VISIBLE);
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) StudentAssignee(com.instructure.canvasapi2.models.StudentAssignee) InputMethodManager(android.view.inputmethod.InputMethodManager) KeyEvent(android.view.KeyEvent) ListView(android.widget.ListView) TextView(android.widget.TextView) Course(com.instructure.canvasapi2.models.Course) MediaComment(com.instructure.canvasapi2.models.MediaComment) Navigation(com.instructure.interactions.Navigation) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Submission(com.instructure.canvasapi2.models.Submission) GradeableStudentSubmission(com.instructure.canvasapi2.models.GradeableStudentSubmission) Bundle(android.os.Bundle) Intent(android.content.Intent) ImageView(android.widget.ImageView) AttachmentView(com.instructure.candroid.view.AttachmentView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View) AdapterView(android.widget.AdapterView) BeforePageView(com.instructure.canvasapi2.utils.pageview.BeforePageView) PageView(com.instructure.canvasapi2.utils.pageview.PageView) TextView(android.widget.TextView) ListView(android.widget.ListView) Paint(android.graphics.Paint) InternalWebViewActivity(com.instructure.candroid.activity.InternalWebViewActivity) GradeableStudentSubmission(com.instructure.canvasapi2.models.GradeableStudentSubmission) OnClickListener(android.view.View.OnClickListener) AdapterView(android.widget.AdapterView)

Aggregations

Submission (com.instructure.canvasapi2.models.Submission)33 Assignment (com.instructure.canvasapi2.models.Assignment)20 Test (org.junit.Test)17 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)14 RestParams (com.instructure.canvasapi2.builders.RestParams)13 ArrayList (java.util.ArrayList)8 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)7 Date (java.util.Date)7 List (java.util.List)5 Request (okhttp3.Request)4 Response (okhttp3.Response)4 NonNull (android.support.annotation.NonNull)3 View (android.view.View)3 StatusCallback (com.instructure.canvasapi2.StatusCallback)3 GradeableStudentSubmission (com.instructure.canvasapi2.models.GradeableStudentSubmission)3 ApiType (com.instructure.canvasapi2.utils.ApiType)3 Navigation (com.instructure.interactions.Navigation)3 Response (retrofit2.Response)3 Intent (android.content.Intent)2 Paint (android.graphics.Paint)2