modelClass,
@@ -559,6 +558,28 @@ public GenericRequestBuilder l
return this;
}
+ /**
+ * Returns a copy of this request builder with all of the options set so far on this builder.
+ *
+ *
+ * This method returns a "deep" copy in that all non-immutable arguments are copied such that changes to one
+ * builder will not affect the other builder. However, in addition to immutable arguments, the current model
+ * is not copied copied so changes to the model will affect both builders.
+ *
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public GenericRequestBuilder clone() {
+ try {
+ GenericRequestBuilder clone =
+ (GenericRequestBuilder) super.clone();
+ clone.loadProvider = loadProvider != null ? loadProvider.clone() : null;
+ return clone;
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
/**
* Set the target the resource will be loaded into.
*
@@ -729,7 +750,7 @@ private Request buildRequestRecursive(Target target, ThumbnailReq
}
}
- private Request obtainRequest(Target target, float sizeMultiplier, Priority priority,
+ private Request obtainRequest(Target target, float sizeMultiplier, Priority priority,
RequestCoordinator requestCoordinator) {
return GenericRequest.obtain(
loadProvider,
diff --git a/library/src/main/java/com/bumptech/glide/GifRequestBuilder.java b/library/src/main/java/com/bumptech/glide/GifRequestBuilder.java
index 5e63549de5..ffde6fe1d7 100644
--- a/library/src/main/java/com/bumptech/glide/GifRequestBuilder.java
+++ b/library/src/main/java/com/bumptech/glide/GifRequestBuilder.java
@@ -403,6 +403,11 @@ public GifRequestBuilder load(ModelType model) {
return this;
}
+ @Override
+ public GifRequestBuilder clone() {
+ return (GifRequestBuilder) super.clone();
+ }
+
@Override
void applyFitCenter() {
fitCenter();
diff --git a/library/src/main/java/com/bumptech/glide/provider/ChildLoadProvider.java b/library/src/main/java/com/bumptech/glide/provider/ChildLoadProvider.java
index ee07f74cec..5478eab210 100644
--- a/library/src/main/java/com/bumptech/glide/provider/ChildLoadProvider.java
+++ b/library/src/main/java/com/bumptech/glide/provider/ChildLoadProvider.java
@@ -17,7 +17,7 @@
* @param The type of the resource that will be decoded from the data.
* @param The type of the resource that will be transcoded from the decoded resource.
*/
-public class ChildLoadProvider implements LoadProvider {
+public class ChildLoadProvider implements LoadProvider, Cloneable {
private final LoadProvider parent;
private ResourceDecoder cacheDecoder;
@@ -141,4 +141,14 @@ public ResourceTranscoder getTranscoder() {
return parent.getTranscoder();
}
}
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public ChildLoadProvider clone() {
+ try {
+ return (ChildLoadProvider) super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
diff --git a/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java b/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
index 4f97391387..12a676f028 100644
--- a/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
+++ b/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
@@ -8,7 +8,6 @@
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
-
import com.bumptech.glide.DrawableRequestBuilder;
import com.bumptech.glide.GenericRequestBuilder;
import com.bumptech.glide.Glide;
@@ -64,14 +63,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
thumbnailRequest = Glide.with(this)
.from(Photo.class)
- .priority(Priority.HIGH)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.override(Api.SQUARE_THUMB_SIZE, Api.SQUARE_THUMB_SIZE);
- preloadRequest = thumbnail ? thumbnailRequest : Glide.with(this)
- .from(Photo.class)
- .priority(Priority.HIGH)
- .centerCrop();
+ preloadRequest = thumbnail ? thumbnailRequest.clone().priority(Priority.HIGH) : fullRequest;
final View result = inflater.inflate(R.layout.flickr_photo_grid, container, false);
grid = (GridView) result.findViewById(R.id.images);
diff --git a/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoList.java b/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoList.java
index 19537c98ac..2627f6602f 100644
--- a/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoList.java
+++ b/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoList.java
@@ -11,12 +11,10 @@
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
-
import com.bumptech.glide.DrawableRequestBuilder;
import com.bumptech.glide.GenericRequestBuilder;
import com.bumptech.glide.Glide;
import com.bumptech.glide.ListPreloader;
-import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.samples.flickr.api.Api;
import com.bumptech.glide.samples.flickr.api.Photo;
@@ -36,7 +34,6 @@ public class FlickrPhotoList extends Fragment implements PhotoViewer {
private ListView list;
private DrawableRequestBuilder fullRequest;
private DrawableRequestBuilder thumbRequest;
- private DrawableRequestBuilder preloadRequest;
public static FlickrPhotoList newInstance() {
return new FlickrPhotoList();
@@ -67,18 +64,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
.placeholder(new ColorDrawable(Color.GRAY))
.centerCrop();
- preloadRequest = Glide.with(FlickrPhotoList.this)
- .from(Photo.class)
- .placeholder(new ColorDrawable(Color.GRAY))
- .centerCrop()
- .priority(Priority.HIGH);
-
thumbRequest = Glide.with(FlickrPhotoList.this)
.from(Photo.class)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.override(Api.SQUARE_THUMB_SIZE, Api.SQUARE_THUMB_SIZE);
-
if (savedInstanceState != null) {
int index = savedInstanceState.getInt(STATE_POSITION_INDEX);
int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET);
@@ -139,7 +129,7 @@ protected List getItems(int start, int end) {
@Override
protected GenericRequestBuilder getRequestBuilder(Photo item) {
- return preloadRequest
+ return fullRequest
.thumbnail(thumbRequest.load(item))
.load(item);
}
diff --git a/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/MainActivity.java b/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/MainActivity.java
index 6f5fd6421c..e8b25e716e 100644
--- a/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/MainActivity.java
+++ b/samples/giphy/src/main/java/com/bumptech/glide/samples/giphy/MainActivity.java
@@ -12,7 +12,6 @@
import com.bumptech.glide.GenericRequestBuilder;
import com.bumptech.glide.Glide;
import com.bumptech.glide.ListPreloader;
-import com.bumptech.glide.Priority;
import java.io.InputStream;
import java.util.ArrayList;
@@ -25,7 +24,7 @@ public class MainActivity extends Activity implements Api.Monitor {
private static final String TAG = "GiphyActivity";
private GifAdapter adapter;
- private DrawableRequestBuilder preloadRequest;
+ private DrawableRequestBuilder fullRequest;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -44,15 +43,10 @@ protected void onCreate(Bundle savedInstanceState) {
ListView gifList = (ListView) findViewById(R.id.gif_list);
GiphyPreloader preloader = new GiphyPreloader(2);
- DrawableRequestBuilder fullRequest = Glide.with(this)
+ fullRequest = Glide.with(this)
.from(Api.GifResult.class)
.fitCenter();
- preloadRequest = Glide.with(this)
- .from(Api.GifResult.class)
- .fitCenter()
- .priority(Priority.HIGH);
-
adapter = new GifAdapter(this, preloader, fullRequest);
gifList.setAdapter(adapter);
gifList.setOnScrollListener(preloader);
@@ -99,7 +93,7 @@ protected List getItems(int start, int end) {
@Override
protected GenericRequestBuilder getRequestBuilder(Api.GifResult item) {
- return preloadRequest.load(item);
+ return fullRequest.load(item);
}
}