Merged
Conversation
Contributor
There was a problem hiding this comment.
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
RemoteViewsTargetusage with synchronous image fetch +setImageViewBitmapin widget update flows - Deleted
RemoteViewsTarget.ktas 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
widgetCameraImagevisible 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(...).imageis null or the request throws, the code leaveswidgetMediaImagevisible 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
approved these changes
Mar 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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