diff --git a/Clover/app/src/main/java/org/floens/chan/ui/view/ThumbnailImageView.java b/Clover/app/src/main/java/org/floens/chan/ui/view/ThumbnailImageView.java index b82eb072..323f3828 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/view/ThumbnailImageView.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/view/ThumbnailImageView.java @@ -34,6 +34,7 @@ import com.koushikdutta.async.future.Future; import com.koushikdutta.async.future.FutureCallback; import com.koushikdutta.ion.Ion; import com.koushikdutta.ion.ProgressCallback; +import com.koushikdutta.ion.Response; import org.floens.chan.ChanApplication; import org.floens.chan.R; @@ -139,20 +140,30 @@ public class ThumbnailImageView extends LoadView implements View.OnClickListener } }) .write(file) - .setCallback(new FutureCallback() { + .withResponse() + .setCallback(new FutureCallback>() { @Override - public void onCompleted(Exception e, File result) { - if (e != null || result == null || result.length() == 0) { - if (result != null) { - ChanApplication.getFileCache().delete(result); + public void onCompleted(Exception e, Response result) { + if (result != null && result.getHeaders() != null && result.getHeaders().getResponseCode() / 100 != 2) { + if (result.getResult() != null) { + ChanApplication.getFileCache().delete(result.getResult()); } - if (e != null && !(e instanceof CancellationException)) { - onError(); - e.printStackTrace(); + onNotFoundError(); + return; + } + + if (e != null && !(e instanceof CancellationException)) { + e.printStackTrace(); + if (result != null && result.getResult() != null) { + ChanApplication.getFileCache().delete(result.getResult()); } - } else { - ChanApplication.getFileCache().put(result); - onBigImage(result); + onError(); + return; + } + + if (result != null && result.getResult() != null) { + ChanApplication.getFileCache().put(result.getResult()); + onBigImage(result.getResult()); } } }); @@ -196,20 +207,30 @@ public class ThumbnailImageView extends LoadView implements View.OnClickListener } }) .write(file) - .setCallback(new FutureCallback() { + .withResponse() + .setCallback(new FutureCallback>() { @Override - public void onCompleted(Exception e, File result) { - if (e != null || result == null || result.length() == 0) { - if (result != null) { - ChanApplication.getFileCache().delete(result); + public void onCompleted(Exception e, Response result) { + if (result != null && result.getHeaders() != null && result.getHeaders().getResponseCode() / 100 != 2) { + if (result.getResult() != null) { + ChanApplication.getFileCache().delete(result.getResult()); } - if (e != null && !(e instanceof CancellationException)) { - onError(); - e.printStackTrace(); + onNotFoundError(); + return; + } + + if (e != null && !(e instanceof CancellationException)) { + e.printStackTrace(); + if (result != null && result.getResult() != null) { + ChanApplication.getFileCache().delete(result.getResult()); } - } else { - ChanApplication.getFileCache().put(result); - onGif(result); + onError(); + return; + } + + if (result != null && result.getResult() != null) { + ChanApplication.getFileCache().put(result.getResult()); + onGif(result.getResult()); } } }); @@ -257,20 +278,30 @@ public class ThumbnailImageView extends LoadView implements View.OnClickListener } }) .write(file) - .setCallback(new FutureCallback() { + .withResponse() + .setCallback(new FutureCallback>() { @Override - public void onCompleted(Exception e, File result) { - if (e != null || result == null || result.length() == 0) { - if (result != null) { - ChanApplication.getFileCache().delete(result); + public void onCompleted(Exception e, Response result) { + if (result != null && result.getHeaders() != null && result.getHeaders().getResponseCode() / 100 != 2) { + if (result.getResult() != null) { + ChanApplication.getFileCache().delete(result.getResult()); } - if (e != null && !(e instanceof CancellationException)) { - onError(); - e.printStackTrace(); + onNotFoundError(); + return; + } + + if (e != null && !(e instanceof CancellationException)) { + e.printStackTrace(); + if (result != null && result.getResult() != null) { + ChanApplication.getFileCache().delete(result.getResult()); } - } else { - ChanApplication.getFileCache().put(result); - onVideo(result); + onError(); + return; + } + + if (result != null && result.getResult() != null) { + ChanApplication.getFileCache().put(result.getResult()); + onVideo(result.getResult()); } } }); @@ -319,6 +350,11 @@ public class ThumbnailImageView extends LoadView implements View.OnClickListener callback.setProgress(false); } + public void onNotFoundError() { + Toast.makeText(getContext(), R.string.image_not_found, Toast.LENGTH_LONG).show(); + callback.setProgress(false); + } + public void cancelLoad() { if (imageRequest != null) { imageRequest.cancel(); diff --git a/Clover/app/src/main/res/values/strings.xml b/Clover/app/src/main/res/values/strings.xml index a392e713..cee652ea 100644 --- a/Clover/app/src/main/res/values/strings.xml +++ b/Clover/app/src/main/res/values/strings.xml @@ -61,6 +61,7 @@ along with this program. If not, see . Start / stop playing Failed to show image + Image not found Failed to open image No network