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);
}
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);
}
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);
}
}
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();
}
Aggregations