Search in sources :

Example 6 with MediaVariations

use of com.facebook.imagepipeline.request.MediaVariations in project fresco by facebook.

the class MediaVariationsFallbackProducer method attemptCacheReadForVariant.

private Task attemptCacheReadForVariant(final Consumer<EncodedImage> consumer, final ProducerContext producerContext, ImageRequest imageRequest, MediaVariations mediaVariations, List<MediaVariations.Variant> sortedVariants, int index, AtomicBoolean isCancelled) {
    final MediaVariations.Variant variant = sortedVariants.get(index);
    final CacheKey cacheKey = mCacheKeyFactory.getEncodedCacheKey(imageRequest, variant.getUri(), producerContext.getCallerContext());
    final ImageRequest.CacheChoice cacheChoice;
    if (variant.getCacheChoice() == null) {
        cacheChoice = imageRequest.getCacheChoice();
    } else {
        cacheChoice = variant.getCacheChoice();
    }
    final BufferedDiskCache preferredCache = cacheChoice == ImageRequest.CacheChoice.SMALL ? mSmallImageBufferedDiskCache : mDefaultBufferedDiskCache;
    Task<EncodedImage> readTask = preferredCache.get(cacheKey, isCancelled);
    Continuation<EncodedImage, Void> continuation = onFinishDiskReads(consumer, producerContext, imageRequest, mediaVariations, sortedVariants, index, isCancelled);
    return readTask.continueWith(continuation);
}
Also used : BufferedDiskCache(com.facebook.imagepipeline.cache.BufferedDiskCache) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) CacheKey(com.facebook.cache.common.CacheKey) MediaVariations(com.facebook.imagepipeline.request.MediaVariations)

Example 7 with MediaVariations

use of com.facebook.imagepipeline.request.MediaVariations in project fresco by facebook.

the class MediaVariationsIndexDatabaseTest method testGetsSameCachedVariantAfterBeingSavedIfTwoSaved.

@Test
public void testGetsSameCachedVariantAfterBeingSavedIfTwoSaved() {
    whenNonMatchingItemInIndex();
    mMediaVariationsIndexDatabase.saveCachedVariantSync(MEDIA_ID, CACHE_CHOICE_1, CACHE_KEY_1, mEncodedImage1);
    mMediaVariationsIndexDatabase.saveCachedVariantSync(MEDIA_ID, CACHE_CHOICE_2, CACHE_KEY_2, mEncodedImage2);
    MediaVariations mediaVariations = mMediaVariationsIndexDatabase.getCachedVariantsSync(MEDIA_ID, MediaVariations.newBuilderForMediaId(MEDIA_ID));
    assertThat(mediaVariations.getVariantsCount()).isEqualTo(2);
    assertVariantIsEqualTo(mediaVariations.getVariant(0), URI_1, WIDTH_1, HEIGHT_1, CACHE_CHOICE_1);
    assertVariantIsEqualTo(mediaVariations.getVariant(1), URI_2, WIDTH_2, HEIGHT_2, CACHE_CHOICE_2);
}
Also used : MediaVariations(com.facebook.imagepipeline.request.MediaVariations) Test(org.junit.Test)

Example 8 with MediaVariations

use of com.facebook.imagepipeline.request.MediaVariations in project fresco by facebook.

the class MediaVariationsIndexDatabaseTest method testMediaVariationsSourceIsSetAsExpected.

@Test
public void testMediaVariationsSourceIsSetAsExpected() {
    whenNonMatchingItemInIndex();
    String[] sources = new String[] { MediaVariations.SOURCE_IMAGE_REQUEST, MediaVariations.SOURCE_INDEX_DB };
    for (String source : sources) {
        MediaVariations.Builder builder = MediaVariations.newBuilderForMediaId(MEDIA_ID).setSource(source);
        MediaVariations mediaVariations = mMediaVariationsIndexDatabase.getCachedVariantsSync(MEDIA_ID, builder);
        assertThat(mediaVariations.getSource()).isEqualTo(source);
    }
}
Also used : MediaVariations(com.facebook.imagepipeline.request.MediaVariations) Test(org.junit.Test)

Example 9 with MediaVariations

use of com.facebook.imagepipeline.request.MediaVariations in project fresco by facebook.

the class MediaVariationsIndexDatabaseTest method testGetsNoCachedVariantsIfNonMatchingItemStored.

@Test
public void testGetsNoCachedVariantsIfNonMatchingItemStored() {
    whenNonMatchingItemInIndex();
    MediaVariations mediaVariations = mMediaVariationsIndexDatabase.getCachedVariantsSync(MEDIA_ID, MediaVariations.newBuilderForMediaId(MEDIA_ID));
    assertThat(mediaVariations.getMediaId()).isEqualTo(MEDIA_ID);
    assertThat(mediaVariations.getVariantsCount()).isZero();
}
Also used : MediaVariations(com.facebook.imagepipeline.request.MediaVariations) Test(org.junit.Test)

Aggregations

MediaVariations (com.facebook.imagepipeline.request.MediaVariations)9 Test (org.junit.Test)7 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)2 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)2 CacheKey (com.facebook.cache.common.CacheKey)1 BufferedDiskCache (com.facebook.imagepipeline.cache.BufferedDiskCache)1 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)1 CancellationException (java.util.concurrent.CancellationException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1