Proper 404 handling

captchafix
Florens Douwes 11 years ago
parent 3020275725
commit 4515a04543
  1. 102
      Clover/app/src/main/java/org/floens/chan/ui/view/ThumbnailImageView.java
  2. 1
      Clover/app/src/main/res/values/strings.xml

@ -34,6 +34,7 @@ import com.koushikdutta.async.future.Future;
import com.koushikdutta.async.future.FutureCallback; import com.koushikdutta.async.future.FutureCallback;
import com.koushikdutta.ion.Ion; import com.koushikdutta.ion.Ion;
import com.koushikdutta.ion.ProgressCallback; import com.koushikdutta.ion.ProgressCallback;
import com.koushikdutta.ion.Response;
import org.floens.chan.ChanApplication; import org.floens.chan.ChanApplication;
import org.floens.chan.R; import org.floens.chan.R;
@ -139,20 +140,30 @@ public class ThumbnailImageView extends LoadView implements View.OnClickListener
} }
}) })
.write(file) .write(file)
.setCallback(new FutureCallback<File>() { .withResponse()
.setCallback(new FutureCallback<Response<File>>() {
@Override @Override
public void onCompleted(Exception e, File result) { public void onCompleted(Exception e, Response<File> result) {
if (e != null || result == null || result.length() == 0) { if (result != null && result.getHeaders() != null && result.getHeaders().getResponseCode() / 100 != 2) {
if (result != null) { if (result.getResult() != null) {
ChanApplication.getFileCache().delete(result); ChanApplication.getFileCache().delete(result.getResult());
} }
if (e != null && !(e instanceof CancellationException)) { onNotFoundError();
onError(); return;
e.printStackTrace(); }
if (e != null && !(e instanceof CancellationException)) {
e.printStackTrace();
if (result != null && result.getResult() != null) {
ChanApplication.getFileCache().delete(result.getResult());
} }
} else { onError();
ChanApplication.getFileCache().put(result); return;
onBigImage(result); }
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) .write(file)
.setCallback(new FutureCallback<File>() { .withResponse()
.setCallback(new FutureCallback<Response<File>>() {
@Override @Override
public void onCompleted(Exception e, File result) { public void onCompleted(Exception e, Response<File> result) {
if (e != null || result == null || result.length() == 0) { if (result != null && result.getHeaders() != null && result.getHeaders().getResponseCode() / 100 != 2) {
if (result != null) { if (result.getResult() != null) {
ChanApplication.getFileCache().delete(result); ChanApplication.getFileCache().delete(result.getResult());
} }
if (e != null && !(e instanceof CancellationException)) { onNotFoundError();
onError(); return;
e.printStackTrace(); }
if (e != null && !(e instanceof CancellationException)) {
e.printStackTrace();
if (result != null && result.getResult() != null) {
ChanApplication.getFileCache().delete(result.getResult());
} }
} else { onError();
ChanApplication.getFileCache().put(result); return;
onGif(result); }
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) .write(file)
.setCallback(new FutureCallback<File>() { .withResponse()
.setCallback(new FutureCallback<Response<File>>() {
@Override @Override
public void onCompleted(Exception e, File result) { public void onCompleted(Exception e, Response<File> result) {
if (e != null || result == null || result.length() == 0) { if (result != null && result.getHeaders() != null && result.getHeaders().getResponseCode() / 100 != 2) {
if (result != null) { if (result.getResult() != null) {
ChanApplication.getFileCache().delete(result); ChanApplication.getFileCache().delete(result.getResult());
} }
if (e != null && !(e instanceof CancellationException)) { onNotFoundError();
onError(); return;
e.printStackTrace(); }
if (e != null && !(e instanceof CancellationException)) {
e.printStackTrace();
if (result != null && result.getResult() != null) {
ChanApplication.getFileCache().delete(result.getResult());
} }
} else { onError();
ChanApplication.getFileCache().put(result); return;
onVideo(result); }
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); callback.setProgress(false);
} }
public void onNotFoundError() {
Toast.makeText(getContext(), R.string.image_not_found, Toast.LENGTH_LONG).show();
callback.setProgress(false);
}
public void cancelLoad() { public void cancelLoad() {
if (imageRequest != null) { if (imageRequest != null) {
imageRequest.cancel(); imageRequest.cancel();

@ -61,6 +61,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<string name="image_play_state">Start / stop playing</string> <string name="image_play_state">Start / stop playing</string>
<string name="image_preview_failed">Failed to show image</string> <string name="image_preview_failed">Failed to show image</string>
<string name="image_not_found">Image not found</string>
<string name="image_open_failed">Failed to open image</string> <string name="image_open_failed">Failed to open image</string>
<string name="thread_load_failed_network">No network</string> <string name="thread_load_failed_network">No network</string>

Loading…
Cancel
Save