Skip to content

Commit

Permalink
Make nearby card click action work
Browse files Browse the repository at this point in the history
  • Loading branch information
neslihanturan committed Sep 17, 2019
1 parent 4304e3d commit c5d4d55
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import fr.free.nrw.commons.R;
import fr.free.nrw.commons.contributions.MainActivity;
import fr.free.nrw.commons.nearby.mvp.fragments.NearbyParentFragment;
import fr.free.nrw.commons.utils.SwipableCardView;
import fr.free.nrw.commons.utils.ViewUtil;
import timber.log.Timber;
Expand Down Expand Up @@ -90,7 +91,7 @@ private void setActionListeners(Place place) {
m.viewPager.setCurrentItem(NEARBY_TAB_POSITION);

// Center the map to the place
//((NearbyFragment) m.contributionsActivityPagerAdapter.getItem(NEARBY_TAB_POSITION)).centerMapToPlace(place);
((NearbyParentFragment) m.contributionsActivityPagerAdapter.getItem(NEARBY_TAB_POSITION)).centerMapToPlace(place);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ interface View{
MapboxMap getMapboxMap();
void viewsAreAssignedToPresenter(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback);
void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener);
void centerMapToPlace(Place place, boolean isPortraitMode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ public void updateMarker(boolean isBookmarked, Place place, @Nullable LatLng cur
* Centers the map in nearby fragment to a given place
* @param place is new center of the map
*/
@Override
public void centerMapToPlace(Place place, boolean isPortraitMode) {
Log.d("denemeSon","isPortyrait:"+isPortraitMode);
double cameraShift;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,13 @@ public void onStyleLoaded(@NonNull Style style) {
public void centerMapToPlace(Place place) {
Log.d("denemeson","place:"+place);
if (nearbyMapFragment != null) {
nearbyMapFragment.centerMapToPlace(
place,
nearbyParentFragmentPresenter.centerMapToPlace(place,
getActivity().getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_PORTRAIT);
/*nearbyMapFragment.centerMapToPlace(
place,
getActivity().getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_PORTRAIT);*/
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.location.LocationUpdateListener;
import fr.free.nrw.commons.nearby.NearbyController;
import fr.free.nrw.commons.nearby.Place;
import fr.free.nrw.commons.nearby.mvp.contract.NearbyMapContract;
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
import fr.free.nrw.commons.utils.LocationUtils;
Expand Down Expand Up @@ -43,6 +44,11 @@ public class NearbyParentFragmentPresenter
boolean nearbyOperationsInitialized;
boolean mapInitialized; // TODO reset this on fragment destroyed

Place placeToCenter;
boolean isPortraitMode;
boolean willMapBeCentered;
boolean placesLoadedOnce;


private LocationServiceManager locationServiceManager;

Expand Down Expand Up @@ -282,7 +288,7 @@ public void updateMapAndList(LocationServiceManager.LocationChangeType locationC
/**
* Populates places for custom location, should be used for finding nearby places around a
* location where you are not at.
* @param nearbyPlacesInfo This variable has place list information and distances.
* @param nearbyPlacesInfo This variable has placeToCenter list information and distances.
*/
public void updateMapMarkers(NearbyController.NearbyPlacesInfo nearbyPlacesInfo, Marker selectedMarker) {
nearbyMapFragmentView.updateMapMarkers(nearbyPlacesInfo.curLatLng, nearbyPlacesInfo.placeList, selectedMarker, this);
Expand All @@ -291,20 +297,28 @@ public void updateMapMarkers(NearbyController.NearbyPlacesInfo nearbyPlacesInfo,
lockUnlockNearby(false); // So that new location updates wont come
nearbyParentFragmentView.setProgressBarVisibility(false);
nearbyListFragmentView.updateListFragment(nearbyPlacesInfo.placeList);
handleCenteringTaskIfAny();
}

/**
* Populates places for custom location, should be used for finding nearby places around a
* location where you are not at.
* @param nearbyPlacesInfo This variable has place list information and distances.
* @param nearbyPlacesInfo This variable has placeToCenter list information and distances.
*/
public void updateMapMarkersForCustomLocation(NearbyController.NearbyPlacesInfo nearbyPlacesInfo, Marker selectedMarker) {
nearbyMapFragmentView.updateMapMarkers(nearbyPlacesInfo.curLatLng, nearbyPlacesInfo.placeList, selectedMarker, this);
nearbyMapFragmentView.addCurrentLocationMarker(nearbyPlacesInfo.curLatLng);
lockUnlockNearby(false); // So that new location updates wont come
nearbyParentFragmentView.setProgressBarVisibility(false);
nearbyListFragmentView.updateListFragment(nearbyPlacesInfo.placeList);
handleCenteringTaskIfAny();
}

private void handleCenteringTaskIfAny() {
if (!placesLoadedOnce) {
placesLoadedOnce = true;
nearbyMapFragmentView.centerMapToPlace(placeToCenter, isPortraitMode);
}
}

@Override
Expand Down Expand Up @@ -395,4 +409,18 @@ public boolean searchCloseToCurrentLocation() {
return true;
}
}

/**
* Centers the map in nearby fragment to a given placeToCenter
* @param place is new center of the map
*/
public void centerMapToPlace(Place place, boolean isPortraitMode) {
if (placesLoadedOnce) {
nearbyMapFragmentView.centerMapToPlace(place, isPortraitMode);
} else {
willMapBeCentered = true;
this.isPortraitMode = isPortraitMode;
this.placeToCenter = place;
}
}
}

0 comments on commit c5d4d55

Please sign in to comment.