Search in sources :

Example 1 with SubmissionComment

use of com.instructure.canvasapi2.models.SubmissionComment 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 2 with SubmissionComment

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

the class SubmissionDetailsFragment method getMessageExtras.

private void getMessageExtras(final LinearLayout extras, SubmissionComment message) {
    // Assume there are no media comments or attachments.
    extras.removeAllViews();
    // If there is a media comment, add it.
    final MediaComment mc = message.getMediaComment();
    if (mc != null) {
        populateMediaComments(extras, message, mc);
    }
    // If there are attachments, add them.
    final List<Attachment> atts = message.getAttachments();
    if (atts != null) {
        populateAttachments(extras, atts);
    }
    if (extras.getChildCount() > 0) {
        populateExtras(extras);
    }
}
Also used : MediaComment(com.instructure.canvasapi2.models.MediaComment) Attachment(com.instructure.canvasapi2.models.Attachment)

Example 3 with SubmissionComment

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

the class SubmissionDetailsFragment method populateMediaComments.

/**
 * @param extras
 * @param message
 * @param mediaComment
 */
private void populateMediaComments(final LinearLayout extras, SubmissionComment message, final MediaComment mediaComment) {
    // Inflate the view.
    RelativeLayout extra = (RelativeLayout) (inflater.inflate(R.layout.detailed_conversation_extras, null));
    // the text should be the display name
    TextView content = extra.findViewById(R.id.content);
    String displayName = mediaComment.getDisplayName();
    if (displayName == null || "null".equals(displayName)) {
        displayName = mediaComment.get_fileName();
    }
    content.setText(displayName);
    // Underline the text view.
    content.setPaintFlags(content.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    // Make it blue
    content.setTextColor(getResources().getColor(R.color.real_blue));
    // Set the image to be the media_comment icon
    ImageView image = extra.findViewById(R.id.image);
    if (mediaComment.getMediaType() == MediaComment.MediaType.VIDEO) {
        image.setImageDrawable(ColorKeeper.getColoredDrawable(getContext(), R.drawable.vd_media, getResources().getColor(R.color.defaultTextGray)));
    } else {
        image.setImageDrawable(ColorKeeper.getColoredDrawable(getContext(), R.drawable.vd_audio, getResources().getColor(R.color.defaultTextGray)));
    }
    // Add a divider
    View divider = new View(getActivity());
    divider.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));
    divider.setBackgroundColor(getResources().getColor(R.color.gray));
    // Set hidden mimetype url display name. filename. id
    extra.findViewById(R.id.mime).setTag(mediaComment.getContentType());
    extra.findViewById(R.id.url).setTag(mediaComment.getUrl());
    extra.findViewById(R.id.file).setTag(mediaComment.getMediaId() + "." + FileUtils.getFileExtensionFromMimetype(mediaComment.getContentType()));
    extra.findViewById(R.id.display).setTag(displayName);
    // allow long presses to show context menu
    registerForContextMenu(extra);
    extra.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            openMedia(mediaComment.getContentType(), mediaComment.getUrl(), mediaComment.getMediaId() + "." + FileUtils.getFileExtensionFromMimetype(mediaComment.getContentType()));
        }
    });
    // Add the view
    divider.setVisibility(View.GONE);
    extra.setVisibility(View.GONE);
    extras.addView(divider);
    extras.addView(extra);
}
Also used : ViewGroup(android.view.ViewGroup) RelativeLayout(android.widget.RelativeLayout) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) ImageView(android.widget.ImageView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) 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)

Example 4 with SubmissionComment

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

the class SubmissionDetailsFragment method setupCallbacks.

// /////////////////////////////////////////////////////////////////////////
// CallBack
// /////////////////////////////////////////////////////////////////////////
public void setupCallbacks() {
    notoriousConfigCallback = new StatusCallback<NotoriousConfig>() {

        @Override
        public void onResponse(@NonNull Response<NotoriousConfig> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            NotoriousConfig notoriousConfig = response.body();
            if (notoriousConfig.isEnabled()) {
                mediaComment.setEnabled(true);
            }
        }
    };
    // We use a NoNetworkErrorDelegate because sometimes old submissions are deleted.
    // We don't want to display unnecessary croutons.
    canvasCallbackSubmission = new StatusCallback<Submission>() {

        @Override
        public void onResponse(@NonNull Response<Submission> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            if (response.body() != null) {
                populateAdapter(response.body());
            }
        }
    };
    canvasCallbackMessage = new StatusCallback<Submission>() {

        @Override
        public void onResponse(@NonNull Response<Submission> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            // See if it was successful.
            Submission submission = response.body();
            if (submission != null) {
                SubmissionComment comment = submission.getSubmissionComments().get(submission.getSubmissionComments().size() - 1);
                // Our list is a list of Submission, so add the comment to a SubmissionGrade object
                Submission newSub = new Submission();
                ArrayList<SubmissionComment> comments = new ArrayList<>();
                comments.add(comment);
                newSub.setSubmittedAt(comment.getCreatedAt());
                newSub.setSubmissionComments(comments);
                adapter.subList.add(0, newSub);
                message.setText("");
            } else {
                showToast(R.string.errorPostingComment);
            }
            adapter.notifyDataSetChanged();
            // Close the keyboard
            InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(message.getWindowToken(), 0);
            // Enable the send message button again
            submitComment.setVisibility(View.VISIBLE);
            sendingProgressBar.setVisibility(View.GONE);
            // Clear the attachments list
            attachmentsList.clear();
            attachmentIds.clear();
            attachments.clear();
            refreshAttachments();
        }

        @Override
        public void onFail(@Nullable Call<Submission> call, @NonNull Throwable error, @Nullable Response response) {
            // Enable the send message button again if there was an Error
            submitComment.setVisibility(View.VISIBLE);
            sendingProgressBar.setVisibility(View.GONE);
            // Clear the attachments list
            attachmentsList.clear();
            attachmentIds.clear();
            attachments.clear();
            refreshAttachments();
        }
    };
    canvasCallbackLTITool = new StatusCallback<LTITool>() {

        @Override
        public void onResponse(@NonNull Response<LTITool> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            LTITool ltiTool = response.body();
            String url = ltiTool.getUrl();
            // Append platform for quizzes 2 lti tool
            Uri uri = Uri.parse(url).buildUpon().appendQueryParameter("platform", "android").build();
            // Do NOT authenticate or the LTI tool won't load.
            InternalWebviewFragment.Companion.loadInternalWebView(getActivity(), ((Navigation) getActivity()), InternalWebviewFragment.Companion.createBundle(getCanvasContext(), uri.toString(), ltiTool.getName(), false, false, true, assignment.getUrl()));
        }

        @Override
        public void onFail(@Nullable Call<LTITool> call, @NonNull Throwable error, @Nullable Response response) {
            // If it wasn't a network Error, then the LTI tool must be expired or invalid.
            if (APIHelper.hasNetworkConnection() && (response == null || (response != null && response.code() != 504))) {
                showToast(R.string.invalidExternal);
            }
        }
    };
    canvasCallbackAssignment = new StatusCallback<Assignment>() {

        @Override
        public void onResponse(@NonNull Response<Assignment> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
            if (!apiCheck()) {
                return;
            }
            Assignment newAssignment = response.body();
            String authenticationURL;
            if (newAssignment == null) {
                authenticationURL = null;
            } else {
                authenticationURL = newAssignment.getUrl();
            }
            // Now get the LTITool
            // This API call handles url being null
            SubmissionManager.getLtiFromAuthenticationUrl(authenticationURL, canvasCallbackLTITool, true);
        }
    };
}
Also used : ArrayList(java.util.ArrayList) InputMethodManager(android.view.inputmethod.InputMethodManager) Uri(android.net.Uri) SubmissionComment(com.instructure.canvasapi2.models.SubmissionComment) Assignment(com.instructure.canvasapi2.models.Assignment) ApiType(com.instructure.canvasapi2.utils.ApiType) Submission(com.instructure.canvasapi2.models.Submission) GradeableStudentSubmission(com.instructure.canvasapi2.models.GradeableStudentSubmission) LTITool(com.instructure.canvasapi2.models.LTITool) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) Response(retrofit2.Response) NotoriousConfig(com.instructure.canvasapi2.models.NotoriousConfig)

Aggregations

GradeableStudentSubmission (com.instructure.canvasapi2.models.GradeableStudentSubmission)2 Submission (com.instructure.canvasapi2.models.Submission)2 SubmissionComment (com.instructure.canvasapi2.models.SubmissionComment)2 ArrayList (java.util.ArrayList)2 Paint (android.graphics.Paint)1 Uri (android.net.Uri)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ViewGroup (android.view.ViewGroup)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 RelativeLayout (android.widget.RelativeLayout)1 TextView (android.widget.TextView)1 AttachmentView (com.instructure.candroid.view.AttachmentView)1 Assignment (com.instructure.canvasapi2.models.Assignment)1 Attachment (com.instructure.canvasapi2.models.Attachment)1 LTITool (com.instructure.canvasapi2.models.LTITool)1 MediaComment (com.instructure.canvasapi2.models.MediaComment)1