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(); execute();
} catch (InterruptedIOException | InterruptedException e) { } catch (InterruptedIOException | InterruptedException e) {
cancelDueToCancellation(e); cancelDueToCancellation(e);
return;
} catch (Exception e) { } catch (Exception e) {
cancelDueToException(e); cancelDueToException(e);
return; } finally {
finish();
} }
finish();
success();
} }
private void cancelDueToException(Exception e) { private void cancelDueToException(Exception e) {
@ -178,7 +175,6 @@ public class FileCache {
Log.w(TAG, "IOException downloading file", e); Log.w(TAG, "IOException downloading file", e);
purgeOutput(); purgeOutput();
finish();
post(new Runnable() { post(new Runnable() {
@Override @Override
@ -196,7 +192,6 @@ public class FileCache {
Log.w(TAG, "Cancel due to http error, code: " + code); Log.w(TAG, "Cancel due to http error, code: " + code);
purgeOutput(); purgeOutput();
finish();
post(new Runnable() { post(new Runnable() {
@Override @Override
@ -214,21 +209,35 @@ public class FileCache {
Log.d(TAG, "Cancel due to cancellation"); Log.d(TAG, "Cancel due to cancellation");
purgeOutput(); purgeOutput();
finish();
// No callback // 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() { private void finish() {
Util.closeQuietly(downloadInput); Util.closeQuietly(downloadInput);
Util.closeQuietly(downloadOutput); Util.closeQuietly(downloadOutput);
if (call != null) { if (call != null) {
call.cancel(); call.cancel();
call = null;
} }
if (body != null) { if (body != null) {
Util.closeQuietly(body); Util.closeQuietly(body);
body = null;
} }
} }
@ -257,18 +266,6 @@ public class FileCache {
post(progressRunnable); 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) { private void post(Runnable runnable) {
Utils.runOnUiThread(runnable); Utils.runOnUiThread(runnable);
} }
@ -303,9 +300,11 @@ public class FileCache {
totalLast = total; totalLast = total;
progress(total, contentLength, false); progress(total, contentLength, false);
} }
if (Thread.currentThread().isInterrupted()) throw new InterruptedIOException();
} }
if (Thread.currentThread().isInterrupted()) throw new InterruptedIOException();
success();
} }
} }
} }

Loading…
Cancel
Save