diff --git a/library/src/com/bumptech/glide/ListPreloader.java b/library/src/com/bumptech/glide/ListPreloader.java index faa69ffd7218e41640c4e151d991efde25b81dad..2878bb9ac156cf7c8fc5665b9f2f334d68536d83 100644 --- a/library/src/com/bumptech/glide/ListPreloader.java +++ b/library/src/com/bumptech/glide/ListPreloader.java @@ -6,6 +6,7 @@ import android.graphics.Bitmap; import android.os.Build; import android.widget.AbsListView; import com.bumptech.glide.presenter.target.SimpleTarget; +import com.bumptech.glide.util.Log; import java.util.ArrayDeque; import java.util.LinkedList; @@ -37,7 +38,7 @@ public abstract class ListPreloader implements AbsListView.OnScrollListener { private boolean isIncreasing = true; /** - * Create the preloader. + * Constructor for the preloader. * * @param context A context * @param maxPreload The maximum number of items in the list to load ahead (corresponds to adapter positions). @@ -63,18 +64,18 @@ public abstract class ListPreloader implements AbsListView.OnScrollListener { } /** - * Get the dimensions of the view in the list where the images will be displayed. + * Returns the dimensions of the view in the list where the images will be displayed. *

* Note - The dimensions returned here must precisely match those of the view in the list. *

* @param item A model * @return The dimensions of the view where the item will be displayed */ - protected abstract int[] getDimens(T item); + protected abstract int[] getDimensions(T item); /** - * Get a list of all models that need to be loaded for the list to display adapter items start - end. A list of any - * size can be returned so there can be multiple models per adapter position. + * Returns a list of all models that need to be loaded for the list to display adapter items start - end. A list of + * any size can be returned so there can be multiple models per adapter position. * * @param start The smallest adapter position. Will be >= 0 && < adapter.getCount() && <= end * @param end The largest adapter position. Will be >= 0 && < adapter.getCount && >= start @@ -83,7 +84,7 @@ public abstract class ListPreloader implements AbsListView.OnScrollListener { protected abstract List getItems(int start, int end); /** - * Get a glide request for a given item. Must exactly match the request used to load the image in the list. The + * Returns a glide request for a given item. Must exactly match the request used to load the image in the list. The * target and context will be provided by the preloader. * * @param item The model to load. @@ -113,15 +114,16 @@ public abstract class ListPreloader implements AbsListView.OnScrollListener { start = Math.min(totalItemCount, Math.max(0, start)); List items = getItems(start, end); - // Increasing if (from < to) { + // Increasing final int numItems = items.size(); for (int i = 0; i < numItems; i++) { - preload(items, i); + preloadItem(items, i); } } else { + // Decreasing for (int i = items.size() - 1; i >= 0; i--) { - preload(items, i); + preloadItem(items, i); } } @@ -129,11 +131,11 @@ public abstract class ListPreloader implements AbsListView.OnScrollListener { lastEnd = end; } - private void preload(List items, int position) { + private void preloadItem(List items, int position) { final T item = items.get(position); - final int[] dimens = getDimens(item); - if (dimens != null) { - getRequest(item).into(preloadTargetQueue.next(dimens[0], dimens[1])).with(context); + final int[] dimensions = getDimensions(item); + if (dimensions != null) { + getRequest(item).into(preloadTargetQueue.next(dimensions[0], dimensions[1])).with(context); } } diff --git a/samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java b/samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java index 9ce5e47bbc6734ae75af221b75b722eb4458cd6d..33e95b77ef3a054ac8516ef429f0cfab37b6c634 100644 --- a/samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java +++ b/samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java @@ -75,7 +75,7 @@ public class FlickrPhotoGrid extends SherlockFragment implements PhotoViewer { } @Override - protected int[] getDimens(Photo item) { + protected int[] getDimensions(Photo item) { return dimens; } diff --git a/samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrPhotoList.java b/samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrPhotoList.java index 7d49d7e485a74fff24c3a379ef5ab38859594678..d9132ce3aafaafa5ccc4253f9acb3084d7ad37c4 100644 --- a/samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrPhotoList.java +++ b/samples/flickr/src/com/bumptech/glide/samples/flickr/FlickrPhotoList.java @@ -84,7 +84,7 @@ public class FlickrPhotoList extends SherlockFragment implements PhotoViewer { } @Override - protected int[] getDimens(Photo item) { + protected int[] getDimensions(Photo item) { return photoDimens; }