From 21a5b4ba681390dbbb3202355ed51afc8fc53e08 Mon Sep 17 00:00:00 2001 From: Floens Date: Fri, 6 Feb 2015 13:03:56 +0100 Subject: [PATCH] Fix some image loading issues. --- .../java/org/floens/chan/utils/FileCache.java | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/Clover/app/src/main/java/org/floens/chan/utils/FileCache.java b/Clover/app/src/main/java/org/floens/chan/utils/FileCache.java index 433ff2de..7e4c00be 100644 --- a/Clover/app/src/main/java/org/floens/chan/utils/FileCache.java +++ b/Clover/app/src/main/java/org/floens/chan/utils/FileCache.java @@ -161,14 +161,11 @@ public class FileCache { execute(); } catch (InterruptedIOException | InterruptedException e) { cancelDueToCancellation(e); - return; } catch (Exception e) { cancelDueToException(e); - return; + } finally { + finish(); } - - finish(); - success(); } private void cancelDueToException(Exception e) { @@ -178,7 +175,6 @@ public class FileCache { Log.w(TAG, "IOException downloading file", e); purgeOutput(); - finish(); post(new Runnable() { @Override @@ -196,7 +192,6 @@ public class FileCache { Log.w(TAG, "Cancel due to http error, code: " + code); purgeOutput(); - finish(); post(new Runnable() { @Override @@ -214,21 +209,35 @@ public class FileCache { Log.d(TAG, "Cancel due to cancellation"); purgeOutput(); - finish(); // No callback } + private void success() { + fileCache.put(output); + + post(new Runnable() { + @Override + public void run() { + callback.onProgress(0, 0, true); + callback.onSuccess(output); + } + }); + call = null; + } + private void finish() { Util.closeQuietly(downloadInput); Util.closeQuietly(downloadOutput); if (call != null) { call.cancel(); + call = null; } if (body != null) { Util.closeQuietly(body); + body = null; } } @@ -257,18 +266,6 @@ public class FileCache { post(progressRunnable); } - private void success() { - fileCache.put(output); - - post(new Runnable() { - @Override - public void run() { - callback.onProgress(0, 0, true); - callback.onSuccess(output); - } - }); - } - private void post(Runnable runnable) { Utils.runOnUiThread(runnable); } @@ -303,9 +300,11 @@ public class FileCache { totalLast = total; progress(total, contentLength, false); } - - if (Thread.currentThread().isInterrupted()) throw new InterruptedIOException(); } + + if (Thread.currentThread().isInterrupted()) throw new InterruptedIOException(); + + success(); } } }