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