Add image and view image in places

This commit is contained in:
Pau 2025-05-22 23:56:38 +02:00
parent 40d6107caa
commit 58101ea489
3 changed files with 28 additions and 5 deletions

View File

@ -99,6 +99,7 @@ public class AddNewPlaceActivity extends AppCompatActivity implements View.OnCli
private void loadIntentData() { private void loadIntentData() {
entity = (Place) getIntent().getSerializableExtra(Constants.PLACE); entity = (Place) getIntent().getSerializableExtra(Constants.PLACE);
place_uuid = entity.getUuid(); // setting place uuid first place_uuid = entity.getUuid(); // setting place uuid first
jsonString = entity.getImage();
if (entity != null) { if (entity != null) {
Log.d(TAG, Log.d(TAG,
"PLACE ENTITY DATA \n " + "PLACE ENTITY DATA \n " +
@ -130,7 +131,7 @@ public class AddNewPlaceActivity extends AppCompatActivity implements View.OnCli
etLongitude.setText(entity.getLongitude()); etLongitude.setText(entity.getLongitude());
etAddress.setText(entity.getAddress()); etAddress.setText(entity.getAddress());
etPlaceDescription.setText(entity.getDescription()); etPlaceDescription.setText(entity.getDescription());
if (entity.getImage() != null || !Objects.equals(entity.getImage(), "")) { if (entity.getImage() != null && !entity.getImage().isEmpty()) {
String rawImg = entity.getImage(); String rawImg = entity.getImage();
try { try {
JSONArray array = new JSONArray(rawImg); JSONArray array = new JSONArray(rawImg);
@ -308,8 +309,21 @@ public class AddNewPlaceActivity extends AppCompatActivity implements View.OnCli
DialogUtils.dismissDialog(); DialogUtils.dismissDialog();
if (response.isSuccessful()) { if (response.isSuccessful()) {
Helper.makeSnackBar(rlAddPlace, getString(R.string.Place_updated_successfully)); 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(() -> { rlAddPlace.postDelayed(() -> {
finish(); Helper.goToAndFinish(context, PlaceDetailActivity.class, Constants.PLACE, entity);
// finish();
}, 500); }, 500);
} else { } else {
Helper.makeSnackBar(rlAddPlace, getString(R.string.Update_failed_Server_error_Try_again)); Helper.makeSnackBar(rlAddPlace, getString(R.string.Update_failed_Server_error_Try_again));

View File

@ -20,7 +20,6 @@ import com.example.acloc.api.LocationApiClient;
import com.example.acloc.model.Place; import com.example.acloc.model.Place;
import com.example.acloc.model.Report; import com.example.acloc.model.Report;
import com.example.acloc.service.FavoriteService; import com.example.acloc.service.FavoriteService;
import com.example.acloc.service.PlaceService;
import com.example.acloc.service.ReportService; import com.example.acloc.service.ReportService;
import com.example.acloc.utility.Constants; import com.example.acloc.utility.Constants;
import com.example.acloc.utility.DialogUtils; import com.example.acloc.utility.DialogUtils;
@ -140,7 +139,7 @@ public class PlaceDetailActivity extends AppCompatActivity implements View.OnCli
etPlaceName.setText(placeEntity.getName()); etPlaceName.setText(placeEntity.getName());
etAddress.setText(placeEntity.getAddress()); etAddress.setText(placeEntity.getAddress());
etPlaceDescription.setText(placeEntity.getDescription()); etPlaceDescription.setText(placeEntity.getDescription());
if (placeEntity.getImage() != null || placeEntity.getImage() != "") { if (placeEntity.getImage() != null && !placeEntity.getImage().isEmpty()) {
String rawImg = placeEntity.getImage(); String rawImg = placeEntity.getImage();
try { try {
JSONArray array = new JSONArray(rawImg); JSONArray array = new JSONArray(rawImg);
@ -212,7 +211,7 @@ public class PlaceDetailActivity extends AppCompatActivity implements View.OnCli
} }
private void onClickBtnEdit() { private void onClickBtnEdit() {
Helper.goTo(context, AddNewPlaceActivity.class, Constants.PLACE, placeEntity); Helper.goToAndFinish(context, AddNewPlaceActivity.class, Constants.PLACE, placeEntity);
} }
private void onClickBtnSubmit() { private void onClickBtnSubmit() {

View File

@ -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) { public static void goTo(Context context, Class<?> activity, String key, Serializable object) {
Intent intent = new Intent(context, activity); Intent intent = new Intent(context, activity);
intent.putExtra(key, object); intent.putExtra(key, object);