do not display toast for cancelled downloads
This commit is contained in:
parent
aaac8296b3
commit
38ef69a926
|
@ -211,14 +211,19 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
mHttpConnectionManager.updateConversationUi(true);
|
mHttpConnectionManager.updateConversationUi(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showToastForException(Exception e) {
|
private void showToastForException(final Exception e) {
|
||||||
|
final Call call = mostRecentCall;
|
||||||
|
final boolean cancelled = call != null && call.isCanceled();
|
||||||
|
if (e == null || cancelled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (e instanceof java.net.UnknownHostException) {
|
if (e instanceof java.net.UnknownHostException) {
|
||||||
mXmppConnectionService.showErrorToastInUi(R.string.download_failed_server_not_found);
|
mXmppConnectionService.showErrorToastInUi(R.string.download_failed_server_not_found);
|
||||||
} else if (e instanceof java.net.ConnectException) {
|
} else if (e instanceof java.net.ConnectException) {
|
||||||
mXmppConnectionService.showErrorToastInUi(R.string.download_failed_could_not_connect);
|
mXmppConnectionService.showErrorToastInUi(R.string.download_failed_could_not_connect);
|
||||||
} else if (e instanceof FileWriterException) {
|
} else if (e instanceof FileWriterException) {
|
||||||
mXmppConnectionService.showErrorToastInUi(R.string.download_failed_could_not_write_file);
|
mXmppConnectionService.showErrorToastInUi(R.string.download_failed_could_not_write_file);
|
||||||
} else if (!(e instanceof CancellationException)) {
|
} else {
|
||||||
mXmppConnectionService.showErrorToastInUi(R.string.download_failed_file_not_found);
|
mXmppConnectionService.showErrorToastInUi(R.string.download_failed_file_not_found);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,9 +273,7 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
private void retrieveFailed(@Nullable Exception e) {
|
private void retrieveFailed(@Nullable Exception e) {
|
||||||
changeStatus(STATUS_OFFER_CHECK_FILESIZE);
|
changeStatus(STATUS_OFFER_CHECK_FILESIZE);
|
||||||
if (interactive) {
|
if (interactive) {
|
||||||
if (e != null) {
|
|
||||||
showToastForException(e);
|
showToastForException(e);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
HttpDownloadConnection.this.acceptedAutomatically = false;
|
HttpDownloadConnection.this.acceptedAutomatically = false;
|
||||||
HttpDownloadConnection.this.mXmppConnectionService.getNotificationService().push(message);
|
HttpDownloadConnection.this.mXmppConnectionService.getNotificationService().push(message);
|
||||||
|
@ -362,8 +365,7 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
} catch (final SSLHandshakeException e) {
|
} catch (final SSLHandshakeException e) {
|
||||||
changeStatus(STATUS_OFFER);
|
changeStatus(STATUS_OFFER);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
Log.d(Config.LOGTAG,"problem downloading",e);
|
Log.d(Config.LOGTAG, message.getConversation().getAccount().getJid().asBareJid() + ": unable to download file", e);
|
||||||
//TODO do not show toast for cancelled stuff
|
|
||||||
if (interactive) {
|
if (interactive) {
|
||||||
showToastForException(e);
|
showToastForException(e);
|
||||||
} else {
|
} else {
|
||||||
|
@ -421,7 +423,7 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
outputStream = AbstractConnectionManager.createOutputStream(file, false, false);
|
outputStream = AbstractConnectionManager.createOutputStream(file, false, false);
|
||||||
}
|
}
|
||||||
int count;
|
int count;
|
||||||
byte[] buffer = new byte[4096];
|
final byte[] buffer = new byte[4096];
|
||||||
while ((count = inputStream.read(buffer)) != -1) {
|
while ((count = inputStream.read(buffer)) != -1) {
|
||||||
transmitted += count;
|
transmitted += count;
|
||||||
try {
|
try {
|
||||||
|
@ -430,9 +432,6 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
throw new FileWriterException();
|
throw new FileWriterException();
|
||||||
}
|
}
|
||||||
updateProgress(Math.round(((double) transmitted / expected) * 100));
|
updateProgress(Math.round(((double) transmitted / expected) * 100));
|
||||||
if (canceled) {
|
|
||||||
throw new CancellationException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
outputStream.flush();
|
outputStream.flush();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue