diff --git a/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java b/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java index c9e6a43c3..7d5a4570e 100644 --- a/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java @@ -32,6 +32,7 @@ import fr.free.nrw.commons.navtab.NavTabLoggedOut; import fr.free.nrw.commons.nearby.NearbyNotificationCardView; import fr.free.nrw.commons.nearby.Place; import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment; +import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment.NearbyParentFragmentInstanceReadyCallback; import fr.free.nrw.commons.notification.NotificationActivity; import fr.free.nrw.commons.notification.NotificationController; import fr.free.nrw.commons.quiz.QuizChecker; @@ -298,7 +299,14 @@ public class MainActivity extends BaseActivity public void centerMapToPlace(Place place) { setSelectedItemId(NavTab.NEARBY.code()); - nearbyParentFragment.centerMapToPlace(place); + nearbyParentFragment.setNearbyParentFragmentInstanceReadyCallback(new NearbyParentFragmentInstanceReadyCallback() { + // if mapBox initialize in nearbyParentFragment then MapReady() function called + // so that nearbyParentFragemt.centerMaptoPlace(place) not throw any null pointer exception + @Override + public void onReady() { + nearbyParentFragment.centerMapToPlace(place); + } + }); } @Override diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java index fec8be9ec..0689dafc0 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java @@ -214,6 +214,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment private fr.free.nrw.commons.location.LatLng lastFocusLocation; private LatLngBounds latLngBounds; private PlaceAdapter adapter; + private NearbyParentFragmentInstanceReadyCallback nearbyParentFragmentInstanceReadyCallback; @NonNull public static NearbyParentFragment newInstance() { @@ -271,6 +272,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment uiSettings.setAttributionEnabled(false); uiSettings.setRotateGesturesEnabled(false); isMapBoxReady =true; + if(nearbyParentFragmentInstanceReadyCallback!=null){ + nearbyParentFragmentInstanceReadyCallback.onReady(); + } performMapReadyActions(); final CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(51.50550, -0.07520)) @@ -1531,4 +1535,12 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment mapView.onStart(); performMapReadyActions(); } + + public interface NearbyParentFragmentInstanceReadyCallback{ + void onReady(); + } + + public void setNearbyParentFragmentInstanceReadyCallback(NearbyParentFragmentInstanceReadyCallback nearbyParentFragmentInstanceReadyCallback) { + this.nearbyParentFragmentInstanceReadyCallback = nearbyParentFragmentInstanceReadyCallback; + } }