diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/contract/NearbyParentFragmentContract.java b/app/src/main/java/fr/free/nrw/commons/nearby/contract/NearbyParentFragmentContract.java index e1c22edf5..3b08cf7cb 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/contract/NearbyParentFragmentContract.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/contract/NearbyParentFragmentContract.java @@ -8,6 +8,7 @@ import fr.free.nrw.commons.kvstore.JsonKvStore; import fr.free.nrw.commons.location.LatLng; import fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType; import fr.free.nrw.commons.nearby.Label; +import fr.free.nrw.commons.nearby.MarkerPlaceGroup; import fr.free.nrw.commons.nearby.Place; import java.util.List; @@ -69,7 +70,7 @@ public interface NearbyParentFragmentContract { Context getContext(); - void updateMapMarkers(List BaseMarkers); + void replaceMarkerOverlays(List markerPlaceGroups); void filterOutAllMarkers(); 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 28a48e914..6b21681ab 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 @@ -1709,13 +1709,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment } } - @Override - public void updateMapMarkers(final List BaseMarkers) { - if (binding.map != null) { - presenter.updateMapMarkersToController(BaseMarkers); - } - } - @Override public void filterOutAllMarkers() { clearAllMarkers(); @@ -1739,7 +1732,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment replaceMarkerOverlays(NearbyController.markerLabelList); return; } - ArrayList placeGroupsToShow = new ArrayList<>(); + final ArrayList placeGroupsToShow = new ArrayList<>(); for (final MarkerPlaceGroup markerPlaceGroup : NearbyController.markerLabelList) { final Place place = markerPlaceGroup.getPlace(); // When label filter is engaged @@ -1891,6 +1884,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment * @param markerPlaceGroups The list of marker place groups containing the places and * their bookmarked status */ + @Override public void replaceMarkerOverlays(final List markerPlaceGroups) { ArrayList newMarkers = new ArrayList<>(markerPlaceGroups.size()); for (MarkerPlaceGroup markerPlaceGroup : markerPlaceGroups) { diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/presenter/NearbyParentFragmentPresenter.kt b/app/src/main/java/fr/free/nrw/commons/nearby/presenter/NearbyParentFragmentPresenter.kt index fa4c2d3d8..6fc5c4189 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/presenter/NearbyParentFragmentPresenter.kt +++ b/app/src/main/java/fr/free/nrw/commons/nearby/presenter/NearbyParentFragmentPresenter.kt @@ -162,9 +162,12 @@ class NearbyParentFragmentPresenter /** * Sets click listeners of FABs, and 2 bottom sheets */ - override fun setActionListeners(applicationKvStore: JsonKvStore) { + override fun setActionListeners(applicationKvStore: JsonKvStore?) { nearbyParentFragmentView.setFABPlusAction(View.OnClickListener { v: View? -> - if (applicationKvStore.getBoolean("login_skipped", false)) { + if (applicationKvStore != null && applicationKvStore.getBoolean( + "login_skipped", false + ) + ) { // prompt the user to login nearbyParentFragmentView.displayLoginSkippedWarning() } else { @@ -497,8 +500,15 @@ class NearbyParentFragmentPresenter } } + /** + * Sends the supplied markerPlaceGroups to `NearbyController` and nearby list fragment, + * and tells nearby parent fragment to filter the updated values to be rendered as overlays + * on the map + * + * @param markerPlaceGroups the new/updated list of places along with their bookmarked status + */ @MainThread - fun updatePlaceGroupsToControllerAndRender(markerPlaceGroups: List) { + private fun updatePlaceGroupsToControllerAndRender(markerPlaceGroups: List) { NearbyController.markerLabelList.clear() NearbyController.markerLabelList.addAll(markerPlaceGroups) nearbyParentFragmentView.setFilterState() diff --git a/app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyParentFragmentPresenterTest.kt b/app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyParentFragmentPresenterTest.kt index 813c3c297..27f00b5b2 100644 --- a/app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyParentFragmentPresenterTest.kt +++ b/app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyParentFragmentPresenterTest.kt @@ -31,6 +31,12 @@ class NearbyParentFragmentPresenterTest { @Mock internal lateinit var bookmarkLocationsDao: BookmarkLocationsDao + @Mock + internal lateinit var placesRepository: PlacesRepository + + @Mock + internal lateinit var nearbyController: NearbyController + @Mock internal lateinit var latestLocation: LatLng @@ -52,7 +58,8 @@ class NearbyParentFragmentPresenterTest { @Throws(Exception::class) fun setUp() { MockitoAnnotations.openMocks(this) - nearbyPresenter = NearbyParentFragmentPresenter(bookmarkLocationsDao) + nearbyPresenter = + NearbyParentFragmentPresenter(bookmarkLocationsDao, placesRepository, nearbyController) nearbyPresenter.attachView(nearbyParentFragmentView) } @@ -322,7 +329,7 @@ class NearbyParentFragmentPresenterTest { @Test fun testSetActionListeners() { - nearbyPresenter.setActionListeners(any()) + nearbyPresenter.setActionListeners(null) verify(nearbyParentFragmentView).setFABPlusAction(any()) verify(nearbyParentFragmentView).setFABRecenterAction(any()) } @@ -454,11 +461,11 @@ class NearbyParentFragmentPresenterTest { nearbyPlacesInfo.boundaryCoordinates = arrayOf() nearbyPlacesInfo.currentLatLng = latestLocation nearbyPlacesInfo.searchLatLng = latestLocation - nearbyPlacesInfo.placeList = null + nearbyPlacesInfo.placeList = emptyList() whenever(bookmarkLocationsDao.allBookmarksLocations).thenReturn(Collections.emptyList()) nearbyPresenter.updateMapMarkers(nearbyPlacesInfo.placeList, latestLocation, null) - Mockito.verify(nearbyParentFragmentView).updateMapMarkers(any()) + Mockito.verify(nearbyParentFragmentView).setFilterState() Mockito.verify(nearbyParentFragmentView).setProgressBarVisibility(false) Mockito.verify(nearbyParentFragmentView).updateListFragment(nearbyPlacesInfo.placeList) }