picasso: Should #placeholder(int) and #error(int) support theme attribute?

I mean in case we want some theme-depended drawable (vector, for example, which could be passed theme’s color as attribute, not constant color value). By that a placeholder’s drawable could be “lighter” in dark theme, and “darker” in light theme, dynamically. (IMO, caching a placeholder drawable is not necessary, as it doesn’t consume too much resource).

The problem now is: Picasso will use a final ApplicationContext for its #getDrawable() action, which will not listen to theme’s attributes.

Don’t know if you are interested in theming and support libraries or not, but it would be nice if Picasso supports something like ContextCompat.getDrawable().

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 6
  • Comments: 22 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I have this night theme bug in 2.8. I have an vector drawable which I tint with a theme attribute: This causes a strange behavior/bug when I use the same drawable resource id for error and placeholder. The placeholder will use the day theme and the error the dark theme. My workaround is to use there a distince Picasso instance, but It would be nice if Picasso could use the context of the view where the image is loaded “into”.

As of the code on master we finally have the ability to change this. We not longer require a Context for the with() call and can add overloads or new methods which take a Context for loading.

On Thu, Jul 20, 2017, 10:01 PM Alan Viverette notifications@github.com wrote:

picasso’s request creator using the context from when the picasso instance was instantiated to resolve placeholder drawables

This is WAI – due to multi-window support, Resources objects in O+ can exist against multiple configurations within the same application.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/square/picasso/issues/1275#issuecomment-316828857, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEb6Oxd12fKiO-jZm_8lq0_i8q14gks5sP8A7gaJpZM4HLI1z .

One more data point, something changed between Android N and Android O theme resolution for night mode colors. We are using night mode resource loading with Picasso. Particularly we are doing

Picasso.with(context)
                .load(dimension.getUrl())
                .placeholder(R.color.image_placeholder);

With android N and below the R.color.image_placeholdervalue would resolve to our night mode color. With android O the color is always resolving to the non night color. Chasing the code down it seems to be due to picasso’s request creator using the context from when the picasso instance was instantiated to resolve placeholder drawables.

private Drawable getPlaceholderDrawable() {
    if (placeholderResId != 0) {
      return picasso.context.getResources().getDrawable(placeholderResId);
    } else {
      return placeholderDrawable; // This may be null which is expected and desired behavior.
    }
  }

I’m assuming something changed in how themes are resolved in O that is causing this issue but I wasn’t sure where to report