diff options
author | steckbrief <steckbrief@chefmail.de> | 2017-02-06 10:01:13 +0100 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2017-02-06 10:01:13 +0100 |
commit | 754de6bb0449a577d2bb9c28cca6adf0ef9554f6 (patch) | |
tree | 279b405d94e0d86d10ed94bd34d919457944ead6 /src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpDownloadFileTransferEntity.java | |
parent | cd633f13b8d7327e47994bb5a000f0c0b7089e7f (diff) |
relates FS#241: Implementation of http download based on okhttp
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpDownloadFileTransferEntity.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpDownloadFileTransferEntity.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpDownloadFileTransferEntity.java new file mode 100644 index 00000000..fcd3904b --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpDownloadFileTransferEntity.java @@ -0,0 +1,53 @@ +package de.thedevstack.conversationsplus.services.filetransfer.http.download; + +import android.os.PowerManager; + +import de.thedevstack.conversationsplus.entities.FileParams; +import de.thedevstack.conversationsplus.entities.Message; +import de.thedevstack.conversationsplus.http.ProgressListener; +import de.thedevstack.conversationsplus.services.filetransfer.FileTransferEntity; +import de.thedevstack.conversationsplus.utils.UiUpdateHelper; + +/** + * + */ +public class HttpDownloadFileTransferEntity extends FileTransferEntity implements ProgressListener { + public PowerManager.WakeLock wakeLock; + /** + * Initializes the FileTransferEntity based on the associated message. + * This initialization includes loading the file and associating this transferable to the message. + * + * @param message the message in which the file to transfer is contained. + */ + public HttpDownloadFileTransferEntity(Message message) { + super(message, false); + FileParams fileParams = message.getFileParams(); + this.initFile(); + this.getFile().setExpectedSize(fileParams.getSize()); + } + + /** + * Returns the global transferable status. + * + * @return {@value STATUS_FAILED} if #isFailed returns <code>true</code>, {@value STATUS_DOWNLOADING} otherwise + */ + @Override + public int getStatus() { + int status = (isFailed()) ? STATUS_FAILED : STATUS_DOWNLOADING; + return status; + } + + @Override + public void update(long bytesRead, long contentLength, boolean done) { + if (0 >= getFile().getExpectedSize()) { + getFile().setExpectedSize(contentLength); + getMessage().getFileParams().setSize(contentLength); + } + if (done) { + this.transferred(); + } else { + this.updateProgress(bytesRead); + } + UiUpdateHelper.updateConversationUi(); + } +} |