use of com.facebook.imagepipeline.request.MediaVariations in project fresco by facebook.
the class MediaVariationsIndexDatabaseTest method testGetsNoCachedVariantsIfNothingStored.
@Test
public void testGetsNoCachedVariantsIfNothingStored() {
MediaVariations mediaVariations = mMediaVariationsIndexDatabase.getCachedVariantsSync(MEDIA_ID, MediaVariations.newBuilderForMediaId(MEDIA_ID));
assertThat(mediaVariations.getMediaId()).isEqualTo(MEDIA_ID);
assertThat(mediaVariations.getVariantsCount()).isZero();
}
use of com.facebook.imagepipeline.request.MediaVariations in project fresco by facebook.
the class MediaVariationsIndexDatabaseTest method testMediaVariationsShouldForceRequestIfSetInProvidedBuilder.
@Test
public void testMediaVariationsShouldForceRequestIfSetInProvidedBuilder() {
mMediaVariationsIndexDatabase.saveCachedVariantSync(MEDIA_ID, CACHE_CHOICE_1, CACHE_KEY_1, mEncodedImage1);
MediaVariations.Builder builder = MediaVariations.newBuilderForMediaId(MEDIA_ID).setForceRequestForSpecifiedUri(true);
MediaVariations mediaVariations = mMediaVariationsIndexDatabase.getCachedVariantsSync(MEDIA_ID, builder);
assertThat(mediaVariations.shouldForceRequestForSpecifiedUri()).isTrue();
}
use of com.facebook.imagepipeline.request.MediaVariations in project fresco by facebook.
the class MediaVariationsIndexDatabaseTest method testGetsSameCachedVariantAfterBeingSavedIfOneSaved.
@Test
public void testGetsSameCachedVariantAfterBeingSavedIfOneSaved() {
mMediaVariationsIndexDatabase.saveCachedVariantSync(MEDIA_ID, ImageRequest.CacheChoice.DEFAULT, CACHE_KEY_1, mEncodedImage1);
MediaVariations mediaVariations = mMediaVariationsIndexDatabase.getCachedVariantsSync(MEDIA_ID, MediaVariations.newBuilderForMediaId(MEDIA_ID));
assertThat(mediaVariations.getVariantsCount()).isEqualTo(1);
assertVariantIsEqualTo(mediaVariations.getVariant(0), URI_1, WIDTH_1, HEIGHT_1, CACHE_CHOICE_1);
}
use of com.facebook.imagepipeline.request.MediaVariations in project fresco by facebook.
the class MediaVariationsFallbackProducerTest method testSendsNonFinalImageToConsumerAndStartsInputProducerIfRequestForcesRequestForSpecifiedUri.
@Test
public void testSendsNonFinalImageToConsumerAndStartsInputProducerIfRequestForcesRequestForSpecifiedUri() {
MediaVariations mediaVariations = MediaVariations.newBuilderForMediaId(MEDIA_ID).setForceRequestForSpecifiedUri(true).build();
when(mImageRequest.getMediaVariations()).thenReturn(mediaVariations);
whenCacheContains(mDefaultBufferedDiskCache, CACHE_KEY_S, CACHE_KEY_M, CACHE_KEY_L);
whenIndexDbContains(URI_M, SIZE_M, CacheChoice.DEFAULT);
when(mImageRequest.getResizeOptions()).thenReturn(new ResizeOptions(SIZE_M - 10, SIZE_M - 10));
mMediaVariationsFallbackProducer.produceResults(mConsumer, mProducerContext);
verify(mConsumer).onNewResult(mImageM, false);
verify(mConsumer, never()).onProgressUpdate(anyFloat());
verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
verifySuccessSentToListener(FOUND, NOT_USED_AS_LAST, MediaVariations.SOURCE_INDEX_DB, 1);
verifyInputProducerProduceResultsWithNewConsumer();
verifyZeroInteractions(mSmallImageBufferedDiskCache);
}
use of com.facebook.imagepipeline.request.MediaVariations in project fresco by facebook.
the class MediaVariationsFallbackProducer method produceResults.
public void produceResults(final Consumer<EncodedImage> consumer, final ProducerContext producerContext) {
final ImageRequest imageRequest = producerContext.getImageRequest();
final ResizeOptions resizeOptions = imageRequest.getResizeOptions();
final MediaVariations mediaVariations = imageRequest.getMediaVariations();
if (!imageRequest.isDiskCacheEnabled() || resizeOptions == null || resizeOptions.height <= 0 || resizeOptions.width <= 0) {
startInputProducerWithExistingConsumer(consumer, producerContext);
return;
}
final String mediaId;
@MediaVariations.Source final String source;
if (mediaVariations == null) {
if (mMediaIdExtractor == null) {
mediaId = null;
source = null;
} else {
mediaId = mMediaIdExtractor.getMediaIdFrom(imageRequest.getSourceUri());
source = MediaVariations.SOURCE_ID_EXTRACTOR;
}
} else {
mediaId = mediaVariations.getMediaId();
source = MediaVariations.SOURCE_INDEX_DB;
}
if (mediaVariations == null && mediaId == null) {
startInputProducerWithExistingConsumer(consumer, producerContext);
return;
}
producerContext.getListener().onProducerStart(producerContext.getId(), PRODUCER_NAME);
final AtomicBoolean isCancelled = new AtomicBoolean(false);
if (mediaVariations != null && mediaVariations.getVariantsCount() > 0) {
chooseFromVariants(consumer, producerContext, imageRequest, mediaVariations, resizeOptions, isCancelled);
} else {
MediaVariations.Builder mediaVariationsBuilder = MediaVariations.newBuilderForMediaId(mediaId).setForceRequestForSpecifiedUri(mediaVariations != null && mediaVariations.shouldForceRequestForSpecifiedUri()).setSource(source);
Task<MediaVariations> indexedMediaVariationsTask = mMediaVariationsIndex.getCachedVariants(mediaId, mediaVariationsBuilder);
indexedMediaVariationsTask.continueWith(new Continuation<MediaVariations, Object>() {
@Override
public Object then(Task<MediaVariations> task) throws Exception {
if (task.isCancelled() || task.isFaulted()) {
return task;
} else {
try {
if (task.getResult() == null) {
startInputProducerWithWrappedConsumer(consumer, producerContext, mediaId);
return null;
} else {
return chooseFromVariants(consumer, producerContext, imageRequest, task.getResult(), resizeOptions, isCancelled);
}
} catch (Exception e) {
return null;
}
}
}
});
}
subscribeTaskForRequestCancellation(isCancelled, producerContext);
}
Aggregations