mirror of
https://github.com/moparisthebest/Conversations
synced 2024-12-25 00:48:52 -05:00
add timeouts to HTTPUrlConnections and allow cancelation of all sending files
This commit is contained in:
parent
de7c0c5121
commit
61f58b3dbd
@ -212,6 +212,8 @@ public class HttpDownloadConnection implements Transferable {
|
||||
if (connection instanceof HttpsURLConnection) {
|
||||
mHttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, interactive);
|
||||
}
|
||||
connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000);
|
||||
connection.setReadTimeout(Config.SOCKET_TIMEOUT * 1000);
|
||||
connection.connect();
|
||||
String contentLength = connection.getHeaderField("Content-Length");
|
||||
connection.disconnect();
|
||||
@ -279,6 +281,8 @@ public class HttpDownloadConnection implements Transferable {
|
||||
long size = file.getSize();
|
||||
connection.setRequestProperty("Range", "bytes="+size+"-");
|
||||
}
|
||||
connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000);
|
||||
connection.setReadTimeout(Config.SOCKET_TIMEOUT * 1000);
|
||||
connection.connect();
|
||||
is = new BufferedInputStream(connection.getInputStream());
|
||||
boolean serverResumed = "bytes".equals(connection.getHeaderField("Accept-Ranges"));
|
||||
|
@ -171,10 +171,12 @@ public class HttpUploadConnection implements Transferable {
|
||||
connection.setRequestProperty("Content-Type", mime == null ? "application/octet-stream" : mime);
|
||||
connection.setRequestProperty("User-Agent",mXmppConnectionService.getIqGenerator().getIdentityName());
|
||||
connection.setDoOutput(true);
|
||||
connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000);
|
||||
connection.setReadTimeout(Config.SOCKET_TIMEOUT * 1000);
|
||||
connection.connect();
|
||||
os = connection.getOutputStream();
|
||||
transmitted = 0;
|
||||
int count = -1;
|
||||
int count;
|
||||
byte[] buffer = new byte[4096];
|
||||
while (((count = mFileInputStream.read(buffer)) != -1) && !canceled) {
|
||||
transmitted += count;
|
||||
|
@ -573,9 +573,10 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|
||||
downloadFile.setVisible(true);
|
||||
downloadFile.setTitle(activity.getString(R.string.download_x_file,UIHelper.getFileDescriptionString(activity, m)));
|
||||
}
|
||||
if ((t != null && !(t instanceof TransferablePlaceholder))
|
||||
|| (m.isFileOrImage() && (m.getStatus() == Message.STATUS_WAITING
|
||||
|| m.getStatus() == Message.STATUS_OFFERED))) {
|
||||
boolean waitingOfferedSending = m.getStatus() == Message.STATUS_WAITING
|
||||
|| m.getStatus() == Message.STATUS_UNSEND
|
||||
|| m.getStatus() == Message.STATUS_OFFERED;
|
||||
if ((t != null && !(t instanceof TransferablePlaceholder)) || waitingOfferedSending && m.needsUploading()) {
|
||||
cancelTransmission.setVisible(true);
|
||||
}
|
||||
if (treatAsFile) {
|
||||
|
Loading…
Reference in New Issue
Block a user