Search in sources :

Example 1 with RequestGetImage

use of com.fanap.podchat.requestobject.RequestGetImage 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();
// }
// 
// }
// 
// 
// }
// 
// });
}
Also used : RequestGetFile(com.fanap.podchat.requestobject.RequestGetFile) GsonBuilder(com.google.gson.GsonBuilder) RequestGetImage(com.fanap.podchat.requestobject.RequestGetImage) RequestGetPodSpaceImage(com.fanap.podchat.requestobject.RequestGetPodSpaceImage) Bitmap(android.graphics.Bitmap) ChatResponse(com.fanap.podchat.model.ChatResponse) RequestGetPodSpaceFile(com.fanap.podchat.requestobject.RequestGetPodSpaceFile)

Aggregations

Bitmap (android.graphics.Bitmap)1 ChatResponse (com.fanap.podchat.model.ChatResponse)1 RequestGetFile (com.fanap.podchat.requestobject.RequestGetFile)1 RequestGetImage (com.fanap.podchat.requestobject.RequestGetImage)1 RequestGetPodSpaceFile (com.fanap.podchat.requestobject.RequestGetPodSpaceFile)1 RequestGetPodSpaceImage (com.fanap.podchat.requestobject.RequestGetPodSpaceImage)1 GsonBuilder (com.google.gson.GsonBuilder)1