It would be cool if passing null url would use placeholder drawable or error drawable if set. Right now it defeats the purpose of fluent api when you have to do something like:
if (imageUrl != null) {
it.load(imageUrl) {
placeholder(placeholderRes)
}
}
else {
it.setImageResource(placeholderRes)
}
To help design this, if you run:
imageView.load(null) {
placeholder(R.drawable.placeholder)
error(R.drawable.error)
}
Would you expect it to show the placeholder drawable or the error drawable?
To me it would make more sense to use error when defined, and placehold as a fallback. Same goes for the case where you do have an url and there's an error.
I saw multiple points of view about this topic. Some people think that null is a valid case and should show nothing. Maybe it makes more sense to define your own null strategy.
imageView.load(itemModel.imageUrl) {
placeholder(R.drawable.ic_placeholder)
error(R.drawable.ic_error)
isNull(R.drawable.ic_null)
}
or
imageView.load(itemModel.imageUrl) {
placeholder(R.drawable.ic_placeholder)
error(R.drawable.ic_error)
isNull(null)
}
Related topic in glide a few years ago:
https://github.com/bumptech/glide/issues/268
@mlilienberg Great point. I think it makes sense to use the same API as Glide. i.e.:
imageView.load(itemModel.imageUrl) {
placeholder(R.drawable.ic_placeholder)
error(R.drawable.ic_error)
fallback(R.drawable.ic_error)
}
Similar to placeholder and error, you should be able to set the default fallback on your ImageLoader.
This is now supported in master. To get the fix asap you can depend on 0.9.0-SNAPSHOT.
NOTE: There might be minor behaviour changes to the feature before 0.9.0 stable.
Most helpful comment
@mlilienberg Great point. I think it makes sense to use the same API as Glide. i.e.:
Similar to
placeholderanderror, you should be able to set the defaultfallbackon yourImageLoader.