Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

picasso placeholder nonsupport AppCompatDelegate #2082

Closed
jingchao920315 opened this issue Apr 18, 2019 · 4 comments
Closed

picasso placeholder nonsupport AppCompatDelegate #2082

jingchao920315 opened this issue Apr 18, 2019 · 4 comments

Comments

@jingchao920315
Copy link

drawable Choice problem

@JakeWharton
Copy link
Collaborator

This is not enough information for an actionable report. Please provide a failing test case or sample which demonstrates the problem.

@jingchao920315
Copy link
Author

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().

@JakeWharton
Copy link
Collaborator

Got it. We're tracking that use case with #1275.

@jingchao920315
Copy link
Author

in Activity call

AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);

placeholder image Resources no change drawable-night-xxhdpi

The main reason:

  private Drawable getPlaceholderDrawable() {
    if (placeholderResId != 0) {
      if (Build.VERSION.SDK_INT >= 21) {
        return picasso.context.getDrawable(placeholderResId);
      } else if (Build.VERSION.SDK_INT >= 16) {
        return picasso.context.getResources().getDrawable(placeholderResId);
      } else {
        TypedValue value = new TypedValue();
        picasso.context.getResources().getValue(placeholderResId, value, true);
        return picasso.context.getResources().getDrawable(value.resourceId);
      }
    } else {
      return placeholderDrawable; // This may be null which is expected and desired behavior.
    }
  }

picasso.context is ApplicationContext Can't get AppCompatActivity theme

Need to change:Picasso -Builder

    /** Start building a new {@link Picasso} instance. */
    public Builder(@NonNull Context context) {
      if (context == null) {
        throw new IllegalArgumentException("Context must not be null.");
      }
      this.context = context;
    }
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants