Search in sources :

Example 1 with MediaComment

use of com.instructure.canvasapi2.models.MediaComment 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)

Example 2 with MediaComment

use of com.instructure.canvasapi2.models.MediaComment 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 MediaComment

use of com.instructure.canvasapi2.models.MediaComment 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)

Aggregations

View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 AdapterView (android.widget.AdapterView)2 ImageView (android.widget.ImageView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 AttachmentView (com.instructure.candroid.view.AttachmentView)2 MediaComment (com.instructure.canvasapi2.models.MediaComment)2 BeforePageView (com.instructure.canvasapi2.utils.pageview.BeforePageView)2 PageView (com.instructure.canvasapi2.utils.pageview.PageView)2 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)2 Intent (android.content.Intent)1 Paint (android.graphics.Paint)1 Bundle (android.os.Bundle)1 AlertDialog (android.support.v7.app.AlertDialog)1 KeyEvent (android.view.KeyEvent)1 ViewGroup (android.view.ViewGroup)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)1 RelativeLayout (android.widget.RelativeLayout)1