Fix issue where the notification stays up for the album downloader.

postFinished wasn't called if the destination already existed.
Changed IOUtils.copy to IOUtils.copyFile.

Closes #250
multisite^2
Floens 8 years ago
parent f0c38ff433
commit 8e11f039a9
  1. 16
      Clover/app/src/main/java/org/floens/chan/core/saver/ImageSaveTask.java

@ -31,11 +31,7 @@ import org.floens.chan.utils.ImageDecoder;
import org.floens.chan.utils.Logger; import org.floens.chan.utils.Logger;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import static org.floens.chan.utils.AndroidUtils.dp; import static org.floens.chan.utils.AndroidUtils.dp;
import static org.floens.chan.utils.AndroidUtils.getAppContext; import static org.floens.chan.utils.AndroidUtils.getAppContext;
@ -111,7 +107,10 @@ public class ImageSaveTask implements Runnable, FileCache.DownloadedCallback {
try { try {
if (destination.exists()) { if (destination.exists()) {
onDestination(); onDestination();
// Manually call postFinished()
postFinished(success);
} else { } else {
// Both onSuccess and onFail call postFinished()
FileCache.FileCacheDownloader fileCacheDownloader = Chan.getFileCache().downloadFile(postImage.imageUrl, this); FileCache.FileCacheDownloader fileCacheDownloader = Chan.getFileCache().downloadFile(postImage.imageUrl, this);
// If the fileCacheDownloader is null then the destination already existed and onSuccess() has been called. // If the fileCacheDownloader is null then the destination already existed and onSuccess() has been called.
// Wait otherwise for the download to finish to avoid that the next task is immediately executed. // Wait otherwise for the download to finish to avoid that the next task is immediately executed.
@ -169,8 +168,6 @@ public class ImageSaveTask implements Runnable, FileCache.DownloadedCallback {
private boolean copyToDestination(File source) { private boolean copyToDestination(File source) {
boolean result = false; boolean result = false;
InputStream is = null;
OutputStream os = null;
try { try {
File parent = destination.getParentFile(); File parent = destination.getParentFile();
if (!parent.mkdirs() && !parent.isDirectory()) { if (!parent.mkdirs() && !parent.isDirectory()) {
@ -181,16 +178,11 @@ public class ImageSaveTask implements Runnable, FileCache.DownloadedCallback {
throw new IOException("Destination file is already a directory"); throw new IOException("Destination file is already a directory");
} }
is = new FileInputStream(source); IOUtils.copyFile(source, destination);
os = new FileOutputStream(destination);
IOUtils.copy(is, os);
result = true; result = true;
} catch (IOException e) { } catch (IOException e) {
Logger.e(TAG, "Error writing to file", e); Logger.e(TAG, "Error writing to file", e);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
} }
return result; return result;

Loading…
Cancel
Save