use of org.whispersystems.signalservice.api.messages.SignalServiceAttachment.ProgressListener in project Signal-Android by WhisperSystems.
the class AttachmentDownloadJob method retrieveAttachment.
private void retrieveAttachment(MasterSecret masterSecret, long messageId, final AttachmentId attachmentId, final Attachment attachment) throws IOException {
AttachmentDatabase database = DatabaseFactory.getAttachmentDatabase(context);
File attachmentFile = null;
try {
attachmentFile = createTempFile();
SignalServiceAttachmentPointer pointer = createAttachmentPointer(masterSecret, attachment);
InputStream stream = messageReceiver.retrieveAttachment(pointer, attachmentFile, MAX_ATTACHMENT_SIZE, new ProgressListener() {
@Override
public void onAttachmentProgress(long total, long progress) {
EventBus.getDefault().postSticky(new PartProgressEvent(attachment, total, progress));
}
});
database.insertAttachmentsForPlaceholder(masterSecret, messageId, attachmentId, stream);
} catch (InvalidPartException | NonSuccessfulResponseCodeException | InvalidMessageException | MmsException e) {
Log.w(TAG, e);
markFailed(messageId, attachmentId);
} finally {
if (attachmentFile != null)
attachmentFile.delete();
}
}
use of org.whispersystems.signalservice.api.messages.SignalServiceAttachment.ProgressListener in project Signal-Android by WhisperSystems.
the class PushSendJob method getAttachmentsFor.
protected List<SignalServiceAttachment> getAttachmentsFor(MasterSecret masterSecret, List<Attachment> parts) {
List<SignalServiceAttachment> attachments = new LinkedList<>();
for (final Attachment attachment : parts) {
if (ContentType.isImageType(attachment.getContentType()) || ContentType.isAudioType(attachment.getContentType()) || ContentType.isVideoType(attachment.getContentType())) {
try {
if (attachment.getDataUri() == null || attachment.getSize() == 0)
throw new IOException("Assertion failed, outgoing attachment has no data!");
InputStream is = PartAuthority.getAttachmentStream(context, masterSecret, attachment.getDataUri());
attachments.add(SignalServiceAttachment.newStreamBuilder().withStream(is).withContentType(attachment.getContentType()).withLength(attachment.getSize()).withListener(new ProgressListener() {
@Override
public void onAttachmentProgress(long total, long progress) {
EventBus.getDefault().postSticky(new PartProgressEvent(attachment, total, progress));
}
}).build());
} catch (IOException ioe) {
Log.w(TAG, "Couldn't open attachment", ioe);
}
}
}
return attachments;
}
use of org.whispersystems.signalservice.api.messages.SignalServiceAttachment.ProgressListener in project Signal-Android by signalapp.
the class PushSendJob method getAttachmentsFor.
protected List<SignalServiceAttachment> getAttachmentsFor(List<Attachment> parts) {
List<SignalServiceAttachment> attachments = new LinkedList<>();
for (final Attachment attachment : parts) {
try {
if (attachment.getDataUri() == null || attachment.getSize() == 0)
throw new IOException("Assertion failed, outgoing attachment has no data!");
InputStream is = PartAuthority.getAttachmentStream(context, attachment.getDataUri());
attachments.add(SignalServiceAttachment.newStreamBuilder().withStream(is).withContentType(attachment.getContentType()).withLength(attachment.getSize()).withFileName(attachment.getFileName()).withVoiceNote(attachment.isVoiceNote()).withListener(new ProgressListener() {
@Override
public void onAttachmentProgress(long total, long progress) {
EventBus.getDefault().postSticky(new PartProgressEvent(attachment, total, progress));
}
}).build());
} catch (IOException ioe) {
Log.w(TAG, "Couldn't open attachment", ioe);
}
}
return attachments;
}
Aggregations