use of com.instructure.canvasapi.model.Submission 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.Submission in project instructure-android by instructure.
the class RubricHeaderViewHolder method getVersionSelectListener.
private AdapterView.OnItemSelectedListener getVersionSelectListener() {
return new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Submission submission = ((SubmissionsAdapter) submissionSpinner.getAdapter()).getItem(position);
if (mSubmission.getAttempt() != submission.getAttempt()) {
mSubmission = submission;
currentAttempt = submission.getAttempt();
mSubmissionListener.onSubmissionSelected(submission);
populateAttachments(submission.getAttachments());
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
};
}
use of com.instructure.canvasapi.model.Submission in project instructure-android by instructure.
the class StudentListView method initListView.
private void initListView(View popupView) {
// get the listview inside our popupwindow and set our adapter to it
mListView = (ListView) popupView.findViewById(R.id.studentList);
mSubmissionsAdapter = new UserSubmissionsListAdapter(mActivity.getApplicationContext(), mSubmissionsList, mAssignment, mListView, ((App) mActivity.getApplication()).showStudentNames(), mListener);
if (isSortByName) {
mSubmissionsAdapter.sortSubmissionsByName(((App) mActivity.getApplication()).showUngradedStudentsFirst());
} else {
mSubmissionsAdapter.sortSubmissionsByGrade();
}
final ViewGroup header = (ViewGroup) LayoutInflater.from(mActivity).inflate(R.layout.student_list_headerview, mListView, false);
final RelativeLayout row = (RelativeLayout) header.findViewById(R.id.row);
final LinearLayout dropDown = (LinearLayout) header.findViewById(R.id.rowDropdown);
final RadioGroup radioGroup = (RadioGroup) header.findViewById(R.id.radioGroup);
final ImageView expandArrow = (ImageView) header.findViewById(R.id.expandArrow);
final TextView sectionTitle = (TextView) header.findViewById(R.id.sectionTitle);
row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ExpandCollapseAnimation.setHeightForWrapContent(mActivity, dropDown);
ExpandCollapseAnimation expandCollapseAnimation = new ExpandCollapseAnimation(dropDown, 200);
expandCollapseAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
RotateAnimation rotationAnim;
if (dropDown.getHeight() < 50) {
// For some reason, onAnimatinoEnd is getting called slightly before the animation actually ends, causing the height to be a value something greater than 0.
// currently closed
rotationAnim = new RotateAnimation(180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
} else {
// currently open
rotationAnim = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
}
rotationAnim.setDuration(100);
rotationAnim.setFillAfter(true);
expandArrow.startAnimation(rotationAnim);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
dropDown.startAnimation(expandCollapseAnimation);
}
});
// Set our arrow to gray
final Drawable d = CanvasContextColor.getColoredDrawable(mApplicationContext, R.drawable.ic_cv_arrow_down_fill, ContextCompat.getColor(mActivity.getApplicationContext(), R.color.lightGray));
expandArrow.setImageDrawable(d);
mListView.addHeaderView(header);
mListView.setTextFilterEnabled(true);
mListView.setAdapter(mSubmissionsAdapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// show the submission clicked
dismiss();
int positionInList = mSubmissionsAdapter.getPositionForSubmission((Submission) mListView.getItemAtPosition(position));
mListener.onCurrentSubmission(positionInList);
}
});
initSectionsRadioGroup(radioGroup, sectionTitle, header);
}
use of com.instructure.canvasapi.model.Submission 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.Submission in project instructure-android by instructure.
the class UserSubmissionsListAdapter method getCustomView.
public View getCustomView(int position, View convertView, ViewGroup parent, boolean isDropDown) {
ViewHolder viewHolder;
if (convertView == null) {
viewHolder = new ViewHolder();
convertView = li.inflate(R.layout.list_item_student_grades, parent, false);
viewHolder.rootView = convertView.findViewById(R.id.rootView);
viewHolder.sectionTitle = (HelveticaTextView) convertView.findViewById(R.id.gradeTitle);
viewHolder.checkmark = (ImageView) convertView.findViewById(R.id.checkmark);
viewHolder.score = (HelveticaTextView) convertView.findViewById(R.id.score);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
// set user name
if (showStudentNames) {
viewHolder.sectionTitle.setText(DocumentActivity.getDisplayNameBySubmission(submissions.get(position), isGroupAssignment, isGradeIndividually));
} else {
viewHolder.sectionTitle.setText(context.getString(R.string.student) + " " + String.valueOf(position + 1));
}
if (DocumentPagerAdapter.isEmptySubmission(submissions.get(position))) {
viewHolder.sectionTitle.setTextColor(context.getResources().getColor(R.color.lightGray));
} else {
viewHolder.sectionTitle.setTextColor(context.getResources().getColor(R.color.sg_darkText));
}
// get the submission
Submission userSubmission = submissions.get(position);
// display grade and isGraded checkmark
// format the score to remove trailing zeros
DecimalFormat format = new DecimalFormat("0.#");
if (userSubmission.getGraderID() != 0 || userSubmission.getGrade() != null) {
if (isGraded(userSubmission)) {
// set the checkmark if the submission has been graded. It's possible that the user has a grade for the submission,
// has resbumitted the assignment after receiving a grade. In this case, we want to regrade the submission, but still show the last grade.
Drawable checkmark = CanvasContextColor.getColoredDrawable(context, R.drawable.ic_cv_checkmark_fill, context.getResources().getColor(R.color.sg_checkmark_green));
viewHolder.checkmark.setImageDrawable(checkmark);
viewHolder.checkmark.setVisibility(View.VISIBLE);
} else {
viewHolder.checkmark.setVisibility(View.INVISIBLE);
viewHolder.score.setText(context.getString(R.string.slash) + format.format(assignment.getPointsPossible()));
}
String grade = format.format(userSubmission.getScore()) + "/" + format.format(assignment.getPointsPossible());
viewHolder.score.setText(grade);
} else {
viewHolder.checkmark.setVisibility(View.INVISIBLE);
viewHolder.score.setText(context.getString(R.string.slash) + format.format(assignment.getPointsPossible()));
}
return convertView;
}
Aggregations