diff --git a/vito/core-java-impl/src/main/java/com/facebook/fresco/vito/core/impl/FrescoVitoPrefetcherImpl.kt b/vito/core-java-impl/src/main/java/com/facebook/fresco/vito/core/impl/FrescoVitoPrefetcherImpl.kt index 02a86d43ea..98b5a1a074 100644 --- a/vito/core-java-impl/src/main/java/com/facebook/fresco/vito/core/impl/FrescoVitoPrefetcherImpl.kt +++ b/vito/core-java-impl/src/main/java/com/facebook/fresco/vito/core/impl/FrescoVitoPrefetcherImpl.kt @@ -9,6 +9,7 @@ package com.facebook.fresco.vito.core.impl import android.net.Uri import com.facebook.callercontext.CallerContextVerifier +import com.facebook.common.callercontext.ContextChain import com.facebook.datasource.DataSource import com.facebook.datasource.DataSources import com.facebook.fresco.vito.core.FrescoVitoPrefetcher @@ -49,6 +50,15 @@ class FrescoVitoPrefetcherImpl( } } + override fun prefetch( + prefetchTarget: PrefetchTarget, + uri: Uri, + imageOptions: ImageOptions?, + callerContext: Any?, + contextChain: ContextChain?, + callsite: String + ): DataSource = prefetch(prefetchTarget, uri, imageOptions, callerContext, callsite) + override fun prefetchToBitmapCache( uri: Uri, imageOptions: DecodedImageOptions?, @@ -59,6 +69,16 @@ class FrescoVitoPrefetcherImpl( return prefetch(PrefetchTarget.MEMORY_DECODED, imageRequest, callerContext, null) } + override fun prefetchToBitmapCache( + uri: Uri, + imageOptions: DecodedImageOptions?, + callerContext: Any?, + contextChain: ContextChain?, + callsite: String + ): DataSource { + return prefetchToBitmapCache(uri, imageOptions, callerContext, callsite) + } + override fun prefetchToEncodedCache( uri: Uri, imageOptions: EncodedImageOptions?, @@ -69,6 +89,14 @@ class FrescoVitoPrefetcherImpl( return prefetch(PrefetchTarget.MEMORY_ENCODED, imageRequest, callerContext, null) } + override fun prefetchToEncodedCache( + uri: Uri, + imageOptions: EncodedImageOptions?, + callerContext: Any?, + contextChain: ContextChain?, + callsite: String + ): DataSource = prefetchToEncodedCache(uri, imageOptions, callerContext, callsite) + override fun prefetchToDiskCache( uri: Uri, imageOptions: ImageOptions?, @@ -79,6 +107,14 @@ class FrescoVitoPrefetcherImpl( return prefetch(PrefetchTarget.DISK, imageRequest, callerContext, null) } + override fun prefetchToDiskCache( + uri: Uri, + imageOptions: ImageOptions?, + callerContext: Any?, + contextChain: ContextChain?, + callsite: String + ): DataSource = prefetchToDiskCache(uri, imageOptions, callerContext, callsite) + override fun prefetch( prefetchTarget: PrefetchTarget, imageRequest: VitoImageRequest, @@ -88,6 +124,16 @@ class FrescoVitoPrefetcherImpl( ): DataSource = prefetch(prefetchTarget, imageRequest.finalImageRequest, callerContext, requestListener) + override fun prefetch( + prefetchTarget: PrefetchTarget, + imageRequest: VitoImageRequest, + callerContext: Any?, + contextChain: ContextChain?, + requestListener: RequestListener?, + callsite: String + ): DataSource = + prefetch(prefetchTarget, imageRequest, callerContext, requestListener, callsite) + private fun prefetch( prefetchTarget: PrefetchTarget, imageRequest: ImageRequest?, diff --git a/vito/core-java-impl/src/main/java/com/facebook/fresco/vito/core/impl/NoOpFrescoVitoPrefetcher.kt b/vito/core-java-impl/src/main/java/com/facebook/fresco/vito/core/impl/NoOpFrescoVitoPrefetcher.kt index 86eae726ee..da93dc6266 100644 --- a/vito/core-java-impl/src/main/java/com/facebook/fresco/vito/core/impl/NoOpFrescoVitoPrefetcher.kt +++ b/vito/core-java-impl/src/main/java/com/facebook/fresco/vito/core/impl/NoOpFrescoVitoPrefetcher.kt @@ -8,6 +8,7 @@ package com.facebook.fresco.vito.core.impl import android.net.Uri +import com.facebook.common.callercontext.ContextChain import com.facebook.datasource.DataSource import com.facebook.datasource.DataSources import com.facebook.fresco.vito.core.FrescoVitoPrefetcher @@ -29,6 +30,15 @@ class NoOpFrescoVitoPrefetcher(private val throwException: Boolean = false) : Fr callsite: String ): DataSource = maybeThrowUnsupportedOperationException() + override fun prefetch( + prefetchTarget: PrefetchTarget, + uri: Uri, + imageOptions: ImageOptions?, + callerContext: Any?, + contextChain: ContextChain?, + callsite: String + ): DataSource = maybeThrowUnsupportedOperationException() + override fun prefetchToBitmapCache( uri: Uri, imageOptions: DecodedImageOptions?, @@ -36,6 +46,14 @@ class NoOpFrescoVitoPrefetcher(private val throwException: Boolean = false) : Fr callsite: String ): DataSource = maybeThrowUnsupportedOperationException() + override fun prefetchToBitmapCache( + uri: Uri, + imageOptions: DecodedImageOptions?, + callerContext: Any?, + contextChain: ContextChain?, + callsite: String + ): DataSource = maybeThrowUnsupportedOperationException() + override fun prefetchToEncodedCache( uri: Uri, imageOptions: EncodedImageOptions?, @@ -43,10 +61,34 @@ class NoOpFrescoVitoPrefetcher(private val throwException: Boolean = false) : Fr callsite: String ): DataSource = maybeThrowUnsupportedOperationException() + override fun prefetchToEncodedCache( + uri: Uri, + imageOptions: EncodedImageOptions?, + callerContext: Any?, + contextChain: ContextChain?, + callsite: String + ): DataSource = maybeThrowUnsupportedOperationException() + + override fun prefetchToDiskCache( + uri: Uri, + imageOptions: ImageOptions?, + callerContext: Any?, + callsite: String + ): DataSource = maybeThrowUnsupportedOperationException() + override fun prefetchToDiskCache( uri: Uri, imageOptions: ImageOptions?, callerContext: Any?, + contextChain: ContextChain?, + callsite: String + ): DataSource = maybeThrowUnsupportedOperationException() + + override fun prefetch( + prefetchTarget: PrefetchTarget, + imageRequest: VitoImageRequest, + callerContext: Any?, + requestListener: RequestListener?, callsite: String ): DataSource = maybeThrowUnsupportedOperationException() @@ -54,6 +96,7 @@ class NoOpFrescoVitoPrefetcher(private val throwException: Boolean = false) : Fr prefetchTarget: PrefetchTarget, imageRequest: VitoImageRequest, callerContext: Any?, + contextChain: ContextChain?, requestListener: RequestListener?, callsite: String ): DataSource = maybeThrowUnsupportedOperationException() diff --git a/vito/core/src/main/java/com/facebook/fresco/vito/core/FrescoVitoPrefetcher.kt b/vito/core/src/main/java/com/facebook/fresco/vito/core/FrescoVitoPrefetcher.kt index 51744f4191..610758401d 100644 --- a/vito/core/src/main/java/com/facebook/fresco/vito/core/FrescoVitoPrefetcher.kt +++ b/vito/core/src/main/java/com/facebook/fresco/vito/core/FrescoVitoPrefetcher.kt @@ -8,6 +8,7 @@ package com.facebook.fresco.vito.core import android.net.Uri +import com.facebook.common.callercontext.ContextChain import com.facebook.datasource.DataSource import com.facebook.fresco.vito.options.DecodedImageOptions import com.facebook.fresco.vito.options.EncodedImageOptions @@ -37,6 +38,29 @@ interface FrescoVitoPrefetcher { callsite: String ): DataSource + /** + * Prefetch an image to the given [PrefetchTarget] + * + * Beware that if your network fetcher doesn't support priorities prefetch requests may slow down + * images which are immediately required on screen. + * + * @param prefetchTarget the target to prefetch to + * @param uri the image URI to prefetch + * @param imageOptions the image options used to display the image + * @param callerContext the caller context for the given image + * @param contextChain the context chain for the given image + * @param callsite the prefetch callsite from which this request is being made, for logging + * @return a DataSource that can safely be ignored. + */ + fun prefetch( + prefetchTarget: PrefetchTarget, + uri: Uri, + imageOptions: ImageOptions?, + callerContext: Any?, + contextChain: ContextChain?, + callsite: String + ): DataSource + /** * Prefetch an image to the bitmap memory cache (for decoded images). In order to cancel the * prefetch, close the [DataSource] returned by this method. @@ -57,6 +81,48 @@ interface FrescoVitoPrefetcher { callsite: String ): DataSource + /** + * Prefetch an image to the bitmap memory cache (for decoded images). In order to cancel the + * prefetch, close the [DataSource] returned by this method. + * + * Beware that if your network fetcher doesn't support priorities prefetch requests may slow down + * images which are immediately required on screen. + * + * @param uri the image URI to prefetch + * @param imageOptions the image options used to display the image + * @param callerContext the caller context for the given image + * @param contextChain the context chain for the given image + * @param callsite the prefetch callsite from which this request is being made, for logging + * @return a DataSource that can safely be ignored. + */ + fun prefetchToBitmapCache( + uri: Uri, + imageOptions: DecodedImageOptions?, + callerContext: Any?, + contextChain: ContextChain?, + callsite: String + ): DataSource + + /** + * Prefetch an image to the encoded memory cache. In order to cancel the prefetch, close the + * [DataSource] returned by this method. + * + * Beware that if your network fetcher doesn't support priorities prefetch requests may slow down + * images which are immediately required on screen. + * + * @param uri the image URI to prefetch + * @param imageOptions the image options used to display the image + * @param callerContext the caller context for the given image + * @param callsite the prefetch callsite from which this request is being made, for logging + * @return a DataSource that can safely be ignored. + */ + fun prefetchToEncodedCache( + uri: Uri, + imageOptions: EncodedImageOptions?, + callerContext: Any?, + callsite: String + ): DataSource + /** * Prefetch an image to the encoded memory cache. In order to cancel the prefetch, close the * [DataSource] returned by this method. @@ -67,6 +133,7 @@ interface FrescoVitoPrefetcher { * @param uri the image URI to prefetch * @param imageOptions the image options used to display the image * @param callerContext the caller context for the given image + * @param contextChain the context chain for the given image * @param callsite the prefetch callsite from which this request is being made, for logging * @return a DataSource that can safely be ignored. */ @@ -74,6 +141,7 @@ interface FrescoVitoPrefetcher { uri: Uri, imageOptions: EncodedImageOptions?, callerContext: Any?, + contextChain: ContextChain?, callsite: String ): DataSource @@ -97,6 +165,49 @@ interface FrescoVitoPrefetcher { callsite: String ): DataSource + /** + * Prefetch an image to the disk cache. In order to cancel the prefetch, close the [DataSource] + * returned by this method. + * + * Beware that if your network fetcher doesn't support priorities prefetch requests may slow down + * images which are immediately required on screen. + * + * @param uri the image URI to prefetch + * @param imageOptions the image options used to display the image + * @param callerContext the caller context for the given image + * @param contextChain the context chain for the given image + * @param callsite the prefetch callsite from which this request is being made, for logging + * @return a DataSource that can safely be ignored. + */ + fun prefetchToDiskCache( + uri: Uri, + imageOptions: ImageOptions?, + callerContext: Any?, + contextChain: ContextChain?, + callsite: String + ): DataSource + + /** + * Prefetch an image to the given [PrefetchTarget] using a [VitoImageRequest]. In order to cancel + * the prefetch, close the [DataSource] returned by this method. + * + * Beware that if your network fetcher doesn't support priorities prefetch requests may slow down + * images which are immediately required on screen. + * + * @param prefetchTarget the target to prefetch to + * @param callerContext the caller context for the given image + * @param requestListener optional request listener + * @param callsite the prefetch callsite from which this request is being made, for logging + * @return a DataSource that can safely be ignored. + */ + fun prefetch( + prefetchTarget: PrefetchTarget, + imageRequest: VitoImageRequest, + callerContext: Any?, + requestListener: RequestListener?, + callsite: String + ): DataSource + /** * Prefetch an image to the given [PrefetchTarget] using a [VitoImageRequest]. In order to cancel * the prefetch, close the [DataSource] returned by this method. @@ -106,6 +217,7 @@ interface FrescoVitoPrefetcher { * * @param prefetchTarget the target to prefetch to * @param callerContext the caller context for the given image + * @param contextChain the context chain for the given image * @param requestListener optional request listener * @param callsite the prefetch callsite from which this request is being made, for logging * @return a DataSource that can safely be ignored. @@ -114,6 +226,7 @@ interface FrescoVitoPrefetcher { prefetchTarget: PrefetchTarget, imageRequest: VitoImageRequest, callerContext: Any?, + contextChain: ContextChain?, requestListener: RequestListener?, callsite: String ): DataSource