Skip to content

Commit

Permalink
Add thumbnail method that takes in a list
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 320059478
  • Loading branch information
sjudd authored and glide-copybara-robot committed Jul 7, 2020
1 parent d84034d commit 67b01f6
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.bumptech.glide.request.RequestListener;
import java.io.File;
import java.net.URL;
import java.util.List;

/**
* Contains all public methods from {@link RequestBuilder<TranscodeType>}, all options from
Expand Down Expand Up @@ -499,6 +500,13 @@ public final GlideRequest<TranscodeType> thumbnail(@Nullable RequestBuilder<Tran
return (GlideRequest<TranscodeType>) super.thumbnail(builders);
}

@Override
@NonNull
@CheckResult
public GlideRequest<TranscodeType> thumbnail(@Nullable List<RequestBuilder<TranscodeType>> list) {
return (GlideRequest<TranscodeType>) super.thumbnail(list);
}

@Override
@NonNull
@CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.bumptech.glide.request.RequestListener;
import java.io.File;
import java.net.URL;
import java.util.List;

/**
* Contains all public methods from {@link RequestBuilder<TranscodeType>}, all options from
Expand Down Expand Up @@ -499,6 +500,13 @@ public final GlideRequest<TranscodeType> thumbnail(@Nullable RequestBuilder<Tran
return (GlideRequest<TranscodeType>) super.thumbnail(builders);
}

@Override
@NonNull
@CheckResult
public GlideRequest<TranscodeType> thumbnail(@Nullable List<RequestBuilder<TranscodeType>> list) {
return (GlideRequest<TranscodeType>) super.thumbnail(list);
}

@Override
@NonNull
@CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.bumptech.glide.request.RequestListener;
import java.io.File;
import java.net.URL;
import java.util.List;

/**
* Contains all public methods from {@link RequestBuilder<TranscodeType>}, all options from
Expand Down Expand Up @@ -490,6 +491,13 @@ public final GlideRequest<TranscodeType> thumbnail(@Nullable RequestBuilder<Tran
return (GlideRequest<TranscodeType>) super.thumbnail(builders);
}

@Override
@NonNull
@CheckResult
public GlideRequest<TranscodeType> thumbnail(@Nullable List<RequestBuilder<TranscodeType>> list) {
return (GlideRequest<TranscodeType>) super.thumbnail(list);
}

@Override
@NonNull
@CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.bumptech.glide.request.RequestListener;
import java.io.File;
import java.net.URL;
import java.util.List;

/**
* Contains all public methods from {@link RequestBuilder<TranscodeType>}, all options from
Expand Down Expand Up @@ -490,6 +491,13 @@ public final GlideRequest<TranscodeType> thumbnail(@Nullable RequestBuilder<Tran
return (GlideRequest<TranscodeType>) super.thumbnail(builders);
}

@Override
@NonNull
@CheckResult
public GlideRequest<TranscodeType> thumbnail(@Nullable List<RequestBuilder<TranscodeType>> list) {
return (GlideRequest<TranscodeType>) super.thumbnail(list);
}

@Override
@NonNull
@CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.bumptech.glide.request.RequestListener;
import java.io.File;
import java.net.URL;
import java.util.List;

/**
* Contains all public methods from {@link RequestBuilder<TranscodeType>}, all options from
Expand Down Expand Up @@ -490,6 +491,13 @@ public final GlideRequest<TranscodeType> thumbnail(@Nullable RequestBuilder<Tran
return (GlideRequest<TranscodeType>) super.thumbnail(builders);
}

@Override
@NonNull
@CheckResult
public GlideRequest<TranscodeType> thumbnail(@Nullable List<RequestBuilder<TranscodeType>> list) {
return (GlideRequest<TranscodeType>) super.thumbnail(list);
}

@Override
@NonNull
@CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.bumptech.glide.request.RequestListener;
import java.io.File;
import java.net.URL;
import java.util.List;

/**
* Contains all public methods from {@link RequestBuilder<TranscodeType>}, all options from
Expand Down Expand Up @@ -499,6 +500,13 @@ public final GlideRequest<TranscodeType> thumbnail(@Nullable RequestBuilder<Tran
return (GlideRequest<TranscodeType>) super.thumbnail(builders);
}

@Override
@NonNull
@CheckResult
public GlideRequest<TranscodeType> thumbnail(@Nullable List<RequestBuilder<TranscodeType>> list) {
return (GlideRequest<TranscodeType>) super.thumbnail(list);
}

@Override
@NonNull
@CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.bumptech.glide.request.RequestListener;
import java.io.File;
import java.net.URL;
import java.util.List;

/**
* Contains all public methods from {@link RequestBuilder<TranscodeType>}, all options from
Expand Down Expand Up @@ -499,6 +500,13 @@ public final GlideRequest<TranscodeType> thumbnail(@Nullable RequestBuilder<Tran
return (GlideRequest<TranscodeType>) super.thumbnail(builders);
}

@Override
@NonNull
@CheckResult
public GlideRequest<TranscodeType> thumbnail(@Nullable List<RequestBuilder<TranscodeType>> list) {
return (GlideRequest<TranscodeType>) super.thumbnail(list);
}

@Override
@NonNull
@CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.bumptech.glide.request.RequestListener;
import java.io.File;
import java.net.URL;
import java.util.List;

/**
* Contains all public methods from {@link RequestBuilder<TranscodeType>}, all options from
Expand Down Expand Up @@ -499,6 +500,13 @@ public final GlideRequest<TranscodeType> thumbnail(@Nullable RequestBuilder<Tran
return (GlideRequest<TranscodeType>) super.thumbnail(builders);
}

@Override
@NonNull
@CheckResult
public GlideRequest<TranscodeType> thumbnail(@Nullable List<RequestBuilder<TranscodeType>> list) {
return (GlideRequest<TranscodeType>) super.thumbnail(list);
}

@Override
@NonNull
@CheckResult
Expand Down
43 changes: 41 additions & 2 deletions library/src/main/java/com/bumptech/glide/RequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Executor;

Expand Down Expand Up @@ -286,14 +287,52 @@ public RequestBuilder<TranscodeType> thumbnail(
return thumbnail((RequestBuilder<TranscodeType>) null);
}

return thumbnail(Arrays.asList(thumbnails));
}

/**
* Recursively applies {@link #thumbnail(RequestBuilder)} so that the {@link RequestBuilder}s are
* loaded as thumbnails in the given priority order.
*
* <p>{@link #thumbnail(RequestBuilder)} is applied in the order given so that the {@link
* RequestBuilder} at position 0 has the {@link RequestBuilder} at position 1 applied as using its
* thumbnail method, the {@link RequestBuilder} at position 1 has the {@link RequestBuilder} at
* position 2 applied using its thumbnail method and so on.
*
* <p>Calling this method with a {@code null} list of {@link RequestBuilder} thumbnails or an
* empty list of {@link RequestBuilder} thumbnails is equivalent to calling {@link
* #thumbnail(RequestBuilder)} with {@code null}.
*
* <p>Any individual {@link RequestBuilder} in the list of thumbnails provided here may be {@code
* null}. {@code null} {@link RequestBuilder}s are ignored and excluded from the recursive chain.
*
* <p>The {@link RequestBuilder} objects provided here may be mutated and have any previous calls
* to this method or {@link #thumbnail(RequestBuilder)} methods overridden.
*
* <p>Overrides any previous calls to {@link #thumbnail(RequestBuilder)}, {@link
* #thumbnail(float)} and this method.
*
* @see #thumbnail(float)
* @see #thumbnail(RequestBuilder)
* @return This request builder.
*/
@SuppressWarnings({"CheckResult", "unchecked"})
@NonNull
@CheckResult
public RequestBuilder<TranscodeType> thumbnail(
@Nullable List<RequestBuilder<TranscodeType>> thumbnails) {
if (thumbnails == null || thumbnails.isEmpty()) {
return thumbnail((RequestBuilder<TranscodeType>) null);
}

RequestBuilder<TranscodeType> previous = null;

// Start with the lowest priority thumbnail so that we can safely handle mutations if
// autoClone() is enabled by assigning the result of calling thumbnail() during the iteration.
// Starting with the highest priority thumbnail would prevent us from assigning the result of
// thumbnail because the mutated request wouldn't be used in the next iteration.
for (int i = thumbnails.length - 1; i >= 0; i--) {
RequestBuilder<TranscodeType> current = thumbnails[i];
for (int i = thumbnails.size() - 1; i >= 0; i--) {
RequestBuilder<TranscodeType> current = thumbnails.get(i);
// Ignore null thumbnails.
if (current == null) {
continue;
Expand Down

0 comments on commit 67b01f6

Please sign in to comment.