automatically start download if file size is known
This commit is contained in:
parent
ee3438b03a
commit
af420c84a0
|
@ -48,7 +48,7 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
private boolean canceled = false;
|
private boolean canceled = false;
|
||||||
private Method method = Method.HTTP_UPLOAD;
|
private Method method = Method.HTTP_UPLOAD;
|
||||||
|
|
||||||
public HttpDownloadConnection(HttpConnectionManager manager) {
|
HttpDownloadConnection(HttpConnectionManager manager) {
|
||||||
this.mHttpConnectionManager = manager;
|
this.mHttpConnectionManager = manager;
|
||||||
this.mXmppConnectionService = manager.getXmppConnectionService();
|
this.mXmppConnectionService = manager.getXmppConnectionService();
|
||||||
this.mUseTor = mXmppConnectionService.useTorToConnect();
|
this.mUseTor = mXmppConnectionService.useTorToConnect();
|
||||||
|
@ -60,7 +60,7 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
if (this.mStatus == STATUS_OFFER_CHECK_FILESIZE) {
|
if (this.mStatus == STATUS_OFFER_CHECK_FILESIZE) {
|
||||||
checkFileSize(true);
|
checkFileSize(true);
|
||||||
} else {
|
} else {
|
||||||
new Thread(new FileDownloader(true)).start();
|
download(true);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -107,12 +107,22 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
this.message.setEncryption(Message.ENCRYPTION_NONE);
|
this.message.setEncryption(Message.ENCRYPTION_NONE);
|
||||||
}
|
}
|
||||||
method = mUrl.getProtocol().equalsIgnoreCase(P1S3UrlStreamHandler.PROTOCOL_NAME) ? Method.P1_S3 : Method.HTTP_UPLOAD;
|
method = mUrl.getProtocol().equalsIgnoreCase(P1S3UrlStreamHandler.PROTOCOL_NAME) ? Method.P1_S3 : Method.HTTP_UPLOAD;
|
||||||
checkFileSize(interactive);
|
long knownFileSize = message.getFileParams().size;
|
||||||
|
if (knownFileSize > 0 && interactive && method != Method.P1_S3) {
|
||||||
|
this.file.setExpectedSize(knownFileSize);
|
||||||
|
download(true);
|
||||||
|
} else {
|
||||||
|
checkFileSize(interactive);
|
||||||
|
}
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void download(boolean interactive) {
|
||||||
|
new Thread(new FileDownloader(interactive)).start();
|
||||||
|
}
|
||||||
|
|
||||||
private void checkFileSize(boolean interactive) {
|
private void checkFileSize(boolean interactive) {
|
||||||
new Thread(new FileSizeChecker(interactive)).start();
|
new Thread(new FileSizeChecker(interactive)).start();
|
||||||
}
|
}
|
||||||
|
@ -252,7 +262,7 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
&& size <= mHttpConnectionManager.getAutoAcceptFileSize()
|
&& size <= mHttpConnectionManager.getAutoAcceptFileSize()
|
||||||
&& mXmppConnectionService.isDataSaverDisabled()) {
|
&& mXmppConnectionService.isDataSaverDisabled()) {
|
||||||
HttpDownloadConnection.this.acceptedAutomatically = true;
|
HttpDownloadConnection.this.acceptedAutomatically = true;
|
||||||
new Thread(new FileDownloader(interactive)).start();
|
download(interactive);
|
||||||
} else {
|
} else {
|
||||||
changeStatus(STATUS_OFFER);
|
changeStatus(STATUS_OFFER);
|
||||||
HttpDownloadConnection.this.acceptedAutomatically = false;
|
HttpDownloadConnection.this.acceptedAutomatically = false;
|
||||||
|
|
Loading…
Reference in New Issue