Commit e6f88f4f authored by Ishankha K.C's avatar Ishankha K.C

Merge branch 'feature/chamod_dev' into 'master'

connect document management api

See merge request !3
parents 1c4c583c c6a05d88
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetSelector">
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2024-09-03T20:20:16.727982200Z">
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="LocalEmulator" identifier="path=D:\Softwares\toolbox\.android\.android\avd\Pixel_XL_API_29.avd" />
</handle>
</Target>
</DropdownSelection>
<DialogSelection />
</SelectionState>
</selectionStates>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="direct_access_persist.xml">
<option name="deviceSelectionList">
<list>
<PersistentDeviceSelectionData>
<option name="api" value="27" />
<option name="brand" value="DOCOMO" />
<option name="codename" value="F01L" />
<option name="id" value="F01L" />
<option name="manufacturer" value="FUJITSU" />
<option name="name" value="F-01L" />
<option name="screenDensity" value="360" />
<option name="screenX" value="720" />
<option name="screenY" value="1280" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="28" />
<option name="brand" value="DOCOMO" />
<option name="codename" value="SH-01L" />
<option name="id" value="SH-01L" />
<option name="manufacturer" value="SHARP" />
<option name="name" value="AQUOS sense2 SH-01L" />
<option name="screenDensity" value="480" />
<option name="screenX" value="1080" />
<option name="screenY" value="2160" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="Lenovo" />
<option name="codename" value="TB370FU" />
<option name="id" value="TB370FU" />
<option name="manufacturer" value="Lenovo" />
<option name="name" value="Tab P12" />
<option name="screenDensity" value="340" />
<option name="screenX" value="1840" />
<option name="screenY" value="2944" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="31" />
<option name="brand" value="samsung" />
<option name="codename" value="a51" />
<option name="id" value="a51" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy A51" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="google" />
<option name="codename" value="akita" />
<option name="id" value="akita" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 8a" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="samsung" />
<option name="codename" value="b0q" />
<option name="id" value="b0q" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy S22 Ultra" />
<option name="screenDensity" value="600" />
<option name="screenX" value="1440" />
<option name="screenY" value="3088" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="32" />
<option name="brand" value="google" />
<option name="codename" value="bluejay" />
<option name="id" value="bluejay" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 6a" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="google" />
<option name="codename" value="caiman" />
<option name="id" value="caiman" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 9 Pro" />
<option name="screenDensity" value="360" />
<option name="screenX" value="960" />
<option name="screenY" value="2142" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="google" />
<option name="codename" value="comet" />
<option name="id" value="comet" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 9 Pro Fold" />
<option name="screenDensity" value="390" />
<option name="screenX" value="2076" />
<option name="screenY" value="2152" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="29" />
<option name="brand" value="samsung" />
<option name="codename" value="crownqlteue" />
<option name="id" value="crownqlteue" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy Note9" />
<option name="screenDensity" value="420" />
<option name="screenX" value="2220" />
<option name="screenY" value="1080" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="samsung" />
<option name="codename" value="dm3q" />
<option name="id" value="dm3q" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy S23 Ultra" />
<option name="screenDensity" value="600" />
<option name="screenX" value="1440" />
<option name="screenY" value="3088" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="samsung" />
<option name="codename" value="e1q" />
<option name="id" value="e1q" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy S24" />
<option name="screenDensity" value="480" />
<option name="screenX" value="1080" />
<option name="screenY" value="2340" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="google" />
<option name="codename" value="felix" />
<option name="id" value="felix" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel Fold" />
<option name="screenDensity" value="420" />
<option name="screenX" value="2208" />
<option name="screenY" value="1840" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="google" />
<option name="codename" value="felix" />
<option name="id" value="felix" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel Fold" />
<option name="screenDensity" value="420" />
<option name="screenX" value="2208" />
<option name="screenY" value="1840" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="google" />
<option name="codename" value="felix_camera" />
<option name="id" value="felix_camera" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel Fold (Camera-enabled)" />
<option name="screenDensity" value="420" />
<option name="screenX" value="2208" />
<option name="screenY" value="1840" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="samsung" />
<option name="codename" value="gts8uwifi" />
<option name="id" value="gts8uwifi" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy Tab S8 Ultra" />
<option name="screenDensity" value="320" />
<option name="screenX" value="1848" />
<option name="screenY" value="2960" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="google" />
<option name="codename" value="husky" />
<option name="id" value="husky" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 8 Pro" />
<option name="screenDensity" value="390" />
<option name="screenX" value="1008" />
<option name="screenY" value="2244" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="30" />
<option name="brand" value="motorola" />
<option name="codename" value="java" />
<option name="id" value="java" />
<option name="manufacturer" value="Motorola" />
<option name="name" value="G20" />
<option name="screenDensity" value="280" />
<option name="screenX" value="720" />
<option name="screenY" value="1600" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="google" />
<option name="codename" value="komodo" />
<option name="id" value="komodo" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 9 Pro XL" />
<option name="screenDensity" value="360" />
<option name="screenX" value="1008" />
<option name="screenY" value="2244" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="google" />
<option name="codename" value="lynx" />
<option name="id" value="lynx" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 7a" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="31" />
<option name="brand" value="google" />
<option name="codename" value="oriole" />
<option name="id" value="oriole" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 6" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="google" />
<option name="codename" value="panther" />
<option name="id" value="panther" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 7" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="samsung" />
<option name="codename" value="q5q" />
<option name="id" value="q5q" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy Z Fold5" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1812" />
<option name="screenY" value="2176" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="samsung" />
<option name="codename" value="q6q" />
<option name="id" value="q6q" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="SM-F956B" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1856" />
<option name="screenY" value="2160" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="30" />
<option name="brand" value="google" />
<option name="codename" value="r11" />
<option name="id" value="r11" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel Watch" />
<option name="screenDensity" value="320" />
<option name="screenX" value="384" />
<option name="screenY" value="384" />
<option name="type" value="WEAR_OS" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="30" />
<option name="brand" value="google" />
<option name="codename" value="redfin" />
<option name="id" value="redfin" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 5" />
<option name="screenDensity" value="440" />
<option name="screenX" value="1080" />
<option name="screenY" value="2340" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="google" />
<option name="codename" value="shiba" />
<option name="id" value="shiba" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 8" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="google" />
<option name="codename" value="tangorpro" />
<option name="id" value="tangorpro" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel Tablet" />
<option name="screenDensity" value="320" />
<option name="screenX" value="1600" />
<option name="screenY" value="2560" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="google" />
<option name="codename" value="tokay" />
<option name="id" value="tokay" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 9" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2424" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="29" />
<option name="brand" value="samsung" />
<option name="codename" value="x1q" />
<option name="id" value="x1q" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy S20" />
<option name="screenDensity" value="480" />
<option name="screenX" value="1440" />
<option name="screenY" value="3200" />
</PersistentDeviceSelectionData>
</list>
</option>
</component>
</project>
\ No newline at end of file
......@@ -2,6 +2,8 @@ package com.kaluwa.enterprises.babycare.activities;
import static com.kaluwa.enterprises.babycare.config.TokenSaver.clearToken;
import static com.kaluwa.enterprises.babycare.config.TokenSaver.getToken;
import static com.kaluwa.enterprises.babycare.constants.DocumentTypes.IMAGE;
import static com.kaluwa.enterprises.babycare.constants.TableNames.USERS;
import static com.kaluwa.enterprises.babycare.utils.Utils.animationChanger;
import static com.kaluwa.enterprises.babycare.utils.Utils.convertByteArrayToBitmap;
import static com.kaluwa.enterprises.babycare.utils.Utils.disableEditText;
......@@ -47,6 +49,7 @@ import com.kaluwa.enterprises.babycare.dto.UserDto;
import com.kaluwa.enterprises.babycare.dto.responseDto.AuthenticationDto;
import com.kaluwa.enterprises.babycare.dto.responseDto.ResponseDto;
import com.kaluwa.enterprises.babycare.error.ErrorDto;
import com.kaluwa.enterprises.babycare.service.DocumentApiService;
import com.kaluwa.enterprises.babycare.service.UserApiService;
import com.kaluwa.enterprises.babycare.utils.Utils;
import com.yalantis.ucrop.UCrop;
......@@ -76,6 +79,7 @@ public class UserProfileActivity extends AppCompatActivity {
private SpinKitView progressBar;
private View overlay;
private UserApiService userApiService;
private DocumentApiService documentApiService;
private AuthenticationDto authDto;
private ActivityResultLauncher<Intent> pickImageLauncher;
private ActivityResultLauncher<Intent> cropImageLauncher;
......@@ -96,6 +100,7 @@ public class UserProfileActivity extends AppCompatActivity {
Toast.makeText(this, "Error getting token, Please refresh", Toast.LENGTH_SHORT).show();
}
userApiService = ApiConfig.getInstance().getUserApi(authDto.getTokenDto().getToken());
documentApiService = ApiConfig.getInstance().getDocumentApi(authDto.getTokenDto().getToken());
// progress
progressBar = findViewById(R.id.progress_bar);
......@@ -204,7 +209,7 @@ public class UserProfileActivity extends AppCompatActivity {
RequestBody requestFile = RequestBody.create(MediaType.parse("image/jpeg"), compressedData);
MultipartBody.Part body = MultipartBody.Part.createFormData("image", "image.jpg", requestFile);
Call<ResponseDto> call = userApiService.uploadUserImage(authDto.getUserId(), body);
Call<ResponseDto> call = documentApiService.uploadUserImage(IMAGE, USERS, authDto.getUniqKey(), body);
call.enqueue(new Callback<ResponseDto>() {
@Override
public void onResponse(Call<ResponseDto> call, Response<ResponseDto> response) {
......@@ -243,7 +248,7 @@ public class UserProfileActivity extends AppCompatActivity {
}
private void loadUserProfileImage() {
Call<ResponseBody> call = userApiService.getImage(authDto.getUserId());
Call<ResponseBody> call = documentApiService.getImage(USERS, authDto.getUniqKey());
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
......
......@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.kaluwa.enterprises.babycare.service.AuthApiService;
import com.kaluwa.enterprises.babycare.service.BabyApiService;
import com.kaluwa.enterprises.babycare.service.DocumentApiService;
import com.kaluwa.enterprises.babycare.service.UserApiService;
import okhttp3.OkHttpClient;
......@@ -16,7 +17,7 @@ import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.jackson.JacksonConverterFactory;
public class ApiConfig {
private static final String BASE_URL = "http://192.168.63.103:8080/api/v1/baby-care/";
private static final String BASE_URL = "http://192.168.1.2:8080/api/v1/baby-care/";
private static ApiConfig instance;
private static Retrofit retrofitAuth = null;
private static Retrofit retrofitOther = null;
......@@ -71,4 +72,9 @@ public class ApiConfig {
AUTH_TOKEN = JWTToken;
return retrofitOther.create(BabyApiService.class);
}
public DocumentApiService getDocumentApi(String JWTToken) {
AUTH_TOKEN = JWTToken;
return retrofitOther.create(DocumentApiService.class);
}
}
package com.kaluwa.enterprises.babycare.constants;
public class DocumentTypes {
public static final String PROFILE_IMAGE = "profile_image";
public static final String BABY_PROFILE_IMAGE = "baby_profile_image";
public static final String IMAGE = "image";
}
package com.kaluwa.enterprises.babycare.constants;
public class TableNames {
public static final String USERS = "users";
public static final String BABIES = "babies";
}
......@@ -240,7 +240,7 @@ public class AddBabyDialog extends AppCompatDialogFragment {
etSEmergRelation = view.findViewById(R.id.abv_et_s_emergency_relationship);
etSEmergConNumber = view.findViewById(R.id.abv_et_s_emergency_con_number);
etNotes = view.findViewById(R.id.abv_et_notes);
ibPhoto = view.findViewById(R.id.abv_ib_photo);
// ibPhoto = view.findViewById(R.id.abv_ib_photo);
switchStatus = view.findViewById(R.id.abv_switch_status);
progressbar = view.findViewById(R.id.progress_bar);
......
package com.kaluwa.enterprises.babycare.dialogs;
import static com.kaluwa.enterprises.babycare.config.TokenSaver.getToken;
import static com.kaluwa.enterprises.babycare.constants.DocumentTypes.IMAGE;
import static com.kaluwa.enterprises.babycare.constants.TableNames.BABIES;
import static com.kaluwa.enterprises.babycare.constants.TableNames.USERS;
import static com.kaluwa.enterprises.babycare.utils.Utils.convertByteArrayToBitmap;
import static com.kaluwa.enterprises.babycare.utils.Utils.dpToPx;
import static com.kaluwa.enterprises.babycare.utils.Utils.getDateTimeFormatter;
import static com.kaluwa.enterprises.babycare.utils.Utils.loader;
import static com.kaluwa.enterprises.babycare.utils.Utils.setUpDatePicker;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
......@@ -20,27 +32,56 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatDialogFragment;
import androidx.appcompat.widget.SwitchCompat;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.github.ybq.android.spinkit.SpinKitView;
import com.google.android.material.imageview.ShapeableImageView;
import com.google.gson.Gson;
import com.kaluwa.enterprises.babycare.R;
import com.kaluwa.enterprises.babycare.activities.UserProfileActivity;
import com.kaluwa.enterprises.babycare.config.ApiConfig;
import com.kaluwa.enterprises.babycare.dto.BabyDto;
import com.kaluwa.enterprises.babycare.dto.responseDto.AuthenticationDto;
import com.kaluwa.enterprises.babycare.dto.responseDto.ResponseDto;
import com.kaluwa.enterprises.babycare.error.ErrorDto;
import com.kaluwa.enterprises.babycare.service.DocumentApiService;
import com.yalantis.ucrop.UCrop;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
import java.time.LocalDate;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class EditBabyDialog extends AppCompatDialogFragment {
private static final String TAG = "EditBabyDialogTAG";
EditBabyDialogInterface babyDialogInterface;
private EditText etFirstname, etLastname, dateDob, etSex, etWeight, etHeight, etBloodType, etEyeColor, etHairColor, etAllergies, etMediConditions, etMedication, etVaccinateRecs, etDocName, etDocContact, etHealthInsuranceInfo, dateFirstSmile, dateFirstTooth, dateFirstWord, dateFirstStep, etFavFoods, etDisFoods, etPEmergConName, etPEmergRelation, etPEmergConNumber, etSEmergConName, etSEmergRelation, etSEmergConNumber, etNotes;
private ImageButton ibPhoto;
private ShapeableImageView ibPhoto;
private SwitchCompat switchStatus;
private View overlay;
private SpinKitView progressbar;
private BabyDto babyDto;
private ActivityResultLauncher<Intent> pickImageLauncher;
private ActivityResultLauncher<Intent> cropImageLauncher;
private AuthenticationDto authDto;
private DocumentApiService documentApiService;
public EditBabyDialog(BabyDto babyDto) {
this.babyDto = babyDto;
......@@ -68,11 +109,21 @@ public class EditBabyDialog extends AppCompatDialogFragment {
builder.setCustomTitle(title);
// initialize user api service
try {
authDto = getToken(getContext());
} catch (JsonProcessingException e) {
Log.e(TAG, "Error: " + e.getMessage());
Toast.makeText(getContext(), "Error getting token, Please refresh", Toast.LENGTH_SHORT).show();
}
documentApiService = ApiConfig.getInstance().getDocumentApi(authDto.getTokenDto().getToken());
// find views by id
findViews(view);
// Pre-fill data
prefillData();
loadBabyImage();
AlertDialog dialog = builder.create();
......@@ -105,9 +156,176 @@ public class EditBabyDialog extends AppCompatDialogFragment {
dialog.getWindow().setAttributes(layoutParams);
});
// register launchers
launcherReg();
// open image selector
ibPhoto.setOnClickListener(v -> {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickImageLauncher.launch(intent);
});
return dialog;
}
private void launcherReg() {
// Register the ActivityResultLauncher for picking an image
pickImageLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
if (result.getResultCode() == Activity.RESULT_OK) {
Intent data = result.getData();
if (data != null) {
Uri selectedImageUri = data.getData();
if (selectedImageUri != null) {
startCrop(selectedImageUri);
}
}
}
});
// Register the ActivityResultLauncher for cropping the image
cropImageLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
if (result.getResultCode() == Activity.RESULT_OK) {
Intent data = result.getData();
if (data != null) {
Uri resultUri = UCrop.getOutput(data);
if (resultUri != null) {
// Upload the cropped image to the server
ibPhoto.setImageURI(resultUri);
uploadImageToServer(resultUri);
}
}
} else if (result.getResultCode() == UCrop.RESULT_ERROR) {
final Throwable cropError = UCrop.getError(result.getData());
// Handle the error
Toast.makeText(getContext(), "Something went wrong: " + cropError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
private void startCrop(@NonNull Uri uri) {
// Generate a unique destination file name based on current time
String destinationFileName = "CroppedImage_" + System.currentTimeMillis() + ".jpg";
UCrop uCrop = UCrop.of(uri, Uri.fromFile(new File(getContext().getCacheDir(), destinationFileName)));
uCrop.withAspectRatio(1, 1);
uCrop.withOptions(getUCropOptions());
cropImageLauncher.launch(uCrop.getIntent(getContext()));
}
private UCrop.Options getUCropOptions() {
UCrop.Options options = new UCrop.Options();
options.setCircleDimmedLayer(true);
options.setShowCropFrame(false);
options.setShowCropGrid(false);
return options;
}
private void uploadImageToServer(Uri imageUri) {
Bitmap originalBitmap = BitmapFactory.decodeFile(imageUri.getPath());
int maxWidth = 800; // Set your desired maximum width
int maxHeight = 800; // Set your desired maximum height
Bitmap resizedBitmap = Bitmap.createScaledBitmap(originalBitmap, maxWidth, maxHeight, true);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 80, outputStream); // Adjust the quality (80 is just an example)
byte[] compressedData = outputStream.toByteArray();
// Create RequestBody for the compressed image
RequestBody requestFile = RequestBody.create(MediaType.parse("image/jpeg"), compressedData);
MultipartBody.Part body = MultipartBody.Part.createFormData("image", "image.jpg", requestFile);
Call<ResponseDto> call = documentApiService.uploadUserImage(IMAGE, BABIES, babyDto.getUniqKey(), body);
call.enqueue(new Callback<ResponseDto>() {
@Override
public void onResponse(Call<ResponseDto> call, Response<ResponseDto> response) {
if (response.isSuccessful()) {
loadBabyImage();
loader(overlay, progressbar, false);
} else {
try {
Gson gson = new Gson();
assert response.errorBody() != null;
String errorBodyString = response.errorBody().string();
// Check if the error body is in JSON format
if (errorBodyString.startsWith("{")) {
ErrorDto errorDto = gson.fromJson(errorBodyString, ErrorDto.class);
Toast.makeText(getContext(), errorDto.getMessage(), Toast.LENGTH_LONG).show();
} else {
// If the error body is not in JSON format, display a generic error message
Log.e(TAG, errorBodyString);
Toast.makeText(getContext(), "An unexpected error occurred", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Log.e(TAG, "else-error: " + e.getMessage());
Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
loader(overlay, progressbar, false);
}
}
@Override
public void onFailure(Call<ResponseDto> call, Throwable t) {
Toast.makeText(getContext(), "Error to Failure", Toast.LENGTH_LONG).show();
loader(overlay, progressbar, false);
}
});
}
private void loadBabyImage() {
Call<ResponseBody> call = documentApiService.getImage(BABIES, babyDto.getUniqKey());
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.isSuccessful()) {
try {
if (response.body() != null) {
InputStream inputStream = response.body().byteStream();
Bitmap bitmap = convertByteArrayToBitmap(inputStream);
ibPhoto.setImageBitmap(bitmap);
} else {
Log.e(TAG, "Response body is null");
}
} catch (Exception e) {
Log.e(TAG, "Error occurred: " + e.getMessage());
Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
loader(overlay, progressbar, false);
} else {
try {
Gson gson = new Gson();
assert response.errorBody() != null;
String errorBodyString = response.errorBody().string();
// Check if the error body is in JSON format
if (errorBodyString.startsWith("{")) {
ErrorDto errorDto = gson.fromJson(errorBodyString, ErrorDto.class);
Toast.makeText(getContext(), errorDto.getMessage(), Toast.LENGTH_LONG).show();
} else {
// If the error body is not in JSON format, display a generic error message
Log.e(TAG, errorBodyString);
Toast.makeText(getContext(), "An unexpected error occurred", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Log.e(TAG, "else-error: " + e.getMessage());
Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
loader(overlay, progressbar, false);
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Toast.makeText(getContext(), "Error to Failure", Toast.LENGTH_LONG).show();
loader(overlay, progressbar, false);
}
});
}
// Method to pre-fill the data
private void prefillData() {
if (babyDto != null) {
......@@ -156,7 +374,7 @@ public class EditBabyDialog extends AppCompatDialogFragment {
BabyDto baby = new BabyDto();
baby.setBabyId(babyDto.getBabyId());
baby.setSys_validated(false);
String firstname, lastname, dob, sex, weight, height, bType, eyeColor, hairColor, allergies, medicalConditions, medications, vaccinateRecs, docName, docContact, healthInsuInfo, firstSmile, firstTooth, firstWord, firstStep, favFoods, disFoods, pEmergeConName, pEmergeRelationship, pEmergeContact, sEmergeConName, sEmergeRelationship, sEmergeContact, notes;
String firstname, lastname, dob, sex, weight, height, bType, eyeColor, hairColor, allergies, medicalConditions, medications, vaccinateRecs, docName, docContact, healthInsuInfo, firstSmile, firstTooth, firstWord, firstStep, favFoods, disFoods, pEmergeConName, pEmergeRelationship, pEmergeContact, sEmergeConName, sEmergeRelationship, sEmergeContact, notes, uniqKey;
firstname = etFirstname.getText().toString();
lastname = etLastname.getText().toString();
......@@ -240,6 +458,7 @@ public class EditBabyDialog extends AppCompatDialogFragment {
baby.setSecondaryEmergencyRelationship(sEmergeRelationship);
baby.setSecondaryEmergencyContactNumber(sEmergeContact);
baby.setNotes(notes);
baby.setUniqKey(babyDto.getUniqKey());
baby.setSys_validated(true);
}
......@@ -283,7 +502,7 @@ public class EditBabyDialog extends AppCompatDialogFragment {
etSEmergRelation = view.findViewById(R.id.ebv_et_s_emergency_relationship);
etSEmergConNumber = view.findViewById(R.id.ebv_et_s_emergency_con_number);
etNotes = view.findViewById(R.id.ebv_et_notes);
// ibPhoto = view.findViewById(R.id.ebv_ib_photo);
ibPhoto = view.findViewById(R.id.ebv_ib_photo);
switchStatus = view.findViewById(R.id.ebv_switch_status);
progressbar = view.findViewById(R.id.progress_bar);
......
......@@ -45,6 +45,7 @@ public class BabyDto {
private String secondaryEmergencyRelationship;
private String secondaryEmergencyContactNumber;
private String notes;
private String uniqKey;
private UserDto user;
private Long userId;
private Long documentId;
......
......@@ -17,5 +17,6 @@ public class UserDto {
private String phone;
private String role;
private String status;
private String uniqKey;
private LocalDate dob;
}
\ No newline at end of file
......@@ -15,5 +15,6 @@ public class AuthenticationDto {
private String phone;
private String role;
private String status;
private String uniqKey;
private TokenDto tokenDto;
}
\ No newline at end of file
package com.kaluwa.enterprises.babycare.service;
import com.kaluwa.enterprises.babycare.dto.responseDto.ResponseDto;
import okhttp3.MultipartBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Multipart;
import retrofit2.http.PUT;
import retrofit2.http.Part;
import retrofit2.http.Path;
public interface DocumentApiService {
@Multipart
@PUT("document/{docType}/{table}/{uniqKey}")
Call<ResponseDto> uploadUserImage(@Path("docType") String docType, @Path("table") String table, @Path("uniqKey") String uniqKey, @Part MultipartBody.Part image);
@GET("document/{table}/{uniqKey}")
Call<ResponseBody> getImage(@Path("table") String table, @Path("uniqKey") String uniqKey);
}
......@@ -21,11 +21,4 @@ public interface UserApiService {
@PUT("user/{userId}")
Call<UserDto> updateUserById(@Path("userId") Long userId, @Body UserDto user);
@Multipart
@PUT("user/image/{userId}")
Call<ResponseDto> uploadUserImage(@Path("userId") Long userId, @Part MultipartBody.Part image);
@GET("user/image/{userId}")
Call<ResponseBody> getImage(@Path("userId") Long userId);
}
......@@ -77,22 +77,22 @@
android:textSize="16sp"
android:fontFamily="@font/kanit_regular"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="Photo"
android:fontFamily="@font/kanit_regular"
android:paddingStart="5dp"
android:paddingEnd="2dp"
android:paddingTop="6dp"/>
<ImageButton
android:id="@+id/abv_ib_photo"
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@drawable/ic_add_32"
android:contentDescription="baby_uploaded_photo"/>
<!-- <TextView-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:textSize="16sp"-->
<!-- android:text="Photo"-->
<!-- android:fontFamily="@font/kanit_regular"-->
<!-- android:paddingStart="5dp"-->
<!-- android:paddingEnd="2dp"-->
<!-- android:paddingTop="6dp"/>-->
<!-- <ImageButton-->
<!-- android:id="@+id/abv_ib_photo"-->
<!-- android:layout_width="120dp"-->
<!-- android:layout_height="120dp"-->
<!-- android:src="@drawable/ic_add_32"-->
<!-- android:contentDescription="baby_uploaded_photo"/>-->
<LinearLayout
android:layout_width="match_parent"
......
......@@ -41,14 +41,17 @@
android:background="@drawable/borders"
android:padding="8dp">
<ImageButton
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/ebv_ib_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxHeight="200dp"
android:src="@drawable/ic_add_32"
android:layout_width="160dp"
android:layout_height="160dp"
android:maxHeight="160dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:src="@drawable/foreground"
app:shapeAppearanceOverlay="@style/RoundImage"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:layout_gravity="center"
android:contentDescription="baby_uploaded_photo"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment