Skip to content

Commit c5d4d55

Browse files
committed
Make nearby card click action work
1 parent 4304e3d commit c5d4d55

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

app/src/main/java/fr/free/nrw/commons/nearby/NearbyNotificationCardView.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import fr.free.nrw.commons.R;
1515
import fr.free.nrw.commons.contributions.MainActivity;
16+
import fr.free.nrw.commons.nearby.mvp.fragments.NearbyParentFragment;
1617
import fr.free.nrw.commons.utils.SwipableCardView;
1718
import fr.free.nrw.commons.utils.ViewUtil;
1819
import timber.log.Timber;
@@ -90,7 +91,7 @@ private void setActionListeners(Place place) {
9091
m.viewPager.setCurrentItem(NEARBY_TAB_POSITION);
9192

9293
// Center the map to the place
93-
//((NearbyFragment) m.contributionsActivityPagerAdapter.getItem(NEARBY_TAB_POSITION)).centerMapToPlace(place);
94+
((NearbyParentFragment) m.contributionsActivityPagerAdapter.getItem(NEARBY_TAB_POSITION)).centerMapToPlace(place);
9495
});
9596
}
9697

app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyMapContract.java

+1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ interface View{
3434
MapboxMap getMapboxMap();
3535
void viewsAreAssignedToPresenter(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback);
3636
void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener);
37+
void centerMapToPlace(Place place, boolean isPortraitMode);
3738
}
3839
}

app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyMapFragment.java

+1
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ public void updateMarker(boolean isBookmarked, Place place, @Nullable LatLng cur
444444
* Centers the map in nearby fragment to a given place
445445
* @param place is new center of the map
446446
*/
447+
@Override
447448
public void centerMapToPlace(Place place, boolean isPortraitMode) {
448449
Log.d("denemeSon","isPortyrait:"+isPortraitMode);
449450
double cameraShift;

app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,13 @@ public void onStyleLoaded(@NonNull Style style) {
402402
public void centerMapToPlace(Place place) {
403403
Log.d("denemeson","place:"+place);
404404
if (nearbyMapFragment != null) {
405-
nearbyMapFragment.centerMapToPlace(
406-
place,
405+
nearbyParentFragmentPresenter.centerMapToPlace(place,
407406
getActivity().getResources().getConfiguration().orientation ==
408407
Configuration.ORIENTATION_PORTRAIT);
408+
/*nearbyMapFragment.centerMapToPlace(
409+
place,
410+
getActivity().getResources().getConfiguration().orientation ==
411+
Configuration.ORIENTATION_PORTRAIT);*/
409412
}
410413
}
411414

app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java

+30-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import fr.free.nrw.commons.location.LocationServiceManager;
1212
import fr.free.nrw.commons.location.LocationUpdateListener;
1313
import fr.free.nrw.commons.nearby.NearbyController;
14+
import fr.free.nrw.commons.nearby.Place;
1415
import fr.free.nrw.commons.nearby.mvp.contract.NearbyMapContract;
1516
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
1617
import fr.free.nrw.commons.utils.LocationUtils;
@@ -43,6 +44,11 @@ public class NearbyParentFragmentPresenter
4344
boolean nearbyOperationsInitialized;
4445
boolean mapInitialized; // TODO reset this on fragment destroyed
4546

47+
Place placeToCenter;
48+
boolean isPortraitMode;
49+
boolean willMapBeCentered;
50+
boolean placesLoadedOnce;
51+
4652

4753
private LocationServiceManager locationServiceManager;
4854

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

296303
/**
297304
* Populates places for custom location, should be used for finding nearby places around a
298305
* location where you are not at.
299-
* @param nearbyPlacesInfo This variable has place list information and distances.
306+
* @param nearbyPlacesInfo This variable has placeToCenter list information and distances.
300307
*/
301308
public void updateMapMarkersForCustomLocation(NearbyController.NearbyPlacesInfo nearbyPlacesInfo, Marker selectedMarker) {
302309
nearbyMapFragmentView.updateMapMarkers(nearbyPlacesInfo.curLatLng, nearbyPlacesInfo.placeList, selectedMarker, this);
303310
nearbyMapFragmentView.addCurrentLocationMarker(nearbyPlacesInfo.curLatLng);
304311
lockUnlockNearby(false); // So that new location updates wont come
305312
nearbyParentFragmentView.setProgressBarVisibility(false);
306313
nearbyListFragmentView.updateListFragment(nearbyPlacesInfo.placeList);
314+
handleCenteringTaskIfAny();
315+
}
307316

317+
private void handleCenteringTaskIfAny() {
318+
if (!placesLoadedOnce) {
319+
placesLoadedOnce = true;
320+
nearbyMapFragmentView.centerMapToPlace(placeToCenter, isPortraitMode);
321+
}
308322
}
309323

310324
@Override
@@ -395,4 +409,18 @@ public boolean searchCloseToCurrentLocation() {
395409
return true;
396410
}
397411
}
412+
413+
/**
414+
* Centers the map in nearby fragment to a given placeToCenter
415+
* @param place is new center of the map
416+
*/
417+
public void centerMapToPlace(Place place, boolean isPortraitMode) {
418+
if (placesLoadedOnce) {
419+
nearbyMapFragmentView.centerMapToPlace(place, isPortraitMode);
420+
} else {
421+
willMapBeCentered = true;
422+
this.isPortraitMode = isPortraitMode;
423+
this.placeToCenter = place;
424+
}
425+
}
398426
}

0 commit comments

Comments
 (0)