Skip to content

Commit

Permalink
Arreglada carga del siguiente sitio al completar uno
Browse files Browse the repository at this point in the history
Close #57
  • Loading branch information
martinlaizg committed Jul 20, 2019
1 parent dc68c29 commit 7d624f0
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.martinlaizg.geofind.data.access.api;

import com.martinlaizg.geofind.data.access.api.entities.Login;
import com.martinlaizg.geofind.data.access.database.entities.PlacePlay;
import com.martinlaizg.geofind.data.access.database.entities.Play;
import com.martinlaizg.geofind.data.access.database.entities.Tour;
import com.martinlaizg.geofind.data.access.database.entities.User;
Expand Down Expand Up @@ -44,8 +43,9 @@ public interface RestClient {
@POST("plays")
Call<Play> createUserPlay(@QueryMap Map<String, String> params);

@POST("plays/{play_id}/places")
Call<Play> createPlacePlay(@Path("play_id") Integer play_id, @Body PlacePlay placePlay);
@POST("plays/{play_id}/places/{place_id}")
Call<Play> createPlacePlay(@Path("play_id") Integer play_id,
@Path("place_id") Integer place_id);

@POST("support")
Call<Void> sendSupportMessage(@QueryMap Map<String, String> params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.martinlaizg.geofind.data.access.api.error.ErrorType;
import com.martinlaizg.geofind.data.access.api.error.ErrorUtils;
import com.martinlaizg.geofind.data.access.api.service.exceptions.APIException;
import com.martinlaizg.geofind.data.access.database.entities.PlacePlay;
import com.martinlaizg.geofind.data.access.database.entities.Play;

import java.io.IOException;
Expand Down Expand Up @@ -48,7 +47,7 @@ public Play getUserPlay(int user_id, int tour_id) throws APIException {
Response<Play> response;
APIException apiException;
try {
response = restClient.getUserPlay(user_id, tour_id).execute();
response = restClient.getUserPlay(tour_id, user_id).execute();
if(response.isSuccessful()) {
return response.body();
}
Expand Down Expand Up @@ -105,8 +104,7 @@ public Play createPlacePlay(Integer play_id, Integer place_id) throws APIExcepti
Response<Play> response;
APIException apiException;
try {
PlacePlay pp = new PlacePlay(place_id, play_id);
response = restClient.createPlacePlay(play_id, pp).execute();
response = restClient.createPlacePlay(play_id, place_id).execute();
if(response.isSuccessful()) {
return response.body();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private void insert(Play play) {
* @throws APIException
* exception from API
*/
public Play completePlay(Integer play_id, Integer place_id) throws APIException {
public Play completePlace(Integer play_id, Integer place_id) throws APIException {
Play p = playService.createPlacePlay(play_id, place_id);
PlacePlay pp = new PlacePlay(place_id, play_id);
placePlayDAO.insert(pp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.android.material.card.MaterialCardView;
import com.martinlaizg.geofind.R;
import com.martinlaizg.geofind.config.Preferences;
import com.martinlaizg.geofind.data.access.api.service.exceptions.APIException;
import com.martinlaizg.geofind.data.access.database.entities.Place;
import com.martinlaizg.geofind.data.access.database.entities.User;
import com.martinlaizg.geofind.views.viewmodel.PlayTourViewModel;
Expand Down Expand Up @@ -207,29 +208,27 @@ private void completePlace() {
questionDialogBuilder.show();
return;
}
APIException error = viewModel.getError();
Log.e(TAG(), "completePlace: ", error);
Toast.makeText(requireContext(), viewModel.getError().getMessage(),
Toast.LENGTH_SHORT).show();

} else {
Log.d(TAG(), "updateView: Place done");
setPlace(place);
if(requireActivity()
.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && requireActivity()
.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
Toast.makeText(requireContext(), R.string.rejected_location_access,
Toast.LENGTH_SHORT).show();
return;
}
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, LOC_TIME_REQ,
LOC_DIST_REQ, this);
}
});
Log.d(TAG(), "updateView: Place done");
Place p = viewModel.getNextPlace();
if(p == null) {
Log.e(TAG(), "completePlace: null nextPlace ");
Toast.makeText(requireContext(), getString(R.string.something_went_wrong),
Toast.LENGTH_SHORT).show();
} else {
setPlace(p);
if(requireActivity().checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && requireActivity()
.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
Toast.makeText(requireContext(), R.string.rejected_location_access,
Toast.LENGTH_SHORT).show();
return;
}
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, LOC_TIME_REQ,
LOC_DIST_REQ, this);
}
}

private void setPlace(Place nextPlace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class PlaceFragment
ImageView place_image;
@BindView(R.id.place_map)
MapView place_map;
@BindView(R.id.map_circle)
ImageView map_circle;

private int place_id;
private GoogleMap googleMap;
Expand Down Expand Up @@ -103,6 +105,7 @@ private void setPlace(Place place) {

@Override
public void onMapReady(GoogleMap googleMap) {
map_circle.setVisibility(View.VISIBLE);
googleMap.getUiSettings().setAllGesturesEnabled(false);
googleMap.getUiSettings().setMyLocationButtonEnabled(false);
googleMap.getUiSettings().setMapToolbarEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public MutableLiveData<Place> completePlace(Integer place_id) {
MutableLiveData<Place> c = new MutableLiveData<>();
new Thread(() -> {
try {
play = playRepo.completePlay(play.getId(), place_id);
play = playRepo.completePlace(play.getId(), place_id);
c.postValue(getNextPlace());
} catch(APIException e) {
setError(e);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/fragment_place.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@
app:layout_constraintTop_toBottomOf="@id/place_image" />

<ImageView
android:id="@+id/map_circle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/place_area_description"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/place_map"
app:layout_constraintEnd_toEndOf="@+id/place_map"
app:layout_constraintStart_toStartOf="@+id/place_map"
Expand Down

0 comments on commit 7d624f0

Please sign in to comment.