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();
}
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);
}
}
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);
}
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);
}
};
}
Aggregations