work around a NPE caused by arace condition in the http upload

This commit is contained in:
Daniel Gultsch 2015-09-15 22:49:43 +02:00
parent 999d65c187
commit b5719fd747
1 changed files with 6 additions and 3 deletions

View File

@ -70,11 +70,14 @@ public class HttpUploadConnection implements Transferable {
@Override @Override
public long getFileSize() { public long getFileSize() {
return this.file.getExpectedSize(); return file == null ? 0 : file.getExpectedSize();
} }
@Override @Override
public int getProgress() { public int getProgress() {
if (file == null) {
return 0;
}
return (int) ((((double) transmitted) / file.getExpectedSize()) * 100); return (int) ((((double) transmitted) / file.getExpectedSize()) * 100);
} }
@ -92,8 +95,6 @@ public class HttpUploadConnection implements Transferable {
public void init(Message message, boolean delay) { public void init(Message message, boolean delay) {
this.message = message; this.message = message;
message.setTransferable(this);
mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND);
this.account = message.getConversation().getAccount(); this.account = message.getConversation().getAccount();
this.file = mXmppConnectionService.getFileBackend().getFile(message, false); this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
this.mime = this.file.getMimeType(); this.mime = this.file.getMimeType();
@ -139,6 +140,8 @@ public class HttpUploadConnection implements Transferable {
} }
} }
}); });
message.setTransferable(this);
mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND);
} }
private class FileUploader implements Runnable { private class FileUploader implements Runnable {