bumptech / glide

An image loading and caching library for Android focused on smooth scrolling
https://bumptech.github.io/glide/
Other
34.56k stars 6.11k forks source link

Add API to avoid having to pass in arguments to every load for custom types. #189

Closed sjudd closed 7 years ago

sjudd commented 9 years ago

See the discussion here for more context: https://github.com/sjudd/glide/commit/b59798a19396c930a685d2b0cae7d7e66cb9dded#samples-svg-src-main-java-com-bumptech-svgsample-app-mainactivity-java-P58

sjudd commented 9 years ago

So one way this could work would be to allow either the decodes/encoders (Modules?) to be specified first or the model to be specified first, with options in between the two, or after both are set:

Such an API might look something like this:

Glide.with(fragment).module(BitmapModule.class).error(...).placeholder(...).from(Uri.class);
Glide.with(fragment).from(Uri.class).error(...).placeholder(...).module(BitmapModule.class);

Where

Glide.with(fragment).from(Uri.class)

returns

GenericRequestBuilder<Uri, ?, ?, ?>

and

Glide.with(fragment).module(BitmapModule.class)

returns

BitmapTypeRequest<?, ImageVideoWrapper, Bitmap, Bitmap>

So

Glide.with(fragment).from(Uri.class).module(BitmapModule.class)

returns

BitmapTypeRequest<Uri, ImageVideoWrapper, Bitmap, Bitmap>

and

Glide.with(fragment).module(BitmapModule.class).from(Uri.class)

also returns

BitmapTypeRequest<Uri, ImageVideoWrapper, Bitmap, Bitmap>

It's flexible, but it's also pretty complicated, particularly because some options would have to be unavailable before the model and/or module is set.

TWiStErRob commented 9 years ago

Yep, that looks about right.

Its esentially a DSL where you have paths to go on. It's like having "select * from Table where ..." as well as "from Table where ... select *". It may worth to first sketch up a railroad first to clearly see what is the target. Once we have something we could find other use cases which may simplify or complicate things :)

some options would have to be unavailable

That should be taken care of by the compiler. Having a method with ? as it's argument type is not callable as far as I know:

void f(Collection<? extends Integer> l) {
  l.add(5); // see signature of add here
}
sjudd commented 7 years ago

I think this is mostly obsolete from the 4.0 API, especially with the generated API on top of it.