use of com.fanap.podchat.requestobject.RequestGetFile in project pod-chat-android-sdk by FanapSoft.
the class ChatActivity method downloadFile.
private void downloadFile() {
String url = "https://core.pod.ir/nzh/image?imageId=222808&hashCode=16c3cd2b93f-0.527719303638482";
// image
// long imageId = 404143;
long imageId = 68349;
long fileId = 68684;
// String imageHashCode = "17024463974-0.5588549950419339";
String imageHashCode = "16feadc7bf1-0.5248624596970302";
String fileHashCode = "17077360d4b-0.2366487166443898";
RequestGetImage requestGetImage = new RequestGetImage.Builder(imageId, imageHashCode, true).build();
RequestGetFile requestGetFile = new RequestGetFile.Builder(fileId, fileHashCode, true).build();
RequestGetPodSpaceFile rePod = new RequestGetPodSpaceFile.Builder("GAUPE1ZRK76VOXBS").build();
RequestGetPodSpaceImage rePodImage = new RequestGetPodSpaceImage.Builder("613Q7WCCEXZ1DGY5").setQuality(0.45f).build();
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_WRITE_EXTERNAL_STORAGE);
return;
}
downloadingId = presenter.downloadFile(rePodImage, new ProgressHandler.IDownloadFile() {
@Override
public void onProgressUpdate(String uniqueId, long bytesDownloaded, long totalBytesToDownload) {
Log.e("DOWNLOAD", "IN ACTIVITY: " + "Downloaded: " + bytesDownloaded + " Left: " + totalBytesToDownload);
}
@Override
public void onProgressUpdate(String uniqueId, int progress) {
Log.e("DOWNLOAD", "IN ACTIVITY: " + "Progress: " + progress);
}
@Override
public void onError(String uniqueId, String error, String url) {
Log.e("DOWNLOAD", "IN ACTIVITY: ERROR :(((");
}
@Override
public void onLowFreeSpace(String uniqueId, String url) {
Log.e("DOWNLOAD", "Low Space...");
}
@Override
public void onFileReady(ChatResponse<ResultDownloadFile> response) {
Log.e("DOWNLOAD", "IN ACTIVITY: Finish File!!!!");
Log.e("DOWNLOAD", "File name: " + response.getResult().getFile().getName());
Log.e("DOWNLOAD", "Uri " + response.getResult().getUri());
Log.e("DOWNLOAD", "File Exist " + response.getResult().getFile().exists());
if (response.getResult().getFile().exists()) {
try {
Bitmap v = BitmapFactory.decodeFile(response.getResult().getFile().getAbsolutePath());
runOnUiThread(() -> {
// imageMap.setImageBitmap(v)
});
} catch (Exception e) {
e.printStackTrace();
Log.e("DOWNLOAD", "Not Image");
}
}
}
});
// downloadingId = presenter.downloadFile(requestGetImage, new ProgressHandler.IDownloadFile() {
//
//
// @Override
// public void onProgressUpdate(String uniqueId, int bytesDownloaded, int totalBytesToDownload) {
// Log.e("DOWNLOAD", "IN ACTIVITY: " + "Downloaded: " + bytesDownloaded + " Left: " + totalBytesToDownload);
//
// }
//
// @Override
// public void onProgressUpdate(String uniqueId, int progress) {
//
// }
//
// @Override
// public void onError(String uniqueId, String error, String url) {
// Log.e("DOWNLOAD", "IN ACTIVITY: ERROR :(((");
//
// }
//
// @Override
// public void onLowFreeSpace(String uniqueId, String url) {
// Log.e("DOWNLOAD", "Low Space...");
//
// }
//
// @Override
// public void onFileReady(ChatResponse<ResultDownloadFile> response) {
// Log.e("DOWNLOAD", "IN ACTIVITY: Finish File!!!!");
// Log.e("DOWNLOAD", "File name: " + response.getResult().getFile().getName());
// Log.e("DOWNLOAD", "Uri " + response.getResult().getUri());
// Log.e("DOWNLOAD", "File Exist " + response.getResult().getFile().exists());
//
//
// if (response.getResult().getFile().exists()) {
//
//
// try {
// Bitmap v = BitmapFactory.decodeFile(response.getResult().getFile().getAbsolutePath());
// runOnUiThread(() -> imageMap.setImageBitmap(v));
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// }
//
//
// }
//
// });
}
use of com.fanap.podchat.requestobject.RequestGetFile in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method getFile.
/**
* @param request fileId and hashCode of desired file
* @param progressHandler callbacks for downloading progress.
* @return uniqueId of request.
*/
public String getFile(RequestGetFile request, ProgressHandler.IDownloadFile progressHandler) {
String uniqueId = generateUniqueId();
String url = getFile(request.getFileId(), request.getHashCode(), true);
PodDownloader.IDownloaderError downloaderErrorInterface = getDownloaderErrorInterface(progressHandler, uniqueId, url);
File destinationFolder;
if (cache && request.canUseCache()) {
destinationFolder = FileUtils.getDownloadDirectory() != null ? FileUtils.getOrCreateDownloadDirectory(FileUtils.FILES) : FileUtils.getOrCreateDirectory(FileUtils.FILES);
} else {
destinationFolder = FileUtils.getDownloadDirectory() != null ? FileUtils.getOrCreateDownloadDirectory(FileUtils.FILES) : FileUtils.getPublicFilesDirectory();
}
String fileName = "file_" + request.getFileId() + "_" + request.getHashCode();
if (destinationFolder == null) {
progressHandler.onError(uniqueId, ChatConstant.ERROR_WRITING_FILE, url);
return uniqueId;
}
File cachedFile = FileUtils.findFileInFolder(destinationFolder, fileName);
if (cachedFile != null && cachedFile.isFile() && request.canUseCache()) {
// file exists
ChatResponse<ResultDownloadFile> response = PodDownloader.generateDownloadResult(request.getHashCode(), request.getFileId(), cachedFile);
progressHandler.onFileReady(response);
return uniqueId;
}
// only url should return in callback
if (!hasFreeSpace) {
progressHandler.onLowFreeSpace(uniqueId, url);
return uniqueId;
}
if (chatReady) {
Call call = PodDownloader.download(new ProgressHandler.IDownloadFile() {
@Override
public void onError(String mUniqueId, String error, String mUrl) {
progressHandler.onError(uniqueId, error, url);
}
@Override
public void onProgressUpdate(String mUniqueId, long bytesDownloaded, long totalBytesToDownload) {
progressHandler.onProgressUpdate(uniqueId, bytesDownloaded, totalBytesToDownload);
if (totalBytesToDownload > checkFreeSpace()) {
progressHandler.onLowFreeSpace(uniqueId, url);
}
}
@Override
public void onProgressUpdate(String mUniqueId, int progress) {
progressHandler.onProgressUpdate(uniqueId, progress);
}
@Override
public void onFileReady(ChatResponse<ResultDownloadFile> response) {
progressHandler.onFileReady(response);
}
}, getFileServer(), url, fileName, destinationFolder, downloaderErrorInterface, request.getHashCode(), request.getFileId());
downloadCallList.put(uniqueId, call);
} else
onChatNotReady(uniqueId);
return uniqueId;
}
Aggregations