Skip to content

Commit

Permalink
Added new Vito ImagePipeline API to evict an image
Browse files Browse the repository at this point in the history
Reviewed By: kartavya-ramnani

Differential Revision: D65601111

fbshipit-source-id: 8f1fa93bd05d78dcd04a11217b7c1d3ae00f0448
  • Loading branch information
oprisnik authored and facebook-github-bot committed Nov 11, 2024
1 parent b532c53 commit 973d3fb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.facebook.fresco.samples.showcase.misc.ImageUriProvider
import com.facebook.fresco.vito.options.ImageOptions
import com.facebook.fresco.vito.options.RoundingOptions
import com.facebook.fresco.vito.provider.FrescoVitoProvider
import com.facebook.fresco.vito.source.ImageSourceProvider
import com.facebook.fresco.vito.view.VitoView

class VitoViewPrefetchFragment : BaseShowcaseFragment() {
Expand All @@ -42,6 +43,9 @@ class VitoViewPrefetchFragment : BaseShowcaseFragment() {
private val buttonClearCache
get() = binding.buttonClearCache

private val buttonClearCacheSingleItem
get() = binding.buttonClearCacheSingleItem

private val imageOptions =
ImageOptions.create()
.round(RoundingOptions.asCircle())
Expand Down Expand Up @@ -87,6 +91,12 @@ class VitoViewPrefetchFragment : BaseShowcaseFragment() {
}

buttonClearCache.setOnClickListener { Fresco.getImagePipeline().clearCaches() }
buttonClearCacheSingleItem.setOnClickListener {
FrescoVitoProvider.getImagePipeline()
.evictFromCaches(
FrescoVitoProvider.getImagePipeline()
.createImageRequest(resources, ImageSourceProvider.forUri(uri), imageOptions))
}
}

override fun onDestroyView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,22 @@
android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:gravity="center"
>

<Button
android:id="@+id/button_toggle_images" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/button_toggle_images"
/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center">
<Button
android:id="@+id/button_clear_cache" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/button_clear_cache"
/>
<Button
android:id="@+id/button_clear_cache_single_item" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/button_clear_cache_single_item"
/>
</LinearLayout>
</LinearLayout>
3 changes: 2 additions & 1 deletion samples/showcase/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@
<string name="welcome_button_github">GitHub</string>
<string name="welcome_button_doc">Documentation</string>

<string name="button_clear_cache">Clear Cache</string>
<string name="button_clear_cache">Clear Cache (all)</string>
<string name="button_clear_cache_single_item">Clear Cache (single item)</string>
<string name="button_prefetch_disk">Prefetch Disk</string>
<string name="button_prefetch_encoded">Prefetch Encoded</string>
<string name="button_prefetch_bitmap">Prefetch Bitmap</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ class VitoImagePipelineImpl(
}
}

override fun evictFromCaches(imageRequest: VitoImageRequest) {
val uri = imageRequest.finalImageRequest?.sourceUri ?: return
imagePipeline.evictFromCache(uri)
}

private fun experimentalDynamicSizeVito2(): Boolean = config.experimentalDynamicSizeVito2()

private fun experimentalDynamicSizeWithCacheFallbackVito2(): Boolean =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ interface VitoImagePipeline {
): Boolean {
throw UnsupportedOperationException("Not implemented yet")
}

/** Remove an image from all disk & memory caches. */
fun evictFromCaches(imageRequest: VitoImageRequest) {
throw UnsupportedOperationException("Method not implemented: evictFromCaches")
}
}

0 comments on commit 973d3fb

Please sign in to comment.