Skip to content

Remove RemoteViewsTarget#6629

Merged
jpelgrom merged 1 commit intomainfrom
feature/improve_widget_image_loading
Mar 27, 2026
Merged

Remove RemoteViewsTarget#6629
jpelgrom merged 1 commit intomainfrom
feature/improve_widget_image_loading

Conversation

@TimoPtr
Copy link
Copy Markdown
Member

@TimoPtr TimoPtr commented Mar 26, 2026

Summary

While looking at #6626 I found out another way to get the image instead of passing the RemoteView to another object. Thanks to @FletcherD

I prefer this approach to not "leak" the RemoteView into another object.

Checklist

  • New or updated tests have been added to cover the changes following the testing guidelines.
  • The code follows the project's code style and best_practices.
  • The changes have been thoroughly tested, and edge cases have been considered.
  • Changes are backward compatible whenever feasible. Any breaking changes are documented in the changelog for users and/or in the code for developers depending on the relevance.

Copilot AI review requested due to automatic review settings March 26, 2026 09:29
@TimoPtr TimoPtr requested a review from jpelgrom March 26, 2026 09:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the custom RemoteViewsTarget Coil integration for widgets and switches widget image loading to a direct ImageLoader.execute(...) + toBitmap() approach, avoiding passing RemoteViews into a separate target object.

Changes:

  • Replaced RemoteViewsTarget usage with synchronous image fetch + setImageViewBitmap in widget update flows
  • Deleted RemoteViewsTarget.kt as it’s no longer needed
  • Updated widget files to use coil3.toBitmap

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
app/src/main/kotlin/io/homeassistant/companion/android/widgets/mediaplayer/MediaPlayerControlsWidget.kt Loads album art via imageLoader.execute and applies bitmap directly to RemoteViews
app/src/main/kotlin/io/homeassistant/companion/android/widgets/common/RemoteViewsTarget.kt Removed unused Coil Target implementation for RemoteViews
app/src/main/kotlin/io/homeassistant/companion/android/widgets/camera/CameraWidget.kt Loads camera preview via imageLoader.execute and applies bitmap directly to RemoteViews
Comments suppressed due to low confidence (2)

app/src/main/kotlin/io/homeassistant/companion/android/widgets/camera/CameraWidget.kt:187

  • If the image request fails (or returns null image), the widget currently keeps widgetCameraImage visible and does not clear/set a bitmap. Because RemoteViews updates are incremental, this can leave a stale image from a previous successful update or an empty image view. Consider only swapping placeholder->image after a successful bitmap decode, or in the error/null-image path explicitly show the placeholder (and/or clear the ImageView bitmap) before returning the RemoteViews.
                    setViewVisibility(
                        R.id.widgetCameraImage,
                        View.VISIBLE,
                    )
                    setViewVisibility(
                        R.id.widgetCameraPlaceholder,
                        View.GONE,
                    )
                    Timber.d("Fetching camera image")
                    try {
                        context.imageLoader.execute(
                            ImageRequest.Builder(context)
                                .data(url)
                                // RemoteViews requires software bitmaps for serialization
                                .allowHardware(false)
                                .diskCachePolicy(CachePolicy.DISABLED)
                                .memoryCachePolicy(CachePolicy.DISABLED)
                                .networkCachePolicy(CachePolicy.READ_ONLY)
                                .size(Size(getScreenWidth(), Dimension.Undefined))
                                .precision(Precision.INEXACT)
                                .build(),
                        ).image?.toBitmap()?.let {
                            setImageViewBitmap(R.id.widgetCameraImage, it)
                        }
                    } catch (e: CancellationException) {
                        throw e
                    } catch (e: Exception) {
                        Timber.e(e, "Unable to fetch image")
                    }

app/src/main/kotlin/io/homeassistant/companion/android/widgets/mediaplayer/MediaPlayerControlsWidget.kt:271

  • When execute(...).image is null or the request throws, the code leaves widgetMediaImage visible and does not clear/set a bitmap. With RemoteViews this can result in showing stale album art from a previous update or a blank image area. Consider keeping the placeholder visible until a bitmap is successfully set, or in the error/null-image path explicitly restore the placeholder (and/or clear the ImageView bitmap).
                    setViewVisibility(
                        R.id.widgetMediaImage,
                        View.VISIBLE,
                    )
                    setViewVisibility(
                        R.id.widgetMediaPlaceholder,
                        View.GONE,
                    )
                    Timber.d("Fetching media preview image")
                    try {
                        context.imageLoader.execute(
                            ImageRequest.Builder(context)
                                .data(url)
                                // RemoteViews requires software bitmaps for serialization
                                .allowHardware(false)
                                .size(1024)
                                .build(),
                        ).image?.toBitmap()?.let {
                            setImageViewBitmap(R.id.widgetMediaImage, it)
                        }
                    } catch (e: CancellationException) {
                        throw e
                    } catch (e: Exception) {
                        Timber.e(e, "Unable to load image")
                    }

@jpelgrom jpelgrom merged commit 3b45a7f into main Mar 27, 2026
27 checks passed
@jpelgrom jpelgrom deleted the feature/improve_widget_image_loading branch March 27, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants