Updates and image view in place detail
This commit is contained in:
parent
d66f357753
commit
40d6107caa
|
|
@ -31,9 +31,12 @@ import com.google.android.material.textfield.TextInputEditText;
|
|||
import com.google.gson.JsonObject;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
|
@ -55,7 +58,7 @@ public class AddNewPlaceActivity extends AppCompatActivity implements View.OnCli
|
|||
|
||||
private Uri selectedImageUri;
|
||||
private String imageUrl;
|
||||
private String JSonString;
|
||||
private String jsonString;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
|
@ -105,7 +108,8 @@ public class AddNewPlaceActivity extends AppCompatActivity implements View.OnCli
|
|||
"Place created by: " + entity.getCreatedBy() + "\n " +
|
||||
"Place latitude: " + entity.getLatitude() + "\n " +
|
||||
"Place longitude: " + entity.getLongitude() + "\n " +
|
||||
"Place description: " + entity.getDescription() + "\n "
|
||||
"Place description: " + entity.getDescription() + "\n " +
|
||||
"Place photo: " + entity.getImage() + "\n "
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -126,7 +130,18 @@ 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(), "")) {
|
||||
String rawImg = entity.getImage();
|
||||
try {
|
||||
JSONArray array = new JSONArray(rawImg);
|
||||
String imageUrl = array.getString(0); // Get first element in the array
|
||||
Picasso.get().load(imageUrl).into(ivPlacePhoto);
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, "ERROR: " + e.toString());
|
||||
}
|
||||
} else {
|
||||
Picasso.get().load(R.drawable.logo_add_location).into(ivPlacePhoto);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NonConstantResourceId")
|
||||
|
|
@ -170,9 +185,9 @@ public class AddNewPlaceActivity extends AppCompatActivity implements View.OnCli
|
|||
if (json.getBoolean("success")) {
|
||||
String filename = json.getJSONObject("file").getString("filename");
|
||||
imageUrl = BASE_URL + "public/" + filename;
|
||||
JSonString = "[\"" + imageUrl + "\"]";
|
||||
jsonString = "[\"" + imageUrl + "\"]";
|
||||
Helper.makeSnackBar(rlAddPlace, "Image uploaded successfully");
|
||||
Log.d(TAG, "JsonString: " + JSonString);
|
||||
Log.d(TAG, "JsonString: " + jsonString);
|
||||
} else {
|
||||
Helper.makeSnackBar(rlAddPlace, "Upload failed");
|
||||
}
|
||||
|
|
@ -197,11 +212,11 @@ public class AddNewPlaceActivity extends AppCompatActivity implements View.OnCli
|
|||
if (place_uuid != null && !place_uuid.isEmpty()) {
|
||||
// Update existing place
|
||||
updatePlaceRetrofit(place_uuid, entity.getName(), entity.getDescription(),
|
||||
entity.getAddress(), entity.getLatitude(), entity.getLongitude(), entity.getCreatedBy());
|
||||
entity.getAddress(), entity.getLatitude(), entity.getLongitude(), entity.getCreatedBy(), entity.getImage());
|
||||
} else {
|
||||
// Insert new place
|
||||
insertPlaceRetrofit(entity.getName(), entity.getDescription(),
|
||||
entity.getAddress(), entity.getLatitude(), entity.getLongitude(), entity.getCreatedBy());
|
||||
entity.getAddress(), entity.getLatitude(), entity.getLongitude(), entity.getCreatedBy(), entity.getImage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -214,10 +229,11 @@ public class AddNewPlaceActivity extends AppCompatActivity implements View.OnCli
|
|||
entity.setLongitude(Helper.getStringFromInput(etLongitude));
|
||||
entity.setCreatedBy(SharedPref.getUserUid(context));
|
||||
entity.setUuid(place_uuid);
|
||||
entity.setImage(jsonString);
|
||||
}
|
||||
|
||||
private void insertPlaceRetrofit(String name, String description, String address,
|
||||
String latitude, String longitude, String createdBy) {
|
||||
String latitude, String longitude, String createdBy, String jsonString) {
|
||||
DialogUtils.showLoadingDialog(context, context.getString(R.string.Please_wait));
|
||||
|
||||
JsonObject placeBody = new JsonObject();
|
||||
|
|
@ -227,7 +243,7 @@ public class AddNewPlaceActivity extends AppCompatActivity implements View.OnCli
|
|||
placeBody.addProperty("latitude", latitude);
|
||||
placeBody.addProperty("longitude", longitude);
|
||||
placeBody.addProperty("createdBy", createdBy);
|
||||
placeBody.addProperty("images", JSonString);
|
||||
placeBody.addProperty("images", this.jsonString);
|
||||
|
||||
String token = "Bearer " + SharedPref.getAccessToken(context);
|
||||
|
||||
|
|
@ -268,7 +284,7 @@ public class AddNewPlaceActivity extends AppCompatActivity implements View.OnCli
|
|||
}
|
||||
|
||||
private void updatePlaceRetrofit(String uuid, String name, String description, String address,
|
||||
String latitude, String longitude, String createdBy) {
|
||||
String latitude, String longitude, String createdBy, String jsonString) {
|
||||
|
||||
DialogUtils.showLoadingDialog(context, getString(R.string.Updating_place));
|
||||
|
||||
|
|
@ -279,6 +295,7 @@ public class AddNewPlaceActivity extends AppCompatActivity implements View.OnCli
|
|||
placeBody.addProperty("latitude", latitude);
|
||||
placeBody.addProperty("longitude", longitude);
|
||||
placeBody.addProperty("createdBy", createdBy);
|
||||
placeBody.addProperty("images", jsonString);
|
||||
|
||||
String token = "Bearer " + SharedPref.getAccessToken(context);
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,10 @@ import com.google.android.material.textview.MaterialTextView;
|
|||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -44,7 +48,7 @@ public class PlaceDetailActivity extends AppCompatActivity implements View.OnCli
|
|||
public static final String TAG = PlaceDetailActivity.class.getSimpleName();
|
||||
private RelativeLayout rlPlaceDetails;
|
||||
private MaterialTextView etPlaceName, etAddress, etPlaceDescription;
|
||||
private ImageView ivFavorite, ivEdit;
|
||||
private ImageView ivFavorite, ivEdit, ivPlacePhoto;
|
||||
private AppCompatButton btnSubmit;
|
||||
private Dialog dialog;
|
||||
private Context context;
|
||||
|
|
@ -111,6 +115,7 @@ public class PlaceDetailActivity extends AppCompatActivity implements View.OnCli
|
|||
etPlaceDescription = findViewById(R.id.etPlaceDescription);
|
||||
etAddress = findViewById(R.id.etAddress);
|
||||
ivFavorite = findViewById(R.id.ivFavorite);
|
||||
ivPlacePhoto = findViewById(R.id.ivPlacePhoto);
|
||||
ivEdit = findViewById(R.id.ivEdit);
|
||||
btnSubmit = findViewById(R.id.btnSubmit);
|
||||
rvReports = findViewById(R.id.rvReports);
|
||||
|
|
@ -135,6 +140,18 @@ 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() != "") {
|
||||
String rawImg = placeEntity.getImage();
|
||||
try {
|
||||
JSONArray array = new JSONArray(rawImg);
|
||||
String imageUrl = array.getString(0); // Get first element in the array
|
||||
Picasso.get().load(imageUrl).into(ivPlacePhoto);
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, "ERROR: " + e.toString());
|
||||
}
|
||||
} else {
|
||||
Picasso.get().load(R.drawable.logo_add_location).into(ivPlacePhoto);
|
||||
}
|
||||
Log.d(TAG,
|
||||
"Place uuid: " + placeEntity.getUuid() + "\n " +
|
||||
"Place name: " + placeEntity.getName() + "\n " +
|
||||
|
|
@ -142,7 +159,8 @@ public class PlaceDetailActivity extends AppCompatActivity implements View.OnCli
|
|||
"Place created by: " + placeEntity.getCreatedBy() + "\n " +
|
||||
"Place latitude: " + placeEntity.getLatitude() + "\n " +
|
||||
"Place longitude: " + placeEntity.getLongitude() + "\n " +
|
||||
"Place description: " + placeEntity.getDescription() + "\n "
|
||||
"Place description: " + placeEntity.getDescription() + "\n " +
|
||||
"Place Photo: " + placeEntity.getImage() + "\n "
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -304,6 +304,9 @@ public class MapFragment extends Fragment {
|
|||
|
||||
private void initMap() {
|
||||
fetchAndShowAllPlaces();
|
||||
// Clear old data
|
||||
placeList.clear(); // clear in-memory list ///
|
||||
googleMap.clear(); // remove all markers from the map ///
|
||||
|
||||
fusedLocationClient = LocationServices.getFusedLocationProviderClient(requireActivity());
|
||||
geocoder = new Geocoder(requireContext(), Locale.getDefault());
|
||||
|
|
@ -493,7 +496,6 @@ public class MapFragment extends Fragment {
|
|||
private void fetchAndShowAllPlaces() {
|
||||
String token = "Bearer " + SharedPref.getAccessToken(context); // get saved token
|
||||
|
||||
// Using the new PlaceService through LocationApiClient
|
||||
PlaceService placeService = LocationApiClient.getInstance().getPlaceService();
|
||||
Call<ResponseBody> call = placeService.getAllPlaces(token);
|
||||
|
||||
|
|
@ -517,6 +519,7 @@ public class MapFragment extends Fragment {
|
|||
String uuid = placeObj.optString("uuid", "");
|
||||
double lat = placeObj.getDouble("latitude");
|
||||
double lng = placeObj.getDouble("longitude");
|
||||
String image = placeObj.getString("images");
|
||||
|
||||
LatLng latLng = new LatLng(lat, lng);
|
||||
googleMap.addMarker(new MarkerOptions()
|
||||
|
|
@ -533,6 +536,7 @@ public class MapFragment extends Fragment {
|
|||
place.setDescription(description);
|
||||
place.setCreatedBy(createdBy);
|
||||
place.setUuid(uuid);
|
||||
place.setImage(image);
|
||||
|
||||
placeList.add(place);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package com.example.acloc.model;
|
|||
import java.io.Serializable;
|
||||
|
||||
public class Place implements Serializable {
|
||||
String uuid, name, description, address, latitude, longitude, createdBy;
|
||||
String uuid, name, description, address, latitude, longitude, createdBy, image;
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
|
|
@ -60,4 +60,12 @@ public class Place implements Serializable {
|
|||
public void setCreatedBy(String createdBy) {
|
||||
this.createdBy = createdBy;
|
||||
}
|
||||
|
||||
public String getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(String image) {
|
||||
this.image = image;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,17 +25,28 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- <ImageView-->
|
||||
<!-- android:id="@+id/ivProductPhoto"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="@dimen/image_icon_height"-->
|
||||
<!-- android:layout_gravity="center"-->
|
||||
<!-- android:background="@drawable/rectangle"-->
|
||||
<!-- android:importantForAccessibility="no"-->
|
||||
<!-- android:importantForAutofill="no"-->
|
||||
<!-- android:scaleType="fitXY"-->
|
||||
<!-- android:src="@drawable/place_header" />-->
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivProductPhoto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/image_icon_height"
|
||||
android:id="@+id/ivPlacePhoto"
|
||||
android:layout_width="@dimen/image_view_width"
|
||||
android:layout_height="@dimen/image_view_height"
|
||||
android:layout_gravity="center"
|
||||
android:layout_margin="@dimen/layout_padding"
|
||||
android:background="@drawable/rectangle"
|
||||
android:importantForAccessibility="no"
|
||||
android:importantForAutofill="no"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/place_header" />
|
||||
|
||||
android:padding="@dimen/content_padding"
|
||||
android:src="@drawable/logo_add_location" />
|
||||
|
||||
<!-- Place Name and Icons Row -->
|
||||
<LinearLayout
|
||||
|
|
@ -92,7 +103,7 @@
|
|||
android:layout_width="@dimen/small_image_icon_width"
|
||||
android:layout_height="@dimen/small_image_icon_height"
|
||||
android:autofillHints="Add to Favorite"
|
||||
android:contentDescription="Add to Favorite"
|
||||
android:contentDescription="@string/add_to_favorites"
|
||||
android:src="@drawable/ic_favorite_border"
|
||||
/>
|
||||
|
||||
|
|
@ -105,7 +116,7 @@
|
|||
android:layout_width="@dimen/smallest_image_icon_width"
|
||||
android:layout_height="@dimen/smallest_image_icon_height"
|
||||
android:autofillHints="Edit Place"
|
||||
android:contentDescription="Edit Place"
|
||||
android:contentDescription="@string/edit"
|
||||
android:src="@drawable/ic_edit_location"
|
||||
app:tint="?attr/colorOnBackground" />
|
||||
</LinearLayout>
|
||||
|
|
|
|||
Loading…
Reference in New Issue