Search in sources :

Example 1 with LFileUpload

use of com.fanap.podchat.localmodel.LFileUpload in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method mainMapStaticImage.

/**
 * [Required] center
 * if these params don't set they have default values :
 * [default value] messageType = "standard-night"
 * [default value] zoom = 15
 * [default value] width = 800
 * [default value] height = 500
 */
private String mainMapStaticImage(RequestLocationMessage request, Activity activity, String uniqueId, boolean isMessage) {
    try {
        if (Util.isNullOrEmpty(uniqueId)) {
            uniqueId = generateUniqueId();
        }
        if (needReadStoragePermission(activity))
            return uniqueId;
        if (chatReady) {
            String type = request.getType();
            int zoom = request.getZoom();
            int width = request.getWidth();
            int height = request.getHeight();
            String center = request.getCenter();
            long threadId = request.getThreadId();
            int messageType = request.getMessageType();
            String systemMetadata = request.getSystemMetadata();
            if (Util.isNullOrEmpty(type)) {
                type = "standard-night";
            }
            if (Util.isNullOrEmpty(zoom)) {
                zoom = 15;
            }
            if (Util.isNullOrEmpty(width)) {
                width = 800;
            }
            if (Util.isNullOrEmpty(height)) {
                height = 500;
            }
            JsonObject jsonObject = (JsonObject) gson.toJsonTree(request);
            jsonObject.addProperty("uniqueId", uniqueId);
            showLog("SEND_GET_MAP_STATIC", getJsonForLog(jsonObject));
            RetrofitHelperMap retrofitHelperMap = new RetrofitHelperMap("https://api.neshan.org/");
            MapApi mapApi = retrofitHelperMap.getService(MapApi.class);
            Call<ResponseBody> call = mapApi.mapStaticCall(API_KEY_MAP, type, zoom, center, width, height);
            String finalUniqueId = uniqueId;
            String finalUniqueId1 = uniqueId;
            call.enqueue(new retrofit2.Callback<ResponseBody>() {

                @Override
                public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                    if (response.isSuccessful()) {
                        if (response.body() != null) {
                            Bitmap bitmap = BitmapFactory.decodeStream(response.body().byteStream());
                            ChatResponse<ResultStaticMapImage> chatResponse = new ChatResponse<>();
                            ResultStaticMapImage result = new ResultStaticMapImage();
                            result.setBitmap(bitmap);
                            chatResponse.setUniqueId(finalUniqueId);
                            chatResponse.setResult(result);
                            listenerManager.callOnStaticMap(chatResponse);
                            showLog("RECEIVE_MAP_STATIC", "[]");
                            if (!call.isCanceled()) {
                                call.cancel();
                            }
                            if (isMessage) {
                                File file = null;
                                try {
                                    file = FileUtils.saveBitmap(bitmap, "map");
                                } catch (Exception e) {
                                    captureError(ChatConstant.ERROR_WRITING_FILE, ChatConstant.ERROR_CODE_WRITING_FILE, finalUniqueId1);
                                }
                                if (file == null) {
                                    captureError(ChatConstant.ERROR_WRITING_FILE, ChatConstant.ERROR_CODE_WRITING_FILE, finalUniqueId1);
                                    return;
                                }
                                Uri fileUri = Uri.fromFile(file);
                                // String newPath = FilePick.getSmartFilePath(getContext(), fileUri);
                                String mimType = handleMimType(fileUri, file);
                                LFileUpload lFileUpload = new LFileUpload();
                                lFileUpload.setFileUri(fileUri);
                                if (activity != null) {
                                    lFileUpload.setActivity(activity);
                                }
                                lFileUpload.setThreadId(threadId);
                                lFileUpload.setUniqueId(finalUniqueId);
                                lFileUpload.setMessageType(messageType);
                                lFileUpload.setMimeType(mimType);
                                lFileUpload.setMethodName(ChatConstant.METHOD_LOCATION_MSG);
                                lFileUpload.setSystemMetaData(systemMetadata);
                                lFileUpload.setCenter(center);
                                uploadImageFileMessage(lFileUpload);
                            }
                        }
                    } else {
                        captureError(ChatConstant.ERROR_CALL_NESHAN_API, ChatConstant.ERROR_CODE_CALL_NESHAN_API, finalUniqueId);
                        showErrorLog(response.message());
                    }
                }

                @Override
                public void onFailure(Call<ResponseBody> call, Throwable t) {
                    captureError(t.getMessage(), ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, finalUniqueId, t);
                }
            });
        } else {
            captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
        }
    } catch (Throwable throwable) {
        captureError(throwable.getMessage(), ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, uniqueId, throwable);
    }
    return uniqueId;
}
Also used : ResultStaticMapImage(com.fanap.podchat.model.ResultStaticMapImage) LFileUpload(com.fanap.podchat.localmodel.LFileUpload) JsonObject(com.google.gson.JsonObject) Uri(android.net.Uri) JSONException(org.json.JSONException) SentryException(io.sentry.core.protocol.SentryException) IOException(java.io.IOException) JsonSyntaxException(com.google.gson.JsonSyntaxException) PodChatException(com.fanap.podchat.util.PodChatException) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException) ProgressResponseBody(com.fanap.podchat.networking.ProgressResponseBody) ResponseBody(okhttp3.ResponseBody) RetrofitHelperMap(com.fanap.podchat.networking.retrofithelper.RetrofitHelperMap) MapApi(com.fanap.podchat.networking.api.MapApi) Bitmap(android.graphics.Bitmap) ChatResponse(com.fanap.podchat.model.ChatResponse) MetaDataFile(com.fanap.podchat.model.MetaDataFile) RequestUploadFile(com.fanap.podchat.requestobject.RequestUploadFile) ResultDownloadFile(com.fanap.podchat.chat.file_manager.download_file.model.ResultDownloadFile) ResultFile(com.fanap.podchat.model.ResultFile) RequestGetPodSpaceFile(com.fanap.podchat.requestobject.RequestGetPodSpaceFile) RequestGetFile(com.fanap.podchat.requestobject.RequestGetFile) RequestCreateThreadWithFile(com.fanap.podchat.requestobject.RequestCreateThreadWithFile) File(java.io.File) ResultImageFile(com.fanap.podchat.model.ResultImageFile)

Aggregations

Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 ResultDownloadFile (com.fanap.podchat.chat.file_manager.download_file.model.ResultDownloadFile)1 LFileUpload (com.fanap.podchat.localmodel.LFileUpload)1 ChatResponse (com.fanap.podchat.model.ChatResponse)1 MetaDataFile (com.fanap.podchat.model.MetaDataFile)1 ResultFile (com.fanap.podchat.model.ResultFile)1 ResultImageFile (com.fanap.podchat.model.ResultImageFile)1 ResultStaticMapImage (com.fanap.podchat.model.ResultStaticMapImage)1 ProgressResponseBody (com.fanap.podchat.networking.ProgressResponseBody)1 MapApi (com.fanap.podchat.networking.api.MapApi)1 RetrofitHelperMap (com.fanap.podchat.networking.retrofithelper.RetrofitHelperMap)1 RoomIntegrityException (com.fanap.podchat.persistance.RoomIntegrityException)1 RequestCreateThreadWithFile (com.fanap.podchat.requestobject.RequestCreateThreadWithFile)1 RequestGetFile (com.fanap.podchat.requestobject.RequestGetFile)1 RequestGetPodSpaceFile (com.fanap.podchat.requestobject.RequestGetPodSpaceFile)1 RequestUploadFile (com.fanap.podchat.requestobject.RequestUploadFile)1 PodChatException (com.fanap.podchat.util.PodChatException)1 JsonObject (com.google.gson.JsonObject)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1