imageviewer: preload the next image

The next image is preloaded by calling the filecache to download the
image beforehand.
Image loading settings are still honored.

Closes #267
refactor-toolbar
Floens 8 years ago
parent d36f263db2
commit c7087209ef
  1. 38
      Clover/app/src/main/java/org/floens/chan/core/presenter/ImageViewerPresenter.java

@ -26,6 +26,7 @@ import org.floens.chan.core.model.PostImage;
import org.floens.chan.core.settings.ChanSettings;
import org.floens.chan.ui.view.MultiImageView;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@ -203,6 +204,43 @@ public class ImageViewerPresenter implements MultiImageView.Callback, ViewPager.
callback.setImageMode(postImage, MultiImageView.Mode.MOVIE);
}
}
preloadNext();
}
// This won't actually change any modes, but it will preload the image so that it's
// available immediately when the user swipes right.
private void preloadNext() {
if (selectedPosition + 1 < images.size()) {
PostImage next = images.get(selectedPosition + 1);
boolean load = false;
if (next.type == PostImage.Type.STATIC || next.type == PostImage.Type.GIF) {
load = imageAutoLoad(next);
} else if (next.type == PostImage.Type.MOVIE) {
load = videoAutoLoad(next);
}
if (load) {
final FileCache.DownloadedCallback emptyCallback =
new FileCache.DownloadedCallback() {
@Override
public void onProgress(long downloaded, long total, boolean done) {
}
@Override
public void onSuccess(File file) {
}
@Override
public void onFail(boolean notFound) {
}
};
final String fileUrl = next.imageUrl.toString();
fileCache.downloadFile(fileUrl, emptyCallback);
}
}
}
@Override

Loading…
Cancel
Save