From 58101ea48964fdefe8f7a2a7ed8454f08d22a7ab Mon Sep 17 00:00:00 2001 From: Pau Date: Thu, 22 May 2025 23:56:38 +0200 Subject: [PATCH] Add image and view image in places --- .../acloc/activity/AddNewPlaceActivity.java | 18 ++++++++++++++++-- .../acloc/activity/PlaceDetailActivity.java | 5 ++--- .../java/com/example/acloc/utility/Helper.java | 10 ++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/example/acloc/activity/AddNewPlaceActivity.java b/app/src/main/java/com/example/acloc/activity/AddNewPlaceActivity.java index c998b23..8aef1eb 100644 --- a/app/src/main/java/com/example/acloc/activity/AddNewPlaceActivity.java +++ b/app/src/main/java/com/example/acloc/activity/AddNewPlaceActivity.java @@ -99,6 +99,7 @@ public class AddNewPlaceActivity extends AppCompatActivity implements View.OnCli private void loadIntentData() { entity = (Place) getIntent().getSerializableExtra(Constants.PLACE); place_uuid = entity.getUuid(); // setting place uuid first + jsonString = entity.getImage(); if (entity != null) { Log.d(TAG, "PLACE ENTITY DATA \n " + @@ -130,7 +131,7 @@ public class AddNewPlaceActivity extends AppCompatActivity implements View.OnCli etLongitude.setText(entity.getLongitude()); etAddress.setText(entity.getAddress()); etPlaceDescription.setText(entity.getDescription()); - if (entity.getImage() != null || !Objects.equals(entity.getImage(), "")) { + if (entity.getImage() != null && !entity.getImage().isEmpty()) { String rawImg = entity.getImage(); try { JSONArray array = new JSONArray(rawImg); @@ -308,8 +309,21 @@ public class AddNewPlaceActivity extends AppCompatActivity implements View.OnCli DialogUtils.dismissDialog(); if (response.isSuccessful()) { Helper.makeSnackBar(rlAddPlace, getString(R.string.Place_updated_successfully)); + + if (entity != null) { + entity.setUuid(uuid); + entity.setName(name); + entity.setDescription(description); + entity.setAddress(address); + entity.setLatitude(latitude); + entity.setLongitude(longitude); + entity.setCreatedBy(createdBy); + entity.setImage(jsonString); + } + rlAddPlace.postDelayed(() -> { - finish(); + Helper.goToAndFinish(context, PlaceDetailActivity.class, Constants.PLACE, entity); +// finish(); }, 500); } else { Helper.makeSnackBar(rlAddPlace, getString(R.string.Update_failed_Server_error_Try_again)); diff --git a/app/src/main/java/com/example/acloc/activity/PlaceDetailActivity.java b/app/src/main/java/com/example/acloc/activity/PlaceDetailActivity.java index 67e7ccb..e379d9a 100644 --- a/app/src/main/java/com/example/acloc/activity/PlaceDetailActivity.java +++ b/app/src/main/java/com/example/acloc/activity/PlaceDetailActivity.java @@ -20,7 +20,6 @@ import com.example.acloc.api.LocationApiClient; import com.example.acloc.model.Place; import com.example.acloc.model.Report; import com.example.acloc.service.FavoriteService; -import com.example.acloc.service.PlaceService; import com.example.acloc.service.ReportService; import com.example.acloc.utility.Constants; import com.example.acloc.utility.DialogUtils; @@ -140,7 +139,7 @@ public class PlaceDetailActivity extends AppCompatActivity implements View.OnCli etPlaceName.setText(placeEntity.getName()); etAddress.setText(placeEntity.getAddress()); etPlaceDescription.setText(placeEntity.getDescription()); - if (placeEntity.getImage() != null || placeEntity.getImage() != "") { + if (placeEntity.getImage() != null && !placeEntity.getImage().isEmpty()) { String rawImg = placeEntity.getImage(); try { JSONArray array = new JSONArray(rawImg); @@ -212,7 +211,7 @@ public class PlaceDetailActivity extends AppCompatActivity implements View.OnCli } private void onClickBtnEdit() { - Helper.goTo(context, AddNewPlaceActivity.class, Constants.PLACE, placeEntity); + Helper.goToAndFinish(context, AddNewPlaceActivity.class, Constants.PLACE, placeEntity); } private void onClickBtnSubmit() { diff --git a/app/src/main/java/com/example/acloc/utility/Helper.java b/app/src/main/java/com/example/acloc/utility/Helper.java index 8d81066..3f79400 100644 --- a/app/src/main/java/com/example/acloc/utility/Helper.java +++ b/app/src/main/java/com/example/acloc/utility/Helper.java @@ -55,6 +55,16 @@ public class Helper { } } + public static void goToAndFinish(Context context, Class activity, String key, Serializable object) { + Intent intent = new Intent(context, activity); + intent.putExtra(key, object); + context.startActivity(intent); + + if (context instanceof Activity) { + ((Activity) context).finish(); + } + } + public static void goTo(Context context, Class activity, String key, Serializable object) { Intent intent = new Intent(context, activity); intent.putExtra(key, object);