Commit 644d4077 authored by Chamod Ishankha's avatar Chamod Ishankha

add baby dialog

parent 2858c3fb
......@@ -3,8 +3,11 @@ 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.utils.Utils.animationChanger;
import static com.kaluwa.enterprises.babycare.utils.Utils.loader;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
......@@ -13,17 +16,14 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.Toolbar;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
......@@ -35,6 +35,7 @@ import com.kaluwa.enterprises.babycare.MainActivity;
import com.kaluwa.enterprises.babycare.R;
import com.kaluwa.enterprises.babycare.adapter.BabyDashboardAdapter;
import com.kaluwa.enterprises.babycare.config.ApiConfig;
import com.kaluwa.enterprises.babycare.dialogs.AddBabyDialog;
import com.kaluwa.enterprises.babycare.dto.BabyDto;
import com.kaluwa.enterprises.babycare.dto.responseDto.AuthenticationDto;
import com.kaluwa.enterprises.babycare.service.BabyApiService;
......@@ -44,7 +45,7 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
public class BabyDashboardActivity extends AppCompatActivity {
public class BabyDashboardActivity extends AppCompatActivity implements AddBabyDialog.BabyDialogInterface {
private final static String TAG = "BabyDashboardActivity";
private SwipeRefreshLayout swipeContainer;
......@@ -85,16 +86,16 @@ public class BabyDashboardActivity extends AppCompatActivity {
baby1.setFirstName("Chamod");
baby1.setLastName("Ishankha");
baby1.setDob(LocalDate.parse("2000/07/23", DateTimeFormatter.ofPattern("yyyy/MM/dd")));
baby1.setGender("Male");
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.setGender("Female");
baby2.setSex("Female");
baby2.setActive(false);
baby2.setDescription("My little cute daughter, Love you my darling.");
baby2.setNotes("My little cute daughter, Love you my darling.");
babyDtoList.add(baby1);
babyDtoList.add(baby2);
......@@ -105,6 +106,15 @@ public class BabyDashboardActivity extends AppCompatActivity {
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
// add button enable
floatingAddButton.setOnClickListener(v -> {
openAddBabyDialog();
});
}
private void openAddBabyDialog() {
AddBabyDialog addbabyDialog = new AddBabyDialog();
addbabyDialog.show(getSupportFragmentManager(), "ADD_BABY_DIALOG");
}
......@@ -179,4 +189,19 @@ public class BabyDashboardActivity extends AppCompatActivity {
super.onBackPressed();
animationChanger(this);
}
@Override
public void parseValues(BabyDto dto, AlertDialog dialog, View overlay, SpinKitView progressbar) {
dto.setUserId(authDto.getUserId());
Button positiveBtn = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
Button negativeBtn = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
loader(overlay, progressbar, true);
positiveBtn.setEnabled(false);
negativeBtn.setEnabled(false);
// TODO
// make api caller
// make photo selector
// make dropdowns
}
}
\ No newline at end of file
package com.kaluwa.enterprises.babycare.activities;
import static com.kaluwa.enterprises.babycare.utils.Utils.DATE_FORMAT;
import static com.kaluwa.enterprises.babycare.config.TokenSaver.clearToken;
import static com.kaluwa.enterprises.babycare.config.TokenSaver.getToken;
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;
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.mobileNumberValidation;
import static com.kaluwa.enterprises.babycare.utils.Utils.setUpDOBPicker;
......@@ -24,7 +24,6 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.webkit.MimeTypeMap;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
......@@ -44,8 +43,8 @@ import com.google.gson.Gson;
import com.kaluwa.enterprises.babycare.MainActivity;
import com.kaluwa.enterprises.babycare.R;
import com.kaluwa.enterprises.babycare.config.ApiConfig;
import com.kaluwa.enterprises.babycare.dto.responseDto.AuthenticationDto;
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.UserApiService;
......@@ -56,7 +55,6 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
......@@ -81,6 +79,7 @@ public class UserProfileActivity extends AppCompatActivity {
private AuthenticationDto authDto;
private ActivityResultLauncher<Intent> pickImageLauncher;
private ActivityResultLauncher<Intent> cropImageLauncher;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -93,7 +92,7 @@ public class UserProfileActivity extends AppCompatActivity {
try {
authDto = getToken(getApplicationContext());
} catch (JsonProcessingException e) {
Log.e(TAG, "Error: "+e.getMessage());
Log.e(TAG, "Error: " + e.getMessage());
Toast.makeText(this, "Error getting token, Please refresh", Toast.LENGTH_SHORT).show();
}
userApiService = ApiConfig.getInstance().getUserApi(authDto.getTokenDto().getToken());
......@@ -186,7 +185,7 @@ public class UserProfileActivity extends AppCompatActivity {
} else if (result.getResultCode() == UCrop.RESULT_ERROR) {
final Throwable cropError = UCrop.getError(result.getData());
// Handle the error
Toast.makeText(this, "Something went wrong: "+cropError.getMessage(), Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Something went wrong: " + cropError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
......@@ -228,7 +227,7 @@ public class UserProfileActivity extends AppCompatActivity {
Toast.makeText(UserProfileActivity.this, "An unexpected error occurred", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Log.e(TAG, "else-error: "+e.getMessage());
Log.e(TAG, "else-error: " + e.getMessage());
Toast.makeText(UserProfileActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
loader(overlay, progressBar, false);
......@@ -278,7 +277,7 @@ public class UserProfileActivity extends AppCompatActivity {
Toast.makeText(UserProfileActivity.this, "An unexpected error occurred", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Log.e(TAG, "else-error: "+e.getMessage());
Log.e(TAG, "else-error: " + e.getMessage());
Toast.makeText(UserProfileActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
loader(overlay, progressBar, false);
......@@ -343,7 +342,7 @@ public class UserProfileActivity extends AppCompatActivity {
Toast.makeText(UserProfileActivity.this, "An unexpected error occurred", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Log.e(TAG, "else-error: "+e.getMessage());
Log.e(TAG, "else-error: " + e.getMessage());
Toast.makeText(UserProfileActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
loader(overlay, progressBar, false);
......@@ -385,7 +384,7 @@ public class UserProfileActivity extends AppCompatActivity {
userDto.setLastName(lastName);
userDto.setPhone(mobileNumber);
if (!TextUtils.isEmpty(etDob.getText().toString())) {
LocalDate dob = LocalDate.parse(etDob.getText().toString(), DateTimeFormatter.ofPattern(DATE_FORMAT));
LocalDate dob = LocalDate.parse(etDob.getText().toString(), getDateTimeFormatter());
userDto.setDob(dob.toString());
}
}
......@@ -404,14 +403,14 @@ public class UserProfileActivity extends AppCompatActivity {
UserDto user = response.body();
etFirstName.setText(user.getFirstName());
etLastName.setText(user.getLastName());
etType.setText(!Objects.equals(user.getRole(), "USER") ? user.getRole():"PARENT");
etType.setText(!Objects.equals(user.getRole(), "USER") ? user.getRole() : "PARENT");
etEmail.setText(user.getEmail());
ivVerifiedStatus.setImageDrawable(user.getStatus().equals("NEW")?getDrawable(R.drawable.ico_unverified) : getDrawable(R.drawable.ico_verified));
ivVerifiedStatus.setImageDrawable(user.getStatus().equals("NEW") ? getDrawable(R.drawable.ico_unverified) : getDrawable(R.drawable.ico_verified));
etMobile.setText(user.getPhone());
if (user.getDob() != null) {
LocalDate localDate = Utils.getLocalDate(user.getDob());
if (localDate != null) {
etDob.setText(localDate.format(DateTimeFormatter.ofPattern(DATE_FORMAT)));
etDob.setText(localDate.format(getDateTimeFormatter()));
}
}
loader(overlay, progressBar, false);
......
......@@ -52,9 +52,9 @@ public class BabyDashboardAdapter extends RecyclerView.Adapter<BabyDashboardAdap
holder.tvBabyName.setText(babyDto.getFirstName() + " " + babyDto.getLastName());
Double age = calculateAge(babyDto.getDob(), "byMonths");
holder.tvBabyAge.setText(age != null ? age + " months" : "Not Available");
holder.tvBabySex.setText(babyDto.getGender());
if (!TextUtils.isEmpty(babyDto.getDescription())) {
holder.tvBabyDDespContent.setText(babyDto.getDescription());
holder.tvBabySex.setText(babyDto.getSex());
if (!TextUtils.isEmpty(babyDto.getNotes())) {
holder.tvBabyDDespContent.setText(babyDto.getNotes());
} else {
holder.tvBabyDDespTitle.setText("Status >");
holder.tvBabyDDespContent.setTextColor(babyDto.isActive() ? context.getResources().getColor(R.color.success_green) : context.getResources().getColor(R.color.cancel_red));
......
......@@ -13,12 +13,39 @@ public class BabyDto {
private String firstName;
private String lastName;
private Object dob;
private String gender;
private String description;
private String sex;
private String status;
private boolean isActive;
private byte[] photoData;
private float weight;
private float height;
private String bloodType;
private String eyeColor;
private String hairColor;
private String allergies;
private String medicalConditions;
private String medications;
private String vaccinateRecords;
private String docName;
private String docContactNumber;
private String healthInsuranceInfo;
private Object firstSmileDate;
private Object firstToothDate;
private Object firstWordDate;
private Object firstStepDate;
private String favFoods;
private String foodsDislikes;
private String primaryEmergencyContactName;
private String primaryEmergencyRelationship;
private String primaryEmergencyContactNumber;
private String secondaryEmergencyContactName;
private String secondaryEmergencyRelationship;
private String secondaryEmergencyContactNumber;
private String notes;
private UserDto user;
private Long userId;
private InputStream imageData;
private boolean sys_validated;
}
......@@ -10,17 +10,17 @@ import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.github.ybq.android.spinkit.SpinKitView;
import com.kaluwa.enterprises.babycare.R;
import com.kaluwa.enterprises.babycare.activities.UserProfileActivity;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
......@@ -28,13 +28,11 @@ import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import okhttp3.ResponseBody;
public class Utils {
private static final String TAG = "Utils";
public static final String DATE_FORMAT = "dd/M/yyyy";
public static final int PICK_IMAGE_REQUEST = 1;
private static final String TAG = "Utils";
public static void loader(View overlay, SpinKitView spinKitView, boolean status) {
if (status) {
......@@ -199,4 +197,21 @@ public class Utils {
throw new RuntimeException("Error decoding image byte array");
}
}
public static int dpToPx(Context context, int dp) {
float density = context.getResources().getDisplayMetrics().density;
return Math.round(dp * density);
}
@SuppressLint("NewApi")
public static DateTimeFormatter getDateTimeFormatter() {
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder()
.parseCaseInsensitive().parseLenient()
.appendPattern("[d/M/yyyy]")
.appendPattern("[dd MMM yyyy]")
.appendPattern("[dd/MM/yyyy]")
.appendPattern("[dd/M/yyyy]");
return builder.toFormatter(Locale.ENGLISH);
}
}
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke android:width="1dp" android:color="@color/purple"/>
</shape>
</item>
</selector>
\ No newline at end of file
......@@ -77,7 +77,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Email"
android:text="@string/email_req"
android:textSize="15sp"
android:textColor="@color/black"
android:fontFamily="@font/adamina_regular"/>
......@@ -102,7 +102,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Password"
android:text="@string/password_req"
android:textSize="15sp"
android:textColor="@color/black"
android:fontFamily="@font/adamina_regular"/>
......
......@@ -77,7 +77,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="First Name"
android:text="@string/first_name_req"
android:textSize="15sp"
android:textColor="@color/black"
android:fontFamily="@font/adamina_regular"/>
......@@ -100,7 +100,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Last Name"
android:text="@string/last_name_req"
android:textSize="15sp"
android:textColor="@color/black"
android:fontFamily="@font/adamina_regular"/>
......@@ -123,7 +123,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Mobile Number"
android:text="@string/mobile_number_req"
android:textSize="15sp"
android:textColor="@color/black"
android:fontFamily="@font/adamina_regular"/>
......@@ -146,7 +146,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Email"
android:text="@string/email_req"
android:textSize="15sp"
android:textColor="@color/black"
android:fontFamily="@font/adamina_regular"/>
......@@ -170,7 +170,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Password"
android:text="@string/password_req"
android:textSize="15sp"
android:textColor="@color/black"
android:fontFamily="@font/adamina_regular"/>
......@@ -195,7 +195,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Confirm Password"
android:text="@string/confirm_password_req"
android:textSize="15sp"
android:textColor="@color/black"
android:fontFamily="@font/adamina_regular"/>
......
......@@ -68,13 +68,13 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:fontFamily="@font/inknut_antiqua_regular"
android:textSize="20sp"
android:layout_marginTop="6dp"
android:fontFamily="@font/inknut_antiqua_regular"
android:text="Profile Details"
android:textAlignment="center"
android:textColor="@color/purple"
android:textStyle="bold"/>
android:textSize="20sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
......
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="first_name_req">First name<font color="#FF0000"> *</font></string>
<string name="email_req">Email<font color="#FF0000"> *</font></string>
<string name="password_req">Password<font color="#FF0000"> *</font></string>
<string name="last_name_req">Last name<font color="#FF0000"> *</font></string>
<string name="mobile_number_req">Mobile number<font color="#FF0000"> *</font></string>
<string name="confirm_password_req">Confirm password<font color="#FF0000"> *</font></string>
<string name="last_name_label">Last name</string>
<string name="birth_date_req">Birth date<font color="#FF0000"> *</font></string>
<string name="sex">Sex<font color="#FF0000"> *</font></string>
</resources>
\ No newline at end of file
......@@ -4,4 +4,14 @@
<item name="cornerFamily">rounded</item>
<item name="cornerSize">50%</item>
</style>
<!-- Custom AlertDialog theme -->
<style name="CustomAlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="buttonBarStyle">@style/CustomButtonBar</item>
</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>
\ No newline at end of file
......@@ -11,4 +11,13 @@
<string name="login"><u>Login</u></string>
<string name="edit_btn_value">Edit</string>
<string name="update_btn_value">Update</string>
<string name="first_name_req">First name<font color="#FF0000"> *</font></string>
<string name="email_req">Email<font color="#FF0000"> *</font></string>
<string name="password_req">Password<font color="#FF0000"> *</font></string>
<string name="last_name_req">Last name<font color="#FF0000"> *</font></string>
<string name="mobile_number_req">Mobile number<font color="#FF0000"> *</font></string>
<string name="confirm_password_req">Confirm password<font color="#FF0000"> *</font></string>
<string name="last_name_label">Last name</string>
<string name="birth_date_req">Birth date<font color="#FF0000"> *</font></string>
<string name="sex">Sex<font color="#FF0000"> *</font></string>
</resources>
\ No newline at end of file
......@@ -4,4 +4,14 @@
<item name="cornerFamily">rounded</item>
<item name="cornerSize">50%</item>
</style>
<!-- Custom AlertDialog theme -->
<style name="CustomAlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="buttonBarStyle">@style/CustomButtonBar</item>
</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>
\ No newline at end of file
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