admin管理员组文章数量:1418334
I am using Fresco 2.5 and I am downloading image for URL into android ImageView. Unfortunately, I can't use SimpleDrawee.
How do I defer another request for the same URL if the previous request has not finished?
I could create concurrent map where I put url and ImageRequest in map. And if imageRequest for url exist do nothing, and on completion or failure remove the entry from the map.
What other way folks that use Fresco are deplicating the request. Glide has such a nice RequestManager class that handles all of that. I am surprised that Fresco doesn't have such a thing.
Perhaps I have missed something in the documentation that does this already.Would appreciate any suggestions.
I have code like this that doesn't do any map operation yet.
private fun loadImageUsingFresco(
url: String,
imageView: ImageView,
callback: IImageLoadedCallback?,
) {
val startTime = SystemClock.elapsedRealtime()
val imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)).build()
val dataSource =
Fresco.getImagePipeline().fetchDecodedImage(imageRequest, imageViewContext)
dataSource.subscribe(
object : BaseBitmapDataSubscriber() {
override fun onNewResultImpl(bitmap: Bitmap?) {
if (dataSource.isFinished && bitmap != null) {
runOnUiThread {
imageView.setImageBitmap(bitmap)
callback?.onSuccess()
}
}
}
override fun onFailureImpl(dataSource: DataSource<CloseableReference<CloseableImage>>) {
callback?.onFailure(url)
}
},
CallerThreadExecutor.getInstance(),
)
}
本文标签: androidDeduplicating Fresco image load request when using ImageRequest and ImageViewStack Overflow
版权声明:本文标题:android - Deduplicating Fresco image load request when using ImageRequest and ImageView - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745287711a2651599.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论