Search in sources :

Example 41 with Message

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);
}
Also used : Response(okhttp3.Response) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) Conversation(com.instructure.canvasapi2.models.Conversation)

Example 42 with Message

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);
    }
}
Also used : MediaComment(com.instructure.canvasapi2.models.MediaComment) Attachment(com.instructure.canvasapi2.models.Attachment)

Example 43 with Message

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);
}
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 44 with Message

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

Example 45 with Message

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);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Aggregations

LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)59 Response (okhttp3.Response)57 RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)28 ArrayList (java.util.ArrayList)27 Request (okhttp3.Request)27 List (java.util.List)22 Conversation (com.instructure.canvasapi2.models.Conversation)12 ParentResponse (com.instructure.canvasapi2.models.ParentResponse)10 RestParams (com.instructure.canvasapi2.builders.RestParams)8 GradingPeriodResponse (com.instructure.canvasapi2.models.GradingPeriodResponse)8 QuizSubmissionQuestionResponse (com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse)8 QuizSubmissionResponse (com.instructure.canvasapi2.models.QuizSubmissionResponse)8 Submission (com.instructure.canvasapi2.models.Submission)7 Course (com.instructure.canvasapi2.models.Course)6 View (android.view.View)5 AdapterView (android.widget.AdapterView)5 TextView (android.widget.TextView)5 Assignment (com.instructure.canvasapi2.models.Assignment)5 CourseNickname (com.instructure.canvasapi2.models.CourseNickname)5 ImageView (android.widget.ImageView)4