use of com.instructure.canvasapi2.models.Message in project instructure-android by instructure.
the class InboxManager_Test method updateConversation.
public static void updateConversation(long conversationId, Conversation.WorkflowState workflowState, Boolean starred, StatusCallback<Conversation> callback) {
// TODO:
Response rawResponse = new Response.Builder().code(200).message("todo").protocol(Protocol.HTTP_1_0).body(ResponseBody.create(MediaType.parse("application/json"), "todo".getBytes())).addHeader("content-type", "application/json").build();
Conversation conversation = new Conversation();
retrofit2.Response<Conversation> response = retrofit2.Response.success(conversation, rawResponse);
callback.onResponse(response, new LinkHeaders(), ApiType.CACHE);
}
use of com.instructure.canvasapi2.models.Message 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.Message 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.Message 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);
}
};
}
use of com.instructure.canvasapi2.models.Message in project instructure-android by instructure.
the class DiscussionManager method replyToDiscussionEntry.
public static void replyToDiscussionEntry(CanvasContext canvasContext, long topicId, long entryId, String message, File attachment, String mimeType, StatusCallback<DiscussionEntry> callback) {
if (isTesting() || mTesting) {
// TODO:
} else {
RestBuilder adapter = new RestBuilder(callback);
RestParams params = new RestParams.Builder().build();
DiscussionAPI.replyToDiscussionEntryWithAttachment(adapter, canvasContext, topicId, entryId, message, attachment, mimeType, callback, params);
}
}
Aggregations