-
-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate from Picasso to Coil (#4911)
* Migrate from Picasso to Coil * Update to avoid placeholder blinking
- Loading branch information
Showing
7 changed files
with
115 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
35 changes: 35 additions & 0 deletions
35
app/src/main/java/io/homeassistant/companion/android/widgets/common/RemoteViewsTarget.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.homeassistant.companion.android.widgets.common | ||
|
||
import android.appwidget.AppWidgetManager | ||
import android.content.Context | ||
import android.widget.RemoteViews | ||
import androidx.annotation.IdRes | ||
import coil3.Image | ||
import coil3.target.Target | ||
import coil3.toBitmap | ||
|
||
/** | ||
* Load images into RemoteViews with Coil | ||
* (based on https://coil-kt.github.io/coil/recipes/#remote-views) | ||
*/ | ||
class RemoteViewsTarget( | ||
private val context: Context, | ||
private val appWidgetId: Int, | ||
private val remoteViews: RemoteViews, | ||
@IdRes private val imageViewResId: Int | ||
) : Target { | ||
|
||
override fun onStart(placeholder: Image?) { | ||
// Skip if null to avoid blinking (there is no placeholder) | ||
placeholder?.let { setDrawable(it) } | ||
} | ||
|
||
override fun onError(error: Image?) = setDrawable(error) | ||
|
||
override fun onSuccess(result: Image) = setDrawable(result) | ||
|
||
private fun setDrawable(image: Image?) { | ||
remoteViews.setImageViewBitmap(imageViewResId, image?.toBitmap()) | ||
AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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