Fix some image loading issues.

captchafix2
Floens 11 years ago
parent 1de9ee42cf
commit 21a5b4ba68
  1. 43
      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();
}
}
}

Loading…
Cancel
Save