Snippets

A5.ua Mobile Development UI, Animation and more

Created by Ольга Корохина
@Multipart
@POST("locations/image360Degree")
Call<CreateImage360DegreeResponse> createImage360Degree(@Part MultipartBody.Part filePart,
                                                            @Part("photo_string") RequestBody photoString,
                                                            @Part("image_id") RequestBody imageId,
                                                            @Part("region_id") RequestBody regionId,
                                                            @Part("lat") RequestBody lat,
                                                            @Part("lng") RequestBody lng,
                                                            @Part("rotation") RequestBody rotation,
                                                            @Part("url") RequestBody url);
----------------------------------------------------------------------------------------------------------------														
private Call<IBaseModule.CreateImage360DegreeResponse> generateCreateImage360DegreeCall(CImage360Degree image) {
            File file = new File(image.getLocation());

            RequestBody requestFile =
                    RequestBody.create(MediaType.parse("multipart/form-data"), file);
            MultipartBody.Part filePart =
                    MultipartBody.Part.createFormData("file", file.getName(), requestFile);

            String string = image.getImageString();
            RequestBody imageString =
                    RequestBody.create(
                            MediaType.parse("multipart/form-data"), string != null ? string : "");

            RequestBody imageId =
                    RequestBody.create(
                            MediaType.parse("multipart/form-data"), String.valueOf(image.getFloor().getServerId()));

            CRegion region = image.getRegion();
            RequestBody regionId =
                    RequestBody.create(
                            MediaType.parse("multipart/form-data"), String.valueOf(region == null ? 0 : region.getServerId()));

            RequestBody latitude =
                    RequestBody.create(
                            MediaType.parse("multipart/form-data"), String.valueOf(image.getPosition().latitude));

            RequestBody longitude =
                    RequestBody.create(
                            MediaType.parse("multipart/form-data"), String.valueOf(image.getPosition().longitude));

            RequestBody rotation =
                    RequestBody.create(
                            MediaType.parse("multipart/form-data"), String.valueOf(image.getRotation()));

            RequestBody url =
                    RequestBody.create(
                            MediaType.parse("multipart/form-data"), String.valueOf(image.getUrl()));

            return module.createImage360Degree(filePart,
                    imageString,
                    imageId,
                    regionId,
                    latitude,
                    longitude,
                    rotation,
                    url);
}


public Pair<Long, String> createImage360Degree(CImage360Degree image) {
        try {
            Response<IBaseModule.CreateImage360DegreeResponse> response = generateCreateImage360DegreeCall(image, false).execute();
            IBaseModule.CreateImage360DegreeResponse body = response.body();
            if (body != null) {
                long id = body.getId();
                String url = body.getUrl();
                return Pair.create(id, url);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }


public void createImage360Degree(CImage360Degree image, final Callback<Pair<Long, String>> callback) {
        generateCreateImage360DegreeCall(image, false).enqueue(new retrofit2.Callback<IBaseModule.CreateImage360DegreeResponse>() {
            @Override
            public void onResponse(@NonNull Call<IBaseModule.CreateImage360DegreeResponse> call, @NonNull Response<IBaseModule.CreateImage360DegreeResponse> response) {
                IBaseModule.CreateImage360DegreeResponse body = response.body();
                Pair<Long, String> result = null;
                if (body != null) {
                    long id = body.getId();
                    String url = body.getUrl();
                    result = Pair.create(id, url);
                }
                callback.success(result);
            }

            @Override
            public void onFailure(@NonNull Call<IBaseModule.CreateImage360DegreeResponse> call, @NonNull Throwable t) {
                callback.failure(t);
            }
        });
    }

Comments (0)