Search in sources :

Example 1 with RubricCommentItem

use of com.instructure.candroid.model.RubricCommentItem in project instructure-android by instructure.

the class RubricRecyclerAdapterTest method testAreContentsTheSame_SameComment.

@Test
public void testAreContentsTheSame_SameComment() {
    RubricCommentItem item = new RubricCommentItem("hodor", 0d);
    assertFalse(mAdapter.createItemCallback().areContentsTheSame(item, item));
}
Also used : RubricCommentItem(com.instructure.candroid.model.RubricCommentItem) Test(org.junit.Test)

Example 2 with RubricCommentItem

use of com.instructure.candroid.model.RubricCommentItem 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;
        }
    };
}
Also used : RubricRatingItem(com.instructure.candroid.model.RubricRatingItem) RubricCriterionRating(com.instructure.canvasapi2.models.RubricCriterionRating) RubricCriterion(com.instructure.canvasapi2.models.RubricCriterion) RubricItem(com.instructure.candroid.model.RubricItem) RubricCommentItem(com.instructure.candroid.model.RubricCommentItem)

Aggregations

RubricCommentItem (com.instructure.candroid.model.RubricCommentItem)2 RubricItem (com.instructure.candroid.model.RubricItem)1 RubricRatingItem (com.instructure.candroid.model.RubricRatingItem)1 RubricCriterion (com.instructure.canvasapi2.models.RubricCriterion)1 RubricCriterionRating (com.instructure.canvasapi2.models.RubricCriterionRating)1 Test (org.junit.Test)1