diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyNotificationCardView.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyNotificationCardView.java index 21eaafb0c..f506d4136 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyNotificationCardView.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyNotificationCardView.java @@ -13,6 +13,7 @@ import android.widget.TextView; 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; @@ -90,7 +91,7 @@ public class NearbyNotificationCardView extends SwipableCardView { 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); }); } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyMapContract.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyMapContract.java index a49b93f6b..e1cc4fd4d 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyMapContract.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyMapContract.java @@ -34,5 +34,6 @@ public interface NearbyMapContract { MapboxMap getMapboxMap(); void viewsAreAssignedToPresenter(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback); void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener); + void centerMapToPlace(Place place, boolean isPortraitMode); } } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyMapFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyMapFragment.java index 779d3d414..2c79f9dac 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyMapFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyMapFragment.java @@ -444,6 +444,7 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment * 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; diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java index 8378eba0c..53a26c752 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java @@ -402,10 +402,13 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment 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);*/ } } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java index c6df34ce1..bd2892fde 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java @@ -11,6 +11,7 @@ import fr.free.nrw.commons.location.LatLng; 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; @@ -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; @@ -282,7 +288,7 @@ public class NearbyParentFragmentPresenter /** * 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); @@ -291,12 +297,13 @@ public class NearbyParentFragmentPresenter 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); @@ -304,7 +311,14 @@ public class NearbyParentFragmentPresenter 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 @@ -395,4 +409,18 @@ public class NearbyParentFragmentPresenter 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; + } + } }