use of eu.siacs.conversations.Downloader in project Zom-Android by zom.
the class ChatSessionAdapter method downloadMedia.
public String downloadMedia(String mediaLink, String msgId, String nickname) {
String result = null;
try {
Downloader dl = new Downloader();
File fileDownload = dl.openSecureStorageFile(mContactId + "", mediaLink);
OutputStream storageStream = new info.guardianproject.iocipher.FileOutputStream(fileDownload);
boolean downloaded = dl.get(mediaLink, storageStream);
if (downloaded) {
String mimeType = dl.getMimeType();
try {
// boolean isVerified = getDefaultOtrChatSession().isKeyVerified(bareUsername);
// int type = isVerified ? Imps.MessageType.INCOMING_ENCRYPTED_VERIFIED : Imps.MessageType.INCOMING_ENCRYPTED;
int type = Imps.MessageType.INCOMING;
if (mediaLink.startsWith("aesgcm"))
type = Imps.MessageType.INCOMING_ENCRYPTED_VERIFIED;
result = SecureMediaStore.vfsUri(fileDownload.getAbsolutePath()).toString();
insertOrUpdateChat(result);
// Imps.deleteMessageInDb(service.getContentResolver(),msgId);
Uri messageUri = Imps.insertMessageInDb(service.getContentResolver(), mIsGroupChat, getId(), true, nickname, result, System.currentTimeMillis(), type, 0, msgId, mimeType);
if (// error writing to database
messageUri == null) {
Log.e(TAG, "error saving message to the db: " + msgId);
return null;
}
String sanitizedPath = Uri.parse(mediaLink).getLastPathSegment();
try {
int N = mRemoteListeners.beginBroadcast();
for (int i = 0; i < N; i++) {
IChatListener listener = mRemoteListeners.getBroadcastItem(i);
try {
listener.onIncomingFileTransferProgress(sanitizedPath, 100);
} catch (RemoteException e) {
// The RemoteCallbackList will take care of removing the
// dead listeners.
}
}
mRemoteListeners.finishBroadcast();
} catch (Exception e) {
Log.e(TAG, "error notifying of new messages", e);
}
} catch (Exception e) {
Log.e(ImApp.LOG_TAG, "Error updating file transfer progress", e);
}
}
} catch (Exception e) {
Log.e(ImApp.LOG_TAG, "error downloading incoming media", e);
}
return result;
}
Aggregations