提交 78ca8506 编写于 作者: S Sam Judd 提交者: Sam Judd

cancel preloads when changing directions

上级 a6740390
......@@ -22,6 +22,8 @@ public abstract class ListPreloader<T> implements AbsListView.OnScrollListener {
private int lastFirstVisible;
private int totalItemCount;
private boolean isIncreasing = true;
public ListPreloader(Context context, int maxPreload) {
this.context = context;
this.maxPreload = maxPreload;
......@@ -49,6 +51,10 @@ public abstract class ListPreloader<T> implements AbsListView.OnScrollListener {
protected abstract Glide.Request<T> getRequest(T item);
public void preload(int start, boolean increasing) {
if (isIncreasing != increasing) {
isIncreasing = increasing;
cancelAll();
}
preload(start, start + (increasing ? maxPreload : -maxPreload));
}
......@@ -88,6 +94,12 @@ public abstract class ListPreloader<T> implements AbsListView.OnScrollListener {
getRequest(item).into(preloadTargetQueue.next(dimens[0], dimens[1])).with(context);
}
private void cancelAll() {
for (int i = 0; i < maxPreload; i++) {
Glide.cancel(preloadTargetQueue.next(0, 0));
}
}
private static class PreloadTargetQueue {
private final Queue<PreloadTarget> queue;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册