Search in sources :

Example 1 with PercentageRating

use of androidx.media3.common.PercentageRating in project media by androidx.

the class MediaUtilsTest method assertRatingEquals.

void assertRatingEquals(Rating rating, RatingCompat ratingCompat) {
    if (rating == null && ratingCompat == null) {
        return;
    }
    assertThat(rating.isRated()).isEqualTo(ratingCompat.isRated());
    if (rating instanceof HeartRating) {
        assertThat(ratingCompat.getRatingStyle()).isEqualTo(RatingCompat.RATING_HEART);
        assertThat(((HeartRating) rating).isHeart()).isEqualTo(ratingCompat.hasHeart());
    } else if (rating instanceof ThumbRating) {
        assertThat(ratingCompat.getRatingStyle()).isEqualTo(RatingCompat.RATING_THUMB_UP_DOWN);
        assertThat(((ThumbRating) rating).isThumbsUp()).isEqualTo(ratingCompat.isThumbUp());
    } else if (rating instanceof StarRating) {
        StarRating starRating = (StarRating) rating;
        switch(starRating.getMaxStars()) {
            case 3:
                assertThat(ratingCompat.getRatingStyle()).isEqualTo(RatingCompat.RATING_3_STARS);
                break;
            case 4:
                assertThat(ratingCompat.getRatingStyle()).isEqualTo(RatingCompat.RATING_4_STARS);
                break;
            case 5:
                assertThat(ratingCompat.getRatingStyle()).isEqualTo(RatingCompat.RATING_5_STARS);
                break;
            // fall out
            default:
        }
        assertThat(starRating.getStarRating()).isEqualTo(ratingCompat.getStarRating());
    } else if (rating instanceof PercentageRating) {
        assertThat(ratingCompat.getRatingStyle()).isEqualTo(RatingCompat.RATING_PERCENTAGE);
        assertThat(((PercentageRating) rating).getPercent()).isEqualTo(ratingCompat.getPercentRating());
    }
}
Also used : ThumbRating(androidx.media3.common.ThumbRating) PercentageRating(androidx.media3.common.PercentageRating) StarRating(androidx.media3.common.StarRating) HeartRating(androidx.media3.common.HeartRating)

Aggregations

HeartRating (androidx.media3.common.HeartRating)1 PercentageRating (androidx.media3.common.PercentageRating)1 StarRating (androidx.media3.common.StarRating)1 ThumbRating (androidx.media3.common.ThumbRating)1