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

Allow fallback to take a full request rather than just drawables #451

Closed
sjudd opened this issue May 1, 2015 · 19 comments
Closed

Allow fallback to take a full request rather than just drawables #451

sjudd opened this issue May 1, 2015 · 19 comments
Milestone

Comments

@sjudd
Copy link
Collaborator

sjudd commented May 1, 2015

No description provided.

@TWiStErRob
Copy link
Collaborator

It's vastly more complicated to do so, and in many ways similar to functionality you can already get out of thumbnail.

I agree it's complex, here are some thoughts:

It's similar to thumbnail, but there's a big difference: thumbnail races for onResourceReady while fallback should only be started if model is null, that is taking the main load's place and giving null a whole new meaning. Thumbnail is also temporal (while the full load finishes), while again fallback is terminal, once it's displayed it shouldn't be overwritten with anything.

I think Andre's use case is a really good example (little bit enhanced here):

load(programme.url)
.thumbnail(0.2)
.fitCenter()
.fallback(
    load(programme.series.url)
    .thumbnail(0.4)
    .transformation(...)
    .fallback(
        load(programme.channel.url)
        .sizeMultiplier(0.5)
        .centerCrop()
    )
)

with the only exception that he expects HTTP 404 so fallbacks should be errors?!

@vsahu1986
Copy link

+1

1 similar comment
@vipinhelloindia
Copy link

+1

@quentin23soleil
Copy link

+1

1 similar comment
@AndreasBackx
Copy link

+1

@TWiStErRob TWiStErRob added this to the 4.0 milestone Oct 16, 2015
@dadouf
Copy link

dadouf commented Dec 23, 2015

+1

@JesperSjoquist
Copy link

+1

@Ribesg
Copy link

Ribesg commented Feb 15, 2016

+1 I'm showing pictures against a Stream description. I would like to show 1) a thumbnail if available 2) A game image if not 3) a default image if none is available

@sebnapi
Copy link

sebnapi commented Mar 2, 2016

+1 Use-Case: Fallback to different Images. Imagine a music-player that could download covers from last.fm or xyz.com or from the file or in the end generate a cover.

@pkuprys
Copy link

pkuprys commented Mar 23, 2016

+1

We have a lot of images we are loading in recycler views. An image can have more than one type, but depending on the resource/environment, not all types are available. So we first try to load type A, if it fails, we try to load type B, if that fails we try type C, so on and so forth.

We currently do this by calling load() in a listener's onException() method with the next URI and return true. If we run out of URIs to try, we return false. Ideally, we would like to pass in a list of URIs to the load() method, and just have our listener deal with the final success/failure scenario after either one of the URIs succeeds, or all have failed.

@agbison
Copy link

agbison commented Mar 23, 2016

+1

@TWiStErRob
Copy link
Collaborator

@"+1"s (everyone): can you please edit your comments to include your use case, it may help the implementor to choose the right way of implementing serving all of these use cases.

@bspurgin
Copy link

+1 - same use case as @pkuprys

@eanderso
Copy link

+1 I have a URL which may contain a specific image (if the vendor has a custom image) - however if it doesn't exist I need to hit another URL to get 'default' version of this

@mobiRic
Copy link

mobiRic commented Dec 19, 2016

+1 - much the same use case as @pkuprys

On the server we resize our images into different resolutions for devices to fetch based on screen size. Not all images. However the resizing is not guaranteed for all images, so we would like to fallback to the original image in that case.

@TWiStErRob
Copy link
Collaborator

@pkuprys @bspurgin @mobiRic @eanderso I see how convenient that would be.
See #606 for an example of how it could be done simply with current API in the meantime.

@sjudd sjudd modified the milestones: Next, 4.0 Apr 4, 2017
@sjudd sjudd closed this as completed in b06b0cc Oct 7, 2017
@TWiStErRob
Copy link
Collaborator

@sjudd I'm not entirely sure if this is fixed. Didn't run it, but just looking at the code I can't see how I could do this:

  • load a URL
  • if that URL is null, show an image from some other source (see programme/series/channel example above)
  • if any/all of those URLs fail to load, show an error image via a Glide load (not drawable)

@TWiStErRob TWiStErRob removed this from the Next milestone Oct 7, 2017
@TWiStErRob TWiStErRob added this to the 4.3 milestone Oct 7, 2017
@sjudd
Copy link
Collaborator Author

sjudd commented Oct 8, 2017

I've added an error() method that will let you start an arbitrary new load when a request fails. A request will fail if the model is null or if the load fails for some other reason during the decode process.

I believe the above covers your first and third point. Your second point is covered either by the existing fallback drawable, or by a simpleif (model == null) nullRequest.into(...) else normalRequest.into(...). The additional complexity in the library of trying to treat a normal error and a null model error separately is substantial and almost certainly not worth the effort given how easy it is to just write an if/else statement.

Does that make sense?

@TWiStErRob
Copy link
Collaborator

Ok, thanks, makes sense. Just wanted to clarify it was intentional.

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