diff options
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/download/HttpDownloadFileTransferEntity.java')
-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(); + } +} |