Fixed issue with favorite selection
This commit is contained in:
parent
ebfc1f8f74
commit
4c189a0724
|
|
@ -57,7 +57,7 @@
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="com.google.android.geo.API_KEY"
|
android:name="com.google.android.geo.API_KEY"
|
||||||
android:value="@string/google_maps_api_key" />
|
android:value="AIzaSyCzcuZhHd-GqadewAiCbh4NuaBhO2AcPOY" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
@ -75,8 +75,27 @@ public class PlaceBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
View bottomSheet = bottomSheetDialog.findViewById(com.google.android.material.R.id.design_bottom_sheet);
|
View bottomSheet = bottomSheetDialog.findViewById(com.google.android.material.R.id.design_bottom_sheet);
|
||||||
if (bottomSheet != null) {
|
if (bottomSheet != null) {
|
||||||
behavior = BottomSheetBehavior.from(bottomSheet);
|
behavior = BottomSheetBehavior.from(bottomSheet);
|
||||||
|
|
||||||
|
//Set initial state to half expanded
|
||||||
behavior.setPeekHeight(getResources().getDisplayMetrics().heightPixels / 2);
|
behavior.setPeekHeight(getResources().getDisplayMetrics().heightPixels / 2);
|
||||||
behavior.setState(BottomSheetBehavior.STATE_HALF_EXPANDED);
|
behavior.setState(BottomSheetBehavior.STATE_HALF_EXPANDED);
|
||||||
|
|
||||||
|
//Add callback to update expand/collapse icon
|
||||||
|
behavior.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
|
||||||
|
@Override
|
||||||
|
public void onStateChanged(@NonNull View bottomSheet, int newState) {
|
||||||
|
if (newState == BottomSheetBehavior.STATE_EXPANDED) {
|
||||||
|
ivExpand.setImageResource(R.drawable.ic_expand_more);
|
||||||
|
} else {
|
||||||
|
ivExpand.setImageResource(R.drawable.ic_expand_less);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
|
||||||
|
// animation based on slide position - do nothing for now
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -109,7 +128,6 @@ public class PlaceBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
btnAddReport = view.findViewById(R.id.btnAddReport);
|
btnAddReport = view.findViewById(R.id.btnAddReport);
|
||||||
rvReports = view.findViewById(R.id.rvReports);
|
rvReports = view.findViewById(R.id.rvReports);
|
||||||
|
|
||||||
// Set up RecyclerView
|
|
||||||
rvReports.setLayoutManager(new LinearLayoutManager(context));
|
rvReports.setLayoutManager(new LinearLayoutManager(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,14 +193,7 @@ public class PlaceBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
reportList.clear();
|
reportList.clear();
|
||||||
|
|
||||||
for (JsonElement element : data.getAsJsonArray("reports")) {
|
for (JsonElement element : data.getAsJsonArray("reports")) {
|
||||||
JsonObject reportObject = element.getAsJsonObject();
|
Report report = getReport(element);
|
||||||
Report report = new Report();
|
|
||||||
|
|
||||||
report.setUuid(reportObject.get("uuid").getAsString());
|
|
||||||
report.setReportRating(reportObject.get("rating").getAsInt());
|
|
||||||
report.setDescription(reportObject.get("description").getAsString());
|
|
||||||
report.setPlaceName(reportObject.get("place_name").getAsString());
|
|
||||||
report.setPlaceUuid(reportObject.get("place_uuid").getAsString());
|
|
||||||
|
|
||||||
reportList.add(report);
|
reportList.add(report);
|
||||||
}
|
}
|
||||||
|
|
@ -208,6 +219,18 @@ public class PlaceBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static @NonNull Report getReport(JsonElement element) {
|
||||||
|
JsonObject reportObject = element.getAsJsonObject();
|
||||||
|
Report report = new Report();
|
||||||
|
|
||||||
|
report.setUuid(reportObject.get("uuid").getAsString());
|
||||||
|
report.setReportRating(reportObject.get("rating").getAsInt());
|
||||||
|
report.setDescription(reportObject.get("description").getAsString());
|
||||||
|
report.setPlaceName(reportObject.get("place_name").getAsString());
|
||||||
|
report.setPlaceUuid(reportObject.get("place_uuid").getAsString());
|
||||||
|
return report;
|
||||||
|
}
|
||||||
|
|
||||||
private void updateReportsUI(List<Report> reports) {
|
private void updateReportsUI(List<Report> reports) {
|
||||||
if (reports != null && !reports.isEmpty()) {
|
if (reports != null && !reports.isEmpty()) {
|
||||||
adapter = new PlaceReportsAdapter(context, reports);
|
adapter = new PlaceReportsAdapter(context, reports);
|
||||||
|
|
@ -277,7 +300,7 @@ public class PlaceBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
String token = "Bearer " + SharedPref.getAccessToken(context);
|
String token = "Bearer " + SharedPref.getAccessToken(context);
|
||||||
FavoriteService favoriteService = LocationApiClient.getInstance().getFavoriteService();
|
FavoriteService favoriteService = LocationApiClient.getInstance().getFavoriteService();
|
||||||
|
|
||||||
Call<JsonObject> call = favoriteService.restorePlaceToFavorites(token, userUuid, body);
|
Call<JsonObject> call = favoriteService.addPlaceToFavorites(token, userUuid, body);
|
||||||
call.enqueue(new Callback<JsonObject>() {
|
call.enqueue(new Callback<JsonObject>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
|
public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
|
||||||
|
|
@ -291,8 +314,8 @@ public class PlaceBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
if (response.errorBody() != null) {
|
if (response.errorBody() != null) {
|
||||||
String errorBody = response.errorBody().string();
|
String errorBody = response.errorBody().string();
|
||||||
|
|
||||||
// Try restoring if it's a duplicate (409 Conflict)
|
// Try restoring if it's a duplicate (409 Conflict) or it isn't found (deleted)
|
||||||
if (response.code() == 409 && errorBody.contains("ER_DUP_ENTRY")) {
|
if ((response.code() == 409 && errorBody.contains("ER_DUP_ENTRY"))|| response.code() == 404 ) {
|
||||||
restorePlaceToFavorites(userUuid, placeUuid);
|
restorePlaceToFavorites(userUuid, placeUuid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import retrofit2.http.Body;
|
||||||
import retrofit2.http.DELETE;
|
import retrofit2.http.DELETE;
|
||||||
import retrofit2.http.GET;
|
import retrofit2.http.GET;
|
||||||
import retrofit2.http.Header;
|
import retrofit2.http.Header;
|
||||||
|
import retrofit2.http.POST;
|
||||||
import retrofit2.http.PUT;
|
import retrofit2.http.PUT;
|
||||||
import retrofit2.http.Path;
|
import retrofit2.http.Path;
|
||||||
|
|
||||||
|
|
@ -50,4 +51,16 @@ public interface FavoriteService {
|
||||||
@Path("user_uuid") String userUuid,
|
@Path("user_uuid") String userUuid,
|
||||||
@Body JsonObject body
|
@Body JsonObject body
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a place to user's favorite places
|
||||||
|
* @param token Bearer token
|
||||||
|
* @param userUuid User UUID
|
||||||
|
* @param placeBody Data to modify (favorite)*/
|
||||||
|
@POST("users/{user_uuid}/places")
|
||||||
|
Call<JsonObject> addPlaceToFavorites(
|
||||||
|
@Header("Authorization") String token,
|
||||||
|
@Path("user_uuid") String userUuid,
|
||||||
|
@Body JsonObject placeBody
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue