From 4dd16054cab7a0199e0815185328c814d33ba9da Mon Sep 17 00:00:00 2001 From: Tanmay Gupta <119003089+savsch@users.noreply.github.com> Date: Sat, 21 Dec 2024 16:40:33 +0530 Subject: [PATCH] Nearby: Fix disappearing of pins loaded from cache (#6052) (#6057) * Nearby Fix disappearing of pins loaded from cache Fixes #6052 * Remove outdated tests --------- Co-authored-by: Nicolas Raoul --- .../nrw/commons/nearby/MarkerPlaceGroup.java | 4 +++ .../fragments/NearbyParentFragment.java | 2 +- .../NearbyParentFragmentPresenter.kt | 27 ++++++++++--------- .../NearbyParentFragmentPresenterTest.kt | 2 -- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/MarkerPlaceGroup.java b/app/src/main/java/fr/free/nrw/commons/nearby/MarkerPlaceGroup.java index 691f60f6a..c2474adc3 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/MarkerPlaceGroup.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/MarkerPlaceGroup.java @@ -20,4 +20,8 @@ public class MarkerPlaceGroup { public boolean getIsBookmarked() { return isBookmarked; } + + public void setIsBookmarked(boolean isBookmarked) { + this.isBookmarked = isBookmarked; + } } \ No newline at end of file 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 6b21681ab..ab3d9a049 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 @@ -1839,7 +1839,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment ); } - public Marker convertToMarker(Place place, Boolean isBookMarked) { + public Marker convertToMarker(Place place, boolean isBookMarked) { Drawable icon = ContextCompat.getDrawable(getContext(), getIconFor(place, isBookMarked)); GeoPoint point = new GeoPoint(place.location.getLatitude(), place.location.getLongitude()); Marker marker = new Marker(binding.map); 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 6fc5c4189..6f2d0a6a7 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 @@ -105,12 +105,15 @@ class NearbyParentFragmentPresenter * * @see SchedulePlacesUpdateOptions */ - private suspend fun schedulePlacesUpdate(markerPlaceGroups: List) = + private suspend fun schedulePlacesUpdate( + markerPlaceGroups: List, + force: Boolean = false + ) = withContext(Dispatchers.Main) { if (markerPlaceGroups.isEmpty()) return@withContext schedulePlacesUpdateJob?.cancel() schedulePlacesUpdateJob = launch { - if (SchedulePlacesUpdateOptions.skippedCount++ + if (!force && SchedulePlacesUpdateOptions.skippedCount++ < SchedulePlacesUpdateOptions.SKIP_LIMIT ) { delay(SchedulePlacesUpdateOptions.SKIP_DELAY_MS) @@ -298,8 +301,6 @@ class NearbyParentFragmentPresenter lockUnlockNearby(false) // So that new location updates wont come nearbyParentFragmentView.setProgressBarVisibility(false) - updatePlaceGroupsToControllerAndRender(nearbyPlaceGroups) - loadPlacesDataAyncJob = scope?.launch(Dispatchers.IO) { // clear past clicks and bookmarkChanged queues clickedPlaces.clear() @@ -312,18 +313,20 @@ class NearbyParentFragmentPresenter val indicesToUpdate = mutableListOf() for (i in 0..updatedGroups.lastIndex) { val repoPlace = placesRepository.fetchPlace(updatedGroups[i].place.entityID) - if (repoPlace != null && repoPlace.name != ""){ - updatedGroups[i] = MarkerPlaceGroup( - bookmarkLocationDao.findBookmarkLocation(repoPlace), - repoPlace - ) + if (repoPlace != null && repoPlace.name != null && repoPlace.name != ""){ + updatedGroups[i].isBookmarked = bookmarkLocationDao.findBookmarkLocation(repoPlace) + updatedGroups[i].place.apply { + name = repoPlace.name + isMonument = repoPlace.isMonument + pic = repoPlace.pic ?: "" + exists = repoPlace.exists ?: true + longDescription = repoPlace.longDescription ?: "" + } } else { indicesToUpdate.add(i) } } - if (indicesToUpdate.size < updatedGroups.size) { - schedulePlacesUpdate(updatedGroups) - } + schedulePlacesUpdate(updatedGroups, force = true) // channel for lists of indices of places, each list to be fetched in a single request val fetchPlacesChannel = Channel>(Channel.UNLIMITED) var totalBatches = 0 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 27f00b5b2..fd9fdfd55 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 @@ -465,8 +465,6 @@ class NearbyParentFragmentPresenterTest { whenever(bookmarkLocationsDao.allBookmarksLocations).thenReturn(Collections.emptyList()) nearbyPresenter.updateMapMarkers(nearbyPlacesInfo.placeList, latestLocation, null) - Mockito.verify(nearbyParentFragmentView).setFilterState() Mockito.verify(nearbyParentFragmentView).setProgressBarVisibility(false) - Mockito.verify(nearbyParentFragmentView).updateListFragment(nearbyPlacesInfo.placeList) } }