use of com.instructure.candroid.model.RubricRatingItem in project instructure-android by instructure.
the class RubricRecyclerAdapter method addTotalPointsFromRange.
/**
* We only want to add a score if the rubric uses a range, otherwise they already know their score
* @param rubricCriterion
*/
private int addTotalPointsFromRange(RubricCriterion rubricCriterion, int insertCount) {
if (!rubricCriterion.getCriterionUseRange())
return insertCount;
Submission lastSubmission = mAssignment.getSubmission();
if (lastSubmission != null) {
RubricCriterionAssessment rating = lastSubmission.getRubricAssessment().get(rubricCriterion.getId());
if (rating != null) {
RubricCriterionRating rubricCriterionRating = new RubricCriterionRating();
rubricCriterionRating.setDescription(getContext().getString(R.string.score));
if (rating.getPoints() != null) {
rubricCriterionRating.setPoints(rating.getPoints());
}
rubricCriterionRating.setId("null" + (rubricCriterion.getId()));
mInsertedOrderHash.put(rubricCriterion.getId(), ++insertCount);
addOrUpdateItem(rubricCriterion, new RubricRatingItem(rubricCriterionRating));
}
}
return insertCount;
}
use of com.instructure.candroid.model.RubricRatingItem in project instructure-android by instructure.
the class RubricRecyclerAdapterTest method testAreContentsTheSame_SameNotComment.
@Test
public void testAreContentsTheSame_SameNotComment() {
RubricCriterionRating rating = new RubricCriterionRating();
rating.setDescription("item");
RubricRatingItem item = new RubricRatingItem(rating);
assertTrue(mAdapter.createItemCallback().areContentsTheSame(item, item));
}
use of com.instructure.candroid.model.RubricRatingItem in project instructure-android by instructure.
the class RubricRecyclerAdapterTest method testAreContentsTheSame_DifferentNotComment.
@Test
public void testAreContentsTheSame_DifferentNotComment() {
RubricCriterionRating rating = new RubricCriterionRating();
rating.setDescription("item");
RubricRatingItem item = new RubricRatingItem(rating);
RubricCriterionRating rating1 = new RubricCriterionRating();
rating1.setDescription("item1");
RubricRatingItem item1 = new RubricRatingItem(rating1);
assertFalse(mAdapter.createItemCallback().areContentsTheSame(item, item1));
}
use of com.instructure.candroid.model.RubricRatingItem in project instructure-android by instructure.
the class RubricRecyclerAdapter method createItemCallback.
@Override
public GroupSortedList.ItemComparatorCallback<RubricCriterion, RubricItem> createItemCallback() {
return new GroupSortedList.ItemComparatorCallback<RubricCriterion, RubricItem>() {
@Override
public int compare(RubricCriterion group, RubricItem o1, RubricItem o2) {
// put comments at the bottom
if (o1 instanceof RubricCommentItem && o2 instanceof RubricCommentItem) {
return 0;
} else if (o1 instanceof RubricCommentItem) {
return 1;
} else if (o2 instanceof RubricCommentItem) {
return -1;
}
RubricCriterionRating r1 = ((RubricRatingItem) o1).getRating();
RubricCriterionRating r2 = ((RubricRatingItem) o2).getRating();
if (r2.getId() != null && r2.getId().contains("null")) {
return -1;
} else if (r1.getId() != null && r1.getId().contains("null")) {
return -1;
}
return Double.compare(r2.getPoints(), r1.getPoints());
}
@Override
public boolean areContentsTheSame(RubricItem oldItem, RubricItem newItem) {
if (newItem instanceof RubricCommentItem || oldItem instanceof RubricCommentItem) {
// if its a comment always refresh the layout
return false;
} else {
RubricCriterionRating oldRating = ((RubricRatingItem) oldItem).getRating();
RubricCriterionRating newRating = ((RubricRatingItem) newItem).getRating();
return !(oldRating.getDescription() == null || newRating.getDescription() == null) && oldRating.getDescription().equals(newRating.getDescription()) && oldRating.getPoints() == newRating.getPoints();
}
}
@Override
public boolean areItemsTheSame(RubricItem item1, RubricItem item2) {
if (item1 instanceof RubricCommentItem ^ item2 instanceof RubricCommentItem) {
return false;
} else if ((item1 instanceof RubricCommentItem && ((RubricCommentItem) item1).getComment() == null) && (((RubricCommentItem) item2).getComment() == null)) {
return true;
} else if (item1 instanceof RubricCommentItem) {
return (((RubricCommentItem) item1).getComment() != null && ((RubricCommentItem) item2).getComment() != null) && ((RubricCommentItem) item1).getComment().equals(((RubricCommentItem) item2).getComment());
} else {
return (((RubricRatingItem) item1).getRating().getId() != null && ((RubricRatingItem) item2).getRating().getId() != null) && ((RubricRatingItem) item1).getRating().getId().equals(((RubricRatingItem) item2).getRating().getId());
}
}
@Override
public long getUniqueItemId(RubricItem item) {
if (item instanceof RubricCommentItem) {
if (!TextUtils.isEmpty(((RubricCommentItem) item).getComment())) {
return (((RubricCommentItem) item).getComment() + UUID.randomUUID().toString().hashCode()).hashCode();
} else {
return UUID.randomUUID().toString().hashCode();
}
} else {
if (!TextUtils.isEmpty(((RubricRatingItem) item).getRating().getId())) {
return (((RubricRatingItem) item).getRating().getId() + ((RubricRatingItem) item).getRating().getDescription()).hashCode();
} else {
return UUID.randomUUID().toString().hashCode();
}
}
}
@Override
public int getChildType(RubricCriterion group, RubricItem item) {
return (item instanceof RubricCommentItem) ? RubricViewHolder.TYPE_ITEM_COMMENT : RubricViewHolder.TYPE_ITEM_POINTS;
}
};
}
use of com.instructure.candroid.model.RubricRatingItem in project instructure-android by instructure.
the class RubricRecyclerAdapter method populateRatingItems.
// endregion
// region Grade Helpers
private void populateRatingItems(List<RubricCriterion> rubric) {
int insertCount = 0;
for (RubricCriterion rubricCriterion : rubric) {
final List<RubricCriterionRating> rubricCriterionRatings = rubricCriterion.getRatings();
for (RubricCriterionRating rating : rubricCriterionRatings) {
mInsertedOrderHash.put(rubricCriterion.getId(), ++insertCount);
addOrUpdateItem(rubricCriterion, new RubricRatingItem(rating));
}
populateFreeFormRatingItems(rubric);
insertCount = addTotalPointsFromRange(rubricCriterion, insertCount);
}
}
Aggregations