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