use of net.iGap.controllers.MessageDataStorage in project iGap-Android by KianIranian-STDG.
the class CdnDownloader method downloadCompleted.
private void downloadCompleted(DownloadObject file) {
MessageDataStorage storage = MessageDataStorage.getInstance(currentAccount);
String path = null;
try {
if (file.selector == FILE_VALUE) {
AndroidUtils.cutFromTemp(file.tempFile.getAbsolutePath(), file.destFile.getAbsolutePath());
storage.setAttachmentFilePath(file.mainCacheId, path = file.destFile.getAbsolutePath(), false);
} else if (file.selector == SMALL_THUMBNAIL_VALUE || file.selector == LARGE_THUMBNAIL_VALUE) {
storage.setAttachmentFilePath(file.mainCacheId, path = file.tempFile.getAbsolutePath(), true);
}
file.notifyObservers(Resource.success(new HttpRequest.Progress(file, 100, path, file.fileToken, file.selector)));
requestedDownload.remove(file.key);
// must be change!
Downloader.getInstance(currentAccount).onCdnDownloadComplete(file.mainCacheId);
} catch (IOException e) {
handleError(file, e.getMessage());
}
}
use of net.iGap.controllers.MessageDataStorage in project iGap-Android by KianIranian-STDG.
the class HttpRequest method moveTempToDownloadedDir.
@WorkerThread
private void moveTempToDownloadedDir() throws IOException {
MessageDataStorage storage = MessageDataStorage.getInstance(currentAccount);
switch(selector) {
case Selector.FILE_VALUE:
AndroidUtils.globalQueue.postRunnable(() -> {
File cutTo = new File(fileObject.destFile.getAbsolutePath());
if (!cutTo.exists()) {
try {
cutTo.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
File cutForm = new File(fileObject.tempFile.getAbsolutePath());
try (InputStream in = new FileInputStream(cutForm);
OutputStream out = new FileOutputStream(cutTo)) {
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
AndroidUtils.deleteFile(cutForm);
G.runOnUiThread(() -> {
notifyObservers(Resource.success(new Progress(fileObject, fileObject.progress, selector == Selector.FILE_VALUE ? fileObject.destFile.getAbsolutePath() : fileObject.tempFile.getAbsolutePath(), fileObject.fileToken, selector)));
notifyDownloadStatus(HttpDownloader.DownloadStatus.DOWNLOADED);
});
} catch (IOException e) {
e.printStackTrace();
}
});
storage.setAttachmentFilePath(fileObject.mainCacheId, fileObject.destFile.getAbsolutePath(), false);
break;
case Selector.SMALL_THUMBNAIL_VALUE:
case Selector.LARGE_THUMBNAIL_VALUE:
storage.setAttachmentFilePath(fileObject.mainCacheId, fileObject.tempFile.getAbsolutePath(), true);
notifyObservers(Resource.success(new Progress(fileObject, fileObject.progress, selector == Selector.FILE_VALUE ? fileObject.destFile.getAbsolutePath() : fileObject.tempFile.getAbsolutePath(), fileObject.fileToken, selector)));
notifyDownloadStatus(HttpDownloader.DownloadStatus.DOWNLOADED);
break;
}
}
Aggregations