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;
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.dialogs.EditBabyDialog;
import com.kaluwa.enterprises.babycare.dto.BabyDto;
import com.kaluwa.enterprises.babycare.dto.responseDto.AuthenticationDto;
import com.kaluwa.enterprises.babycare.error.ErrorDto;
......@@ -51,7 +52,7 @@ 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, EditBabyDialog.EditBabyDialogInterface {
private final static String TAG = "BabyDashboardActivity";
private SwipeRefreshLayout swipeContainer;
......@@ -299,6 +300,63 @@ public class BabyDashboardActivity extends AppCompatActivity implements AddBabyD
// 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() {
if (babyDtoList.isEmpty()) {
tvNoContent.setVisibility(View.VISIBLE);
......
......@@ -147,13 +147,14 @@ public class EditBabyDialog extends AppCompatDialogFragment {
private void applyBabyDto(AlertDialog dialog) {
babyDto = validateObjects();
if (babyDto.isSys_validated()) {
babyDialogInterface.parseValues(babyDto, dialog, overlay, progressbar);
babyDialogInterface.parseValuesForEdit(babyDto, dialog, overlay, progressbar);
}
}
@SuppressLint("NewApi")
private BabyDto validateObjects() {
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;
......@@ -249,7 +250,7 @@ public class EditBabyDialog extends AppCompatDialogFragment {
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
// babyDialogInterface = (EditBabyDialogInterface) context;
babyDialogInterface = (EditBabyDialogInterface) context;
}
private void findViews(View view) {
......@@ -297,6 +298,6 @@ public class EditBabyDialog extends AppCompatDialogFragment {
}
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;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;
public interface BabyApiService {
......@@ -17,4 +19,7 @@ public interface BabyApiService {
@POST("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 {
.parseCaseInsensitive().parseLenient()
// .appendPattern("[d/M/yyyy]")
// .appendPattern("[dd MMM yyyy]")
.appendPattern("[dd/MM/yyyy]");
// .appendPattern("[dd/M/yyyy]");
.appendPattern("[dd/MM/yyyy]")
.appendPattern("[yyyy-MM-dd]");
return builder.toFormatter(Locale.ENGLISH);
}
......
......@@ -22,7 +22,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Basic Information"
android:text="Baby's Picture"
android:textColor="@color/purple"
android:textStyle="bold"
android:fontFamily="@font/jeju_gothic_regular"
......@@ -33,6 +33,42 @@
android:layout_height="1dp"
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
android:layout_width="match_parent"
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