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

Issue when trying to load thumbnails from URL #1198

Closed
jahirfiquitiva opened this issue May 13, 2016 · 3 comments
Closed

Issue when trying to load thumbnails from URL #1198

jahirfiquitiva opened this issue May 13, 2016 · 3 comments
Labels

Comments

@jahirfiquitiva
Copy link

jahirfiquitiva commented May 13, 2016

Glide Version: 3.7.1

Integration libraries: None

Device/Android Version: Moto G Second Gen (Titan) - Android 6.0.1

I'm trying to use the code in your website (screenshot) to load a thumbnail using a String url.

screenshot_20160512-185432

When using this code, I get an error in Android Studio saying:
Cannot resolve method 'thumbnail(com.bumptech.glid.DrawableRequestBuilder<java.lang.String>)'

I saw another option in a website which was:

DrawableRequestBuilder thumbnailRequest = Glide.with(context).load(thumbnailURL).thumbnail(0.5f);

But now I get:

Unchecked assignment: 'com.bumptech.glide.DrawableRequestBuilder' to 'com.bumptech.glide.GenericRequestBuilder<?,?,?,android.graphics.Bitmap>'

What can I do to fix these issues? What can I use to use a String as thumbnail?


Additionally, I wanted to report, that I can't define .crossFade() before .asBitmap(), neither after it.

Basically, what I expect to be able to do is something like:

Glide.with(context).load(url).crossFade().asBitmap().thumbnail(thumbnailURL).into(target);

I hope to get some help soon. Thank you. :) And thanks for the awesome library.

@TWiStErRob
Copy link
Collaborator

TWiStErRob commented May 13, 2016

When using this code, I get an error

The code on https://futurestud.io/blog/glide-thumbnails works fine, but as soon as you start adding new things, especially asBitmap things may start to break. If you check the available overloads of .thumbnail() you'll see:
image

Glide uses the builder pattern to make a fluid easily changeable API to set up the load request. This is done via GenericRequestBuilder, and its subclasses: DrawableRequestBuilder and BitmapRequestBuilder. By default these two are not compatible, you have to decide what is your resulting object (Bitmap (forced) or Drawable (anything, incl. GIF anim)). This is because there's only one Target created and that target can only accept one type of object.

Unchecked assignment: 'DrawableRequestBuilder' to 'GenericRequestBuilder<?,?,?,Bitmap>'

The unchecked assignment is just a warning, but usually signifies you are doing something weird that may break at runtime. In this case since you cast or otherwise lost the generic argument of DrawableRequestBuilder you dropped all other generics support of that variable/object too, and there's a mismatch of the last generic argument (if you check DrawableRequestBuilder<ModelType> extends GenericRequestBuilder<ModelType, ..., GlideDrawable>) and we can agree that GlideDrawable (or Object after losing generics) is not necessarily compatible with Bitmap.

I can't define .crossFade() before .asBitmap(), neither after it.

Yep, it came up a lot and I fixed it now in #1096, but it's not released yet, you can get 3.8.0-SNAPSHOT to use it: https://github.com/bumptech/glide/wiki/Snapshots or use one of the complex workarounds presented in the listed issues.

I expect to be able to do is something like

That's not available as a convenience method, because most of the time you'll want to customize other things too. The float variant of thumbnail() uses the same url. Here's how to do what you're trying:

Glide
    .with(context)
    .load(url)
    .asBitmap() // -----------------------------------------
    .crossFade() //                                        |
    .thumbnail(Glide //                                    |
        .with(context) //                                  |
        .load(thumbnailURL) //                             |
        .asBitmap() // necessary to match the builder type <
        // .fitCenter|centerCrop() // may need to specify what transform you want
    )
    //.fitCenter|centerCrop() // implicitly added if you use `into(ImageView)`, see source of that method
    .into(imageView)
;

@jahirfiquitiva
Copy link
Author

jahirfiquitiva commented May 13, 2016

Thank you so much, using this now, which worked fine:

Glide.with(context)
        .load(url)
        .asBitmap()
        .crossFade()
        .thumbnail(
            Glide.with(context)
                    .load(thumbnailURL)
                    .asBitmap()
                    .crossFade()
                    .thumbnail(0.5f)
            )
        .into(imageView);

@TWiStErRob
Copy link
Collaborator

TWiStErRob commented May 13, 2016

That loads thumbnailUrl twice, so there are possibly 3 images shown in the same view with higher and higher quality; was that your intention?

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

No branches or pull requests

2 participants