Closed marcelpinto closed 2 years ago
The problem is those might not be stored in disk. Thus, no URI available to pass. Only the downloaded image is cached
On Thu, 23 Jun 2022, 12:12 Yuri Schimke, @.***> wrote:
@.**** commented on this pull request.
In AppWidget/app/src/main/java/com/example/android/appwidget/glance/image/ImageWorker.kt https://github.com/android/user-interface-samples/pull/356#discussion_r904844905 :
- */
- @OptIn(ExperimentalCoilApi::class)
- private suspend fun getRandomImage(width: Float, height: Float, force: Boolean): String {
- val url = "https://picsum.photos/${width.roundToInt()}/${height.roundToInt()}"
- val request = ImageRequest.Builder(context)
- .data(url)
- .build()
- // Request the image to be loaded and throw error if it failed
- with(context.imageLoader) {
- if (force) {
- diskCache?.remove(url)
- memoryCache?.remove(MemoryCache.Key(url))
- }
- val result = execute(request)
- if (result is ErrorResult) {
Coil has placeholder images also, so a proper library might even use that depending on the delay fetching images.
— Reply to this email directly, view it on GitHub https://github.com/android/user-interface-samples/pull/356#discussion_r904844905, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUEQ2KECVCVBH4FJ6Q6ATTVQQ2CRANCNFSM5ZPLS3FQ . You are receiving this because you authored the thread.Message ID: @.***>