Commit 52101e08 authored by Ishankha K.C's avatar Ishankha K.C

edit baby screen and api connect

parent efb2ae08
...@@ -37,6 +37,7 @@ import com.kaluwa.enterprises.babycare.R; ...@@ -37,6 +37,7 @@ import com.kaluwa.enterprises.babycare.R;
import com.kaluwa.enterprises.babycare.adapter.BabyDashboardAdapter; import com.kaluwa.enterprises.babycare.adapter.BabyDashboardAdapter;
import com.kaluwa.enterprises.babycare.config.ApiConfig; 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.dialogs.EditBabyDialog;
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.error.ErrorDto;
...@@ -51,7 +52,7 @@ import retrofit2.Call; ...@@ -51,7 +52,7 @@ import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
import retrofit2.Response; import retrofit2.Response;
public class BabyDashboardActivity extends AppCompatActivity implements AddBabyDialog.BabyDialogInterface { public class BabyDashboardActivity extends AppCompatActivity implements AddBabyDialog.BabyDialogInterface, EditBabyDialog.EditBabyDialogInterface {
private final static String TAG = "BabyDashboardActivity"; private final static String TAG = "BabyDashboardActivity";
private SwipeRefreshLayout swipeContainer; private SwipeRefreshLayout swipeContainer;
...@@ -299,6 +300,63 @@ public class BabyDashboardActivity extends AppCompatActivity implements AddBabyD ...@@ -299,6 +300,63 @@ public class BabyDashboardActivity extends AppCompatActivity implements AddBabyD
// make dropdowns // make dropdowns
} }
@Override
public void parseValuesForEdit(BabyDto baby, AlertDialog dialog, View overlay, SpinKitView progressbar) {
baby.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);
Call<BabyDto> call = babyApiService.updateBaby(baby.getBabyId(), baby);
call.enqueue(new Callback<BabyDto>() {
@Override
public void onResponse(Call<BabyDto> call, Response<BabyDto> response) {
if (response.isSuccessful()) {
loadData();
Toast.makeText(BabyDashboardActivity.this, "Baby Details were successfully updated.", Toast.LENGTH_LONG).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, throwable.getMessage(), Toast.LENGTH_LONG).show();
positiveBtn.setEnabled(true);
negativeBtn.setEnabled(true);
loader(overlay, progressbar, false);
}
});
// TODO
// make photo selector
// make dropdowns
}
void noContentCall() { void noContentCall() {
if (babyDtoList.isEmpty()) { if (babyDtoList.isEmpty()) {
tvNoContent.setVisibility(View.VISIBLE); tvNoContent.setVisibility(View.VISIBLE);
......
...@@ -147,13 +147,14 @@ public class EditBabyDialog extends AppCompatDialogFragment { ...@@ -147,13 +147,14 @@ public class EditBabyDialog extends AppCompatDialogFragment {
private void applyBabyDto(AlertDialog dialog) { private void applyBabyDto(AlertDialog dialog) {
babyDto = validateObjects(); babyDto = validateObjects();
if (babyDto.isSys_validated()) { if (babyDto.isSys_validated()) {
babyDialogInterface.parseValues(babyDto, dialog, overlay, progressbar); babyDialogInterface.parseValuesForEdit(babyDto, dialog, overlay, progressbar);
} }
} }
@SuppressLint("NewApi") @SuppressLint("NewApi")
private BabyDto validateObjects() { private BabyDto validateObjects() {
BabyDto baby = new BabyDto(); BabyDto baby = new BabyDto();
baby.setBabyId(babyDto.getBabyId());
baby.setSys_validated(false); 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;
...@@ -249,7 +250,7 @@ public class EditBabyDialog extends AppCompatDialogFragment { ...@@ -249,7 +250,7 @@ public class EditBabyDialog extends AppCompatDialogFragment {
@Override @Override
public void onAttach(@NonNull Context context) { public void onAttach(@NonNull Context context) {
super.onAttach(context); super.onAttach(context);
// babyDialogInterface = (EditBabyDialogInterface) context; babyDialogInterface = (EditBabyDialogInterface) context;
} }
private void findViews(View view) { private void findViews(View view) {
...@@ -297,6 +298,6 @@ public class EditBabyDialog extends AppCompatDialogFragment { ...@@ -297,6 +298,6 @@ public class EditBabyDialog extends AppCompatDialogFragment {
} }
public interface EditBabyDialogInterface { public interface EditBabyDialogInterface {
void parseValues(BabyDto dto, AlertDialog dialog, View overlay, SpinKitView progressbar); void parseValuesForEdit(BabyDto dto, AlertDialog dialog, View overlay, SpinKitView progressbar);
} }
} }
...@@ -8,6 +8,8 @@ import retrofit2.Call; ...@@ -8,6 +8,8 @@ import retrofit2.Call;
import retrofit2.http.Body; import retrofit2.http.Body;
import retrofit2.http.GET; import retrofit2.http.GET;
import retrofit2.http.POST; import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;
public interface BabyApiService { public interface BabyApiService {
...@@ -17,4 +19,7 @@ public interface BabyApiService { ...@@ -17,4 +19,7 @@ public interface BabyApiService {
@POST("baby") @POST("baby")
Call<BabyDto> addBaby(@Body BabyDto baby); Call<BabyDto> addBaby(@Body BabyDto baby);
@PUT("baby/{babyId}")
Call<BabyDto> updateBaby(@Path("babyId") Long babyId, @Body BabyDto baby);
} }
...@@ -234,8 +234,8 @@ public class Utils { ...@@ -234,8 +234,8 @@ public class Utils {
.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("[yyyy-MM-dd]");
return builder.toFormatter(Locale.ENGLISH); return builder.toFormatter(Locale.ENGLISH);
} }
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Basic Information" android:text="Baby's Picture"
android:textColor="@color/purple" android:textColor="@color/purple"
android:textStyle="bold" android:textStyle="bold"
android:fontFamily="@font/jeju_gothic_regular" android:fontFamily="@font/jeju_gothic_regular"
...@@ -33,6 +33,42 @@ ...@@ -33,6 +33,42 @@
android:layout_height="1dp" android:layout_height="1dp"
android:background="@color/dark_purple"/> android:background="@color/dark_purple"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="4dp"
android:background="@drawable/borders"
android:padding="8dp">
<ImageButton
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:adjustViewBounds="true"
android:scaleType="centerInside"
android:layout_gravity="center"
android:contentDescription="baby_uploaded_photo"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Basic Information"
android:textColor="@color/purple"
android:textStyle="bold"
android:fontFamily="@font/jeju_gothic_regular"
android:textSize="18sp"
android:paddingTop="12dp"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/dark_purple"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
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