Commit 1ad4e397 authored by Chamod Ishankha's avatar Chamod Ishankha

add baby api connect

parent 644d4077
...@@ -3,7 +3,20 @@ ...@@ -3,7 +3,20 @@
<component name="deploymentTargetDropDown"> <component name="deploymentTargetDropDown">
<value> <value>
<entry key="app"> <entry key="app">
<State /> <State>
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="adb-AYAV6R3925006878-kh1m4J._adb-tls-connect._tcp" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-05-21T16:09:48.003353300Z" />
</State>
</entry> </entry>
</value> </value>
</component> </component>
......
...@@ -45,6 +45,8 @@ dependencies { ...@@ -45,6 +45,8 @@ dependencies {
implementation(libs.jackson.databind) implementation(libs.jackson.databind)
implementation(libs.ucrop) implementation(libs.ucrop)
implementation(libs.swiperefreshlayout) implementation(libs.swiperefreshlayout)
implementation(libs.converter.jackson)
implementation(libs.jackson.datatype.jsr310)
testImplementation(libs.junit) testImplementation(libs.junit)
androidTestImplementation(libs.ext.junit) androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core) androidTestImplementation(libs.espresso.core)
......
...@@ -31,6 +31,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; ...@@ -31,6 +31,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.github.ybq.android.spinkit.SpinKitView; import com.github.ybq.android.spinkit.SpinKitView;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.gson.Gson;
import com.kaluwa.enterprises.babycare.MainActivity; import com.kaluwa.enterprises.babycare.MainActivity;
import com.kaluwa.enterprises.babycare.R; import com.kaluwa.enterprises.babycare.R;
import com.kaluwa.enterprises.babycare.adapter.BabyDashboardAdapter; import com.kaluwa.enterprises.babycare.adapter.BabyDashboardAdapter;
...@@ -38,6 +39,7 @@ import com.kaluwa.enterprises.babycare.config.ApiConfig; ...@@ -38,6 +39,7 @@ import com.kaluwa.enterprises.babycare.config.ApiConfig;
import com.kaluwa.enterprises.babycare.dialogs.AddBabyDialog; import com.kaluwa.enterprises.babycare.dialogs.AddBabyDialog;
import com.kaluwa.enterprises.babycare.dto.BabyDto; import com.kaluwa.enterprises.babycare.dto.BabyDto;
import com.kaluwa.enterprises.babycare.dto.responseDto.AuthenticationDto; import com.kaluwa.enterprises.babycare.dto.responseDto.AuthenticationDto;
import com.kaluwa.enterprises.babycare.error.ErrorDto;
import com.kaluwa.enterprises.babycare.service.BabyApiService; import com.kaluwa.enterprises.babycare.service.BabyApiService;
import java.time.LocalDate; import java.time.LocalDate;
...@@ -45,6 +47,10 @@ import java.time.format.DateTimeFormatter; ...@@ -45,6 +47,10 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class BabyDashboardActivity extends AppCompatActivity implements AddBabyDialog.BabyDialogInterface { public class BabyDashboardActivity extends AppCompatActivity implements AddBabyDialog.BabyDialogInterface {
private final static String TAG = "BabyDashboardActivity"; private final static String TAG = "BabyDashboardActivity";
...@@ -56,6 +62,8 @@ public class BabyDashboardActivity extends AppCompatActivity implements AddBabyD ...@@ -56,6 +62,8 @@ public class BabyDashboardActivity extends AppCompatActivity implements AddBabyD
private View overlay; private View overlay;
private SpinKitView progressbar; private SpinKitView progressbar;
private BabyApiService babyApiService; private BabyApiService babyApiService;
private BabyDashboardAdapter adapter;
private List<BabyDto> babyDtoList = new ArrayList<>();
@SuppressLint("NewApi") @SuppressLint("NewApi")
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -81,28 +89,10 @@ public class BabyDashboardActivity extends AppCompatActivity implements AddBabyD ...@@ -81,28 +89,10 @@ public class BabyDashboardActivity extends AppCompatActivity implements AddBabyD
overlay = findViewById(R.id.overlay); overlay = findViewById(R.id.overlay);
progressbar = findViewById(R.id.progress_bar); progressbar = findViewById(R.id.progress_bar);
List<BabyDto> babyDtoList = new ArrayList<>(); // load data
BabyDto baby1 = new BabyDto(); loadData();
baby1.setFirstName("Chamod");
baby1.setLastName("Ishankha"); adapter = new BabyDashboardAdapter(this, babyDtoList);
baby1.setDob(LocalDate.parse("2000/07/23", DateTimeFormatter.ofPattern("yyyy/MM/dd")));
baby1.setSex("Male");
baby1.setActive(true);
BabyDto baby2 = new BabyDto();
baby2.setFirstName("Yohani");
baby2.setLastName("Madusha");
baby2.setDob(LocalDate.parse("2000/11/01", DateTimeFormatter.ofPattern("yyyy/MM/dd")));
baby2.setSex("Female");
baby2.setActive(false);
baby2.setNotes("My little cute daughter, Love you my darling.");
babyDtoList.add(baby1);
babyDtoList.add(baby2);
if (babyDtoList.isEmpty()) {
tvNoContent.setVisibility(View.VISIBLE);
}
BabyDashboardAdapter adapter = new BabyDashboardAdapter(this, babyDtoList);
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setLayoutManager(new LinearLayoutManager(this));
...@@ -112,6 +102,68 @@ public class BabyDashboardActivity extends AppCompatActivity implements AddBabyD ...@@ -112,6 +102,68 @@ public class BabyDashboardActivity extends AppCompatActivity implements AddBabyD
}); });
} }
private void loadData() {
Call<List<BabyDto>> call = babyApiService.getAllBabies();
loader(overlay, progressbar, true);
noContentCall();
call.enqueue(new Callback<List<BabyDto>>() {
@Override
public void onResponse(Call<List<BabyDto>> call, Response<List<BabyDto>> response) {
if (response.isSuccessful()) {
List<BabyDto> newBabyDtoList = new ArrayList<>();
if (response.body() != null) {
newBabyDtoList = response.body();
}
// Assuming babyDtoList is a class member
// Check for changes and update the list accordingly
if (babyDtoList == null) {
babyDtoList = newBabyDtoList;
adapter.notifyItemRangeInserted(0, newBabyDtoList.size());
} else {
// Here, you might want to implement a diffing algorithm
// For simplicity, let's assume you replace the entire list
babyDtoList.clear();
babyDtoList.addAll(newBabyDtoList);
adapter.notifyDataSetChanged();
}
noContentCall();
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(BabyDashboardActivity.this, 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(BabyDashboardActivity.this, "An unexpected error occurred", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Log.e(TAG, "else-error: " + e.getMessage());
Toast.makeText(BabyDashboardActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
noContentCall();
loader(overlay, progressbar, false);
}
}
@Override
public void onFailure(Call<List<BabyDto>> call, Throwable throwable) {
noContentCall();
Log.e(TAG, throwable.getMessage());
Toast.makeText(BabyDashboardActivity.this, "Error to Failure", Toast.LENGTH_LONG).show();
loader(overlay, progressbar, false);
}
});
}
private void openAddBabyDialog() { private void openAddBabyDialog() {
AddBabyDialog addbabyDialog = new AddBabyDialog(); AddBabyDialog addbabyDialog = new AddBabyDialog();
addbabyDialog.show(getSupportFragmentManager(), "ADD_BABY_DIALOG"); addbabyDialog.show(getSupportFragmentManager(), "ADD_BABY_DIALOG");
...@@ -191,17 +243,67 @@ public class BabyDashboardActivity extends AppCompatActivity implements AddBabyD ...@@ -191,17 +243,67 @@ public class BabyDashboardActivity extends AppCompatActivity implements AddBabyD
} }
@Override @Override
public void parseValues(BabyDto dto, AlertDialog dialog, View overlay, SpinKitView progressbar) { public void parseValues(BabyDto baby, AlertDialog dialog, View overlay, SpinKitView progressbar) {
dto.setUserId(authDto.getUserId()); baby.setUserId(authDto.getUserId());
Button positiveBtn = dialog.getButton(DialogInterface.BUTTON_POSITIVE); Button positiveBtn = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
Button negativeBtn = dialog.getButton(DialogInterface.BUTTON_NEGATIVE); Button negativeBtn = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
loader(overlay, progressbar, true); loader(overlay, progressbar, true);
positiveBtn.setEnabled(false); positiveBtn.setEnabled(false);
negativeBtn.setEnabled(false); negativeBtn.setEnabled(false);
Call<BabyDto> call = babyApiService.addBaby(baby);
call.enqueue(new Callback<BabyDto>() {
@Override
public void onResponse(Call<BabyDto> call, Response<BabyDto> response) {
if (response.isSuccessful()) {
loadData();
Toast.makeText(BabyDashboardActivity.this, "New baby added to your list.", Toast.LENGTH_SHORT).show();
dialog.dismiss();
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(BabyDashboardActivity.this, 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(BabyDashboardActivity.this, "An unexpected error occurred", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Log.e(TAG, "else-error: " + e.getMessage());
Toast.makeText(BabyDashboardActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
positiveBtn.setEnabled(true);
negativeBtn.setEnabled(true);
loader(overlay, progressbar, false);
}
}
@Override
public void onFailure(Call<BabyDto> call, Throwable throwable) {
Toast.makeText(BabyDashboardActivity.this, "Error to Failure", Toast.LENGTH_LONG).show();
positiveBtn.setEnabled(true);
negativeBtn.setEnabled(true);
loader(overlay, progressbar, false);
}
});
// TODO // TODO
// make api caller
// make photo selector // make photo selector
// make dropdowns // make dropdowns
} }
void noContentCall() {
if (babyDtoList.isEmpty()) {
tvNoContent.setVisibility(View.VISIBLE);
} else {
tvNoContent.setVisibility(View.GONE);
}
}
} }
\ No newline at end of file
...@@ -385,7 +385,7 @@ public class UserProfileActivity extends AppCompatActivity { ...@@ -385,7 +385,7 @@ public class UserProfileActivity extends AppCompatActivity {
userDto.setPhone(mobileNumber); userDto.setPhone(mobileNumber);
if (!TextUtils.isEmpty(etDob.getText().toString())) { if (!TextUtils.isEmpty(etDob.getText().toString())) {
LocalDate dob = LocalDate.parse(etDob.getText().toString(), getDateTimeFormatter()); LocalDate dob = LocalDate.parse(etDob.getText().toString(), getDateTimeFormatter());
userDto.setDob(dob.toString()); userDto.setDob(dob);
} }
} }
......
package com.kaluwa.enterprises.babycare.adapter; package com.kaluwa.enterprises.babycare.adapter;
import static com.kaluwa.enterprises.babycare.utils.Utils.babyAgeCalculate;
import static com.kaluwa.enterprises.babycare.utils.Utils.calculateAge; import static com.kaluwa.enterprises.babycare.utils.Utils.calculateAge;
import static com.kaluwa.enterprises.babycare.utils.Utils.convertByteArrayToBitmap; import static com.kaluwa.enterprises.babycare.utils.Utils.convertByteArrayToBitmap;
...@@ -25,6 +26,7 @@ import com.kaluwa.enterprises.babycare.activities.UserProfileActivity; ...@@ -25,6 +26,7 @@ import com.kaluwa.enterprises.babycare.activities.UserProfileActivity;
import com.kaluwa.enterprises.babycare.dto.BabyDto; import com.kaluwa.enterprises.babycare.dto.BabyDto;
import java.io.InputStream; import java.io.InputStream;
import java.time.LocalDate;
import java.util.List; import java.util.List;
public class BabyDashboardAdapter extends RecyclerView.Adapter<BabyDashboardAdapter.BabyDashboardItemHolder> { public class BabyDashboardAdapter extends RecyclerView.Adapter<BabyDashboardAdapter.BabyDashboardItemHolder> {
...@@ -49,21 +51,32 @@ public class BabyDashboardAdapter extends RecyclerView.Adapter<BabyDashboardAdap ...@@ -49,21 +51,32 @@ public class BabyDashboardAdapter extends RecyclerView.Adapter<BabyDashboardAdap
@Override @Override
public void onBindViewHolder(@NonNull BabyDashboardAdapter.BabyDashboardItemHolder holder, int position) { public void onBindViewHolder(@NonNull BabyDashboardAdapter.BabyDashboardItemHolder holder, int position) {
BabyDto babyDto = babyList.get(position); BabyDto babyDto = babyList.get(position);
holder.tvBabyName.setText(babyDto.getFirstName() + " " + babyDto.getLastName()); String firstname = babyDto.getFirstName();
Double age = calculateAge(babyDto.getDob(), "byMonths"); String lastname = babyDto.getLastName();
holder.tvBabyAge.setText(age != null ? age + " months" : "Not Available"); LocalDate dob = babyDto.getDob();
holder.tvBabySex.setText(babyDto.getSex()); String sex = babyDto.getSex();
if (!TextUtils.isEmpty(babyDto.getNotes())) { String notes = babyDto.getNotes();
holder.tvBabyDDespContent.setText(babyDto.getNotes()); Boolean isActive = babyDto.getIsActive();
InputStream imageData = babyDto.getImageData();
if (lastname != null) {
holder.tvBabyName.setText(firstname + " " + lastname);
} else {
holder.tvBabyName.setText(firstname);
}
String age = babyAgeCalculate(dob);
holder.tvBabyAge.setText(age != null ? age : "Not Available");
holder.tvBabySex.setText(sex);
if (!TextUtils.isEmpty(notes)) {
holder.tvBabyDDespContent.setText(notes);
} else { } else {
holder.tvBabyDDespTitle.setText("Status >"); holder.tvBabyDDespTitle.setText("Status >");
holder.tvBabyDDespContent.setTextColor(babyDto.isActive() ? context.getResources().getColor(R.color.success_green) : context.getResources().getColor(R.color.cancel_red)); holder.tvBabyDDespContent.setTextColor(isActive ? context.getResources().getColor(R.color.success_green) : context.getResources().getColor(R.color.cancel_red));
holder.tvBabyDDespContent.setText(babyDto.isActive() ? "Active" : "Inactive"); holder.tvBabyDDespContent.setText(isActive ? "Active" : "Inactive");
} }
if (babyDto.getImageData() != null) { if (imageData != null) {
try { try {
InputStream inputStream = babyDto.getImageData(); Bitmap bitmap = convertByteArrayToBitmap(imageData);
Bitmap bitmap = convertByteArrayToBitmap(inputStream);
holder.ivBabyImage.setImageBitmap(bitmap); holder.ivBabyImage.setImageBitmap(bitmap);
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Error occurred: " + e.getMessage()); Log.e(TAG, "Error occurred: " + e.getMessage());
......
...@@ -2,6 +2,9 @@ package com.kaluwa.enterprises.babycare.config; ...@@ -2,6 +2,9 @@ package com.kaluwa.enterprises.babycare.config;
import static com.kaluwa.enterprises.babycare.config.TokenSaver.getToken; import static com.kaluwa.enterprises.babycare.config.TokenSaver.getToken;
import com.fasterxml.jackson.databind.ObjectMapper;
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.AuthApiService;
import com.kaluwa.enterprises.babycare.service.BabyApiService; import com.kaluwa.enterprises.babycare.service.BabyApiService;
import com.kaluwa.enterprises.babycare.service.UserApiService; import com.kaluwa.enterprises.babycare.service.UserApiService;
...@@ -10,6 +13,7 @@ import okhttp3.OkHttpClient; ...@@ -10,6 +13,7 @@ import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import retrofit2.Retrofit; import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.jackson.JacksonConverterFactory;
public class ApiConfig { public class ApiConfig {
private static final String BASE_URL = "http://192.168.1.2:8080/api/v1/baby-care/"; private static final String BASE_URL = "http://192.168.1.2:8080/api/v1/baby-care/";
...@@ -20,9 +24,14 @@ public class ApiConfig { ...@@ -20,9 +24,14 @@ public class ApiConfig {
private ApiConfig() { private ApiConfig() {
OkHttpClient authHttpClient = new OkHttpClient.Builder().build(); OkHttpClient authHttpClient = new OkHttpClient.Builder().build();
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
retrofitAuth = new Retrofit.Builder() retrofitAuth = new Retrofit.Builder()
.baseUrl(BASE_URL) .baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(JacksonConverterFactory.create(mapper))
.client(authHttpClient) .client(authHttpClient)
.build(); .build();
...@@ -37,7 +46,7 @@ public class ApiConfig { ...@@ -37,7 +46,7 @@ public class ApiConfig {
.build(); .build();
retrofitOther = new Retrofit.Builder() retrofitOther = new Retrofit.Builder()
.baseUrl(BASE_URL) .baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(JacksonConverterFactory.create(mapper))
.client(otherHttpClient) .client(otherHttpClient)
.build(); .build();
} }
......
...@@ -88,7 +88,7 @@ public class AddBabyDialog extends AppCompatDialogFragment { ...@@ -88,7 +88,7 @@ public class AddBabyDialog extends AppCompatDialogFragment {
int screenHeight = displayMetrics.heightPixels; int screenHeight = displayMetrics.heightPixels;
// Convert 30dp to pixels // Convert 30dp to pixels
int margin = dpToPx(getContext(), 100); int margin = dpToPx(getContext(), 65);
// Calculate the available height // Calculate the available height
int availableHeight = screenHeight - (2 * margin); int availableHeight = screenHeight - (2 * margin);
...@@ -159,8 +159,7 @@ public class AddBabyDialog extends AppCompatDialogFragment { ...@@ -159,8 +159,7 @@ public class AddBabyDialog extends AppCompatDialogFragment {
baby.setLastName(lastname); baby.setLastName(lastname);
baby.setDob(LocalDate.parse(dob, getDateTimeFormatter())); baby.setDob(LocalDate.parse(dob, getDateTimeFormatter()));
baby.setSex(sex); baby.setSex(sex);
baby.setPhotoData(null); baby.setIsActive(switchStatus.isChecked());
baby.setActive(switchStatus.isChecked());
if (!TextUtils.isEmpty(weight)) { if (!TextUtils.isEmpty(weight)) {
baby.setWeight(Float.parseFloat(weight)); baby.setWeight(Float.parseFloat(weight));
} }
......
package com.kaluwa.enterprises.babycare.dto; package com.kaluwa.enterprises.babycare.dto;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.InputStream; import java.io.InputStream;
import java.time.LocalDate;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
...@@ -10,15 +13,15 @@ import lombok.NoArgsConstructor; ...@@ -10,15 +13,15 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class BabyDto { public class BabyDto {
private Long babyId;
private String firstName; private String firstName;
private String lastName; private String lastName;
private Object dob; private LocalDate dob;
private String sex; private String sex;
private String status; private String status;
private boolean isActive; private Boolean isActive;
private byte[] photoData; private Float weight;
private float weight; private Float height;
private float height;
private String bloodType; private String bloodType;
private String eyeColor; private String eyeColor;
private String hairColor; private String hairColor;
...@@ -29,10 +32,10 @@ public class BabyDto { ...@@ -29,10 +32,10 @@ public class BabyDto {
private String docName; private String docName;
private String docContactNumber; private String docContactNumber;
private String healthInsuranceInfo; private String healthInsuranceInfo;
private Object firstSmileDate; private LocalDate firstSmileDate;
private Object firstToothDate; private LocalDate firstToothDate;
private Object firstWordDate; private LocalDate firstWordDate;
private Object firstStepDate; private LocalDate firstStepDate;
private String favFoods; private String favFoods;
private String foodsDislikes; private String foodsDislikes;
private String primaryEmergencyContactName; private String primaryEmergencyContactName;
...@@ -44,8 +47,11 @@ public class BabyDto { ...@@ -44,8 +47,11 @@ public class BabyDto {
private String notes; private String notes;
private UserDto user; private UserDto user;
private Long userId; private Long userId;
private Long documentId;
@JsonIgnore
private InputStream imageData; private InputStream imageData;
@JsonIgnore
private boolean sys_validated; private boolean sys_validated;
} }
...@@ -17,5 +17,5 @@ public class UserDto { ...@@ -17,5 +17,5 @@ public class UserDto {
private String phone; private String phone;
private String role; private String role;
private String status; private String status;
private Object dob; private LocalDate dob;
} }
\ No newline at end of file
package com.kaluwa.enterprises.babycare.service; package com.kaluwa.enterprises.babycare.service;
import com.kaluwa.enterprises.babycare.dto.BabyDto;
import java.util.List;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
public interface BabyApiService { public interface BabyApiService {
@GET("baby")
Call<List<BabyDto>> getAllBabies();
@POST("baby")
Call<BabyDto> addBaby(@Body BabyDto baby);
} }
...@@ -189,6 +189,31 @@ public class Utils { ...@@ -189,6 +189,31 @@ public class Utils {
return age; return age;
} }
@SuppressLint("NewApi")
public static String babyAgeCalculate(LocalDate dob) {
if (dob == null) {
Log.e(TAG, "Invalid date of birth");
return null;
}
LocalDate currentDate = LocalDate.now();
Period period = Period.between(dob, currentDate);
int totalMonths = period.getYears() * 12 + period.getMonths();
int totalDays = period.getDays();
if (totalMonths <= 12) {
return totalMonths + " months " + totalDays + " days";
} else {
int years = totalMonths / 12;
int remainingMonths = totalMonths % 12;
return years + " years " + remainingMonths + " months " + totalDays + " days";
}
}
public static Bitmap convertByteArrayToBitmap(InputStream stream) { public static Bitmap convertByteArrayToBitmap(InputStream stream) {
try { try {
return BitmapFactory.decodeStream(stream); return BitmapFactory.decodeStream(stream);
...@@ -207,10 +232,10 @@ public class Utils { ...@@ -207,10 +232,10 @@ public class Utils {
public static DateTimeFormatter getDateTimeFormatter() { public static DateTimeFormatter getDateTimeFormatter() {
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder() DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder()
.parseCaseInsensitive().parseLenient() .parseCaseInsensitive().parseLenient()
.appendPattern("[d/M/yyyy]") // .appendPattern("[d/M/yyyy]")
.appendPattern("[dd MMM yyyy]") // .appendPattern("[dd MMM yyyy]")
.appendPattern("[dd/MM/yyyy]") .appendPattern("[dd/MM/yyyy]");
.appendPattern("[dd/M/yyyy]"); // .appendPattern("[dd/M/yyyy]");
return builder.toFormatter(Locale.ENGLISH); return builder.toFormatter(Locale.ENGLISH);
} }
......
...@@ -5,13 +5,9 @@ ...@@ -5,13 +5,9 @@
<item name="cornerSize">50%</item> <item name="cornerSize">50%</item>
</style> </style>
<!-- Custom AlertDialog theme --> <style name="CustomDialogAnimation">
<style name="CustomAlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert"> <!-- Define your custom enter animation here -->
<item name="buttonBarStyle">@style/CustomButtonBar</item> <item name="android:windowEnterAnimation">@anim/fade_in</item>
</style> <!-- You can add more animations like scale, translate, etc. -->
<!-- Custom button bar style -->
<style name="CustomButtonBar" parent="Widget.AppCompat.ButtonBar.AlertDialog">
<item name="android:background">?attr/colorPrimary</item> <!-- Change this to your desired color -->
</style> </style>
</resources> </resources>
\ No newline at end of file
...@@ -5,13 +5,10 @@ ...@@ -5,13 +5,10 @@
<item name="cornerSize">50%</item> <item name="cornerSize">50%</item>
</style> </style>
<!-- Custom AlertDialog theme --> <style name="CustomDialogAnimation">
<style name="CustomAlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert"> <!-- Define your custom enter animation here -->
<item name="buttonBarStyle">@style/CustomButtonBar</item> <item name="android:windowEnterAnimation">@anim/fade_in</item>
<!-- You can add more animations like scale, translate, etc. -->
</style> </style>
<!-- Custom button bar style -->
<style name="CustomButtonBar" parent="Widget.AppCompat.ButtonBar.AlertDialog">
<item name="android:background">?attr/colorPrimary</item> <!-- Change this to your desired color -->
</style>
</resources> </resources>
\ No newline at end of file
...@@ -14,6 +14,8 @@ retrofit2 = "2.11.0" ...@@ -14,6 +14,8 @@ retrofit2 = "2.11.0"
jacksonDatabind = "2.17.1" jacksonDatabind = "2.17.1"
materialVersion = "1.13.0-alpha02" materialVersion = "1.13.0-alpha02"
swiperefreshlayout = "1.2.0-alpha01" swiperefreshlayout = "1.2.0-alpha01"
converterJackson = "2.11.0"
jacksonDatatypeJsr310 = "2.17.1"
[libraries] [libraries]
junit = { group = "junit", name = "junit", version.ref = "junit" } junit = { group = "junit", name = "junit", version.ref = "junit" }
...@@ -32,6 +34,8 @@ convertor-gson = { group = "com.squareup.retrofit2", name = "converter-gson", ve ...@@ -32,6 +34,8 @@ convertor-gson = { group = "com.squareup.retrofit2", name = "converter-gson", ve
jackson-databind = { group = "com.fasterxml.jackson.core", name = "jackson-databind", version.ref = "jacksonDatabind" } jackson-databind = { group = "com.fasterxml.jackson.core", name = "jackson-databind", version.ref = "jacksonDatabind" }
ucrop = { group = "com.github.yalantis", name = "ucrop", version = "2.2.9" } ucrop = { group = "com.github.yalantis", name = "ucrop", version = "2.2.9" }
swiperefreshlayout = { group = "androidx.swiperefreshlayout", name = "swiperefreshlayout", version.ref = "swiperefreshlayout" } swiperefreshlayout = { group = "androidx.swiperefreshlayout", name = "swiperefreshlayout", version.ref = "swiperefreshlayout" }
converter-jackson = { group = "com.squareup.retrofit2", name = "converter-jackson", version.ref = "converterJackson" }
jackson-datatype-jsr310 = { group = "com.fasterxml.jackson.datatype", name = "jackson-datatype-jsr310", version.ref = "jacksonDatatypeJsr310" }
[plugins] [plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" } androidApplication = { id = "com.android.application", version.ref = "agp" }
......
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