Search in sources :

Example 1 with Attachment

use of com.instructure.canvasapi.model.Attachment in project instructure-android by instructure.

the class SubmissionUnitTest method testSubmission.

@Test
public void testSubmission() {
    Gson gson = CanvasRestAdapter.getGSONParser();
    Submission submission = gson.fromJson(submissionJson, Submission.class);
    assertNotNull(submission);
    assertTrue(submission.getId() > 0);
    assertNotNull(submission.getBody());
    assertNotNull(submission.getGrade());
    assertTrue(submission.getScore() > 0);
    assertNotNull(submission.getPreviewUrl());
    assertNotNull(submission.getSubmissionType());
    assertNotNull(submission.getUrl());
    assertNotNull(submission.getWorkflowState());
    assertNotNull(submission.getComments());
    SubmissionComment comment = submission.getComments().get(0);
    isCommentValid(comment);
    assertNotNull(submission.getAttachments());
    Attachment attachment = submission.getAttachments().get(0);
    isValidAttachment(attachment);
}
Also used : Submission(com.instructure.canvasapi.model.Submission) Gson(com.google.gson.Gson) Attachment(com.instructure.canvasapi.model.Attachment) SubmissionComment(com.instructure.canvasapi.model.SubmissionComment) Test(org.junit.Test)

Example 2 with Attachment

use of com.instructure.canvasapi.model.Attachment in project instructure-android by instructure.

the class RubricHeaderViewHolder method getFileSelectListener.

private AdapterView.OnItemSelectedListener getFileSelectListener() {
    return new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // firstSelectEventFired is a workaround to stop these premature calls to our interface.
            if (firstSelectAttachmentEventFired) {
                Attachment attachment = ((FilesAdapter) fileSpinner.getAdapter()).getItem(position);
                mSubmissionListener.onAttachmentSelected(attachment, mSubmission);
            } else {
                firstSelectAttachmentEventFired = true;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    };
}
Also used : FilesAdapter(com.instructure.speedgrader.adapters.FilesAdapter) AdapterView(android.widget.AdapterView) Attachment(com.instructure.canvasapi.model.Attachment) HelveticaTextView(com.instructure.speedgrader.views.HelveticaTextView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 3 with Attachment

use of com.instructure.canvasapi.model.Attachment in project instructure-android by instructure.

the class DocumentPagerAdapter method getSubmissionFragment.

/**
 * Function    : getSubmissionFragment
 * Description : This is a static method that takes a submission and an assignment and generates the corresponding document fragment.
 *               Used to generate our Viewpager, and also to swap out a fragment if necessary.
 */
public Fragment getSubmissionFragment(Submission tempSubmission, Assignment assignment, CanvasContext canvasContext, long currentAttempt) {
    // Check the submission type
    final Submission submissionAttempt = getCurrentAttemptSubmission(tempSubmission, currentAttempt);
    final String submissionType = submissionAttempt.getSubmissionType();
    Attachment attachment = getCurrentAttemptAttachment(submissionAttempt);
    tempSubmission.setAssignment(assignment);
    if (isEmptySubmission(submissionAttempt)) {
        // Check for empty submissions
        boolean isGroupAssignment = assignment.getGroupCategoryId() != 0 && !assignment.isGradeGroupsIndividually();
        boolean useGroupMessage = isGroupAssignment && (tempSubmission.getGroup() != null && tempSubmission.getGroup().getId() != 0);
        int messageResId = useGroupMessage ? R.string.noGroupSubmission : R.string.noSubmission;
        return ParentFragment.newInstance(EmptyViewFragment.class, EmptyViewFragment.createBundle(canvasContext, tempSubmission, messageResId));
    } else // online url
    if (submissionAttempt.getSubmissionType() != null && submissionType.equals(onlineURL)) {
        return ParentFragment.newInstance(OnlineURLFragment.class, BaseSubmissionView.createBundle(canvasContext, tempSubmission, currentAttempt));
    } else // discussion topic
    if (submissionAttempt.getSubmissionType() != null && submissionType.equals(discussionTopic)) {
        return ParentFragment.newInstance(DiscussionSubmissionFragment.class, BaseSubmissionView.createBundle(canvasContext, tempSubmission, currentAttempt));
    } else // media upload
    if (submissionAttempt.getSubmissionType() != null && submissionType.equals(mediaUpload)) {
        return ParentFragment.newInstance(MediaUploadFragment.class, BaseSubmissionView.createBundle(canvasContext, submissionAttempt, currentAttempt));
    } else if (submissionType.equals(Assignment.submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.ONLINE_UPLOAD)) && attachment != null && attachment.getMimeType().contains("pdf")) {
        return ParentFragment.newInstance(PdfSubmissionFragment.class, BaseSubmissionView.createBundle(canvasContext, submissionAttempt, currentAttempt));
    } else {
        // online upload & online text
        return ParentFragment.newInstance(SubmissionWebViewFragment.class, BaseSubmissionView.createBundle(canvasContext, tempSubmission, currentAttempt));
    }
}
Also used : Submission(com.instructure.canvasapi.model.Submission) OnlineURLFragment(com.instructure.speedgrader.fragments.OnlineURLFragment) Attachment(com.instructure.canvasapi.model.Attachment) MediaUploadFragment(com.instructure.speedgrader.fragments.MediaUploadFragment)

Example 4 with Attachment

use of com.instructure.canvasapi.model.Attachment in project instructure-android by instructure.

the class SubmissionCommentRowFactory method buildRowView.

// ///////////////////////////////////////////////////////////////
// Row Factories
// ///////////////////////////////////////////////////////////////
public static View buildRowView(View convertView, LayoutInflater inflater, SubmissionComment comment, final Activity context, boolean isUser) {
    final ViewHolder holder;
    if (convertView == null) {
        holder = new ViewHolder();
        if (isUser) {
            convertView = inflater.inflate(R.layout.list_item_user_comment, null);
        } else {
            convertView = inflater.inflate(R.layout.list_item_other_comment, null);
        }
        holder.avatar = (CircleImageView) convertView.findViewById(R.id.avatar);
        holder.comment = (HelveticaTextView) convertView.findViewById(R.id.commentText);
        holder.date = (HelveticaTextView) convertView.findViewById(R.id.date);
        holder.attachmentsHolder = (LinearLayout) convertView.findViewById(R.id.attachmentsHolder);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    String avatarURL = comment.getAuthor().getAvatarImageUrl();
    if (avatarURL != null) {
        Picasso.with(context).load(avatarURL).into(holder.avatar, new Callback() {

            @Override
            public void onSuccess() {
            }

            @Override
            public void onError() {
                holder.avatar.setImageResource(R.drawable.ic_cv_user);
            }
        });
    }
    holder.comment.setText(comment.getComment());
    holder.date.setText(DateHelpers.getShortDate(context, comment.getComparisonDate()) + context.getString(R.string.at) + DateHelpers.getFormattedTime(context, comment.getComparisonDate()) + ", " + comment.getAuthor().getDisplayName());
    holder.attachmentsHolder.removeAllViews();
    List<Attachment> attachments = comment.getAttachments();
    if (attachments != null) {
        for (final Attachment attachment : attachments) {
            if (attachment.getThumbnailUrl() != null && attachment.getUrl() != null) {
                ImageView imageView = getAttachmentImageView(context);
                imageView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        ((SubmissionListener) context).onMediaOpened(attachment.getMimeType(), attachment.getUrl(), attachment.getFilename());
                    }
                });
                Picasso.with(context).load(attachment.getThumbnailUrl()).into(imageView);
                holder.attachmentsHolder.addView(imageView);
            }
        }
    }
    final MediaComment mediaComment = comment.getMedia_comment();
    if (mediaComment != null) {
        final String url = APIHelpers.getFullDomain(context) + "/media_objects/" + mediaComment.getMediaId() + "/thumbnail?height=140&width=140";
        ImageView imageView = getAttachmentImageView(context);
        imageView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                ((SubmissionListener) context).onMediaOpened(mediaComment.getMimeType(), mediaComment.getUrl(), mediaComment.getFileName());
            }
        });
        Picasso.with(context).load(url).into(imageView);
        holder.attachmentsHolder.addView(imageView);
    }
    return convertView;
}
Also used : MediaComment(com.instructure.canvasapi.model.MediaComment) Callback(com.squareup.picasso.Callback) Attachment(com.instructure.canvasapi.model.Attachment) ImageView(android.widget.ImageView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) HelveticaTextView(com.instructure.speedgrader.views.HelveticaTextView) ImageView(android.widget.ImageView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View)

Example 5 with Attachment

use of com.instructure.canvasapi.model.Attachment in project instructure-android by instructure.

the class AttachmentUnitTest method test1.

@Test
public void test1() {
    Gson gson = CanvasRestAdapter.getGSONParser();
    List<Attachment> list = gson.fromJson(JSON, new TypeToken<List<Attachment>>() {
    }.getType());
    assertNotNull(list);
    Attachment attachment = list.get(0);
    assertTrue(attachment.getId() > 0);
    assertNotNull(attachment.getDisplayName());
    assertNotNull(attachment.getFilename());
    assertNotNull(attachment.getUrl());
    assertNotNull(attachment.getThumbnailUrl());
    assertNotNull(attachment.getMimeType());
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) Attachment(com.instructure.canvasapi.model.Attachment) Test(org.junit.Test)

Aggregations

Attachment (com.instructure.canvasapi.model.Attachment)6 View (android.view.View)2 Gson (com.google.gson.Gson)2 Submission (com.instructure.canvasapi.model.Submission)2 HelveticaTextView (com.instructure.speedgrader.views.HelveticaTextView)2 Test (org.junit.Test)2 RecyclerView (android.support.v7.widget.RecyclerView)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 TypeToken (com.google.gson.reflect.TypeToken)1 MediaComment (com.instructure.canvasapi.model.MediaComment)1 Message (com.instructure.canvasapi.model.Message)1 SubmissionComment (com.instructure.canvasapi.model.SubmissionComment)1 FilesAdapter (com.instructure.speedgrader.adapters.FilesAdapter)1 MediaUploadFragment (com.instructure.speedgrader.fragments.MediaUploadFragment)1 OnlineURLFragment (com.instructure.speedgrader.fragments.OnlineURLFragment)1 Callback (com.squareup.picasso.Callback)1 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)1