Skip to content

Commit 4dd1605

Browse files
Nearby: Fix disappearing of pins loaded from cache (commons-app#6052) (commons-app#6057)
* Nearby Fix disappearing of pins loaded from cache Fixes commons-app#6052 * Remove outdated tests --------- Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
1 parent 4b152fc commit 4dd1605

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ public Place getPlace() {
2020
public boolean getIsBookmarked() {
2121
return isBookmarked;
2222
}
23+
24+
public void setIsBookmarked(boolean isBookmarked) {
25+
this.isBookmarked = isBookmarked;
26+
}
2327
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,7 @@ private void highlightNearestPlace(final Place nearestPlace) {
18391839
);
18401840
}
18411841

1842-
public Marker convertToMarker(Place place, Boolean isBookMarked) {
1842+
public Marker convertToMarker(Place place, boolean isBookMarked) {
18431843
Drawable icon = ContextCompat.getDrawable(getContext(), getIconFor(place, isBookMarked));
18441844
GeoPoint point = new GeoPoint(place.location.getLatitude(), place.location.getLongitude());
18451845
Marker marker = new Marker(binding.map);

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

+15-12
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,15 @@ class NearbyParentFragmentPresenter
105105
*
106106
* @see SchedulePlacesUpdateOptions
107107
*/
108-
private suspend fun schedulePlacesUpdate(markerPlaceGroups: List<MarkerPlaceGroup>) =
108+
private suspend fun schedulePlacesUpdate(
109+
markerPlaceGroups: List<MarkerPlaceGroup>,
110+
force: Boolean = false
111+
) =
109112
withContext(Dispatchers.Main) {
110113
if (markerPlaceGroups.isEmpty()) return@withContext
111114
schedulePlacesUpdateJob?.cancel()
112115
schedulePlacesUpdateJob = launch {
113-
if (SchedulePlacesUpdateOptions.skippedCount++
116+
if (!force && SchedulePlacesUpdateOptions.skippedCount++
114117
< SchedulePlacesUpdateOptions.SKIP_LIMIT
115118
) {
116119
delay(SchedulePlacesUpdateOptions.SKIP_DELAY_MS)
@@ -298,8 +301,6 @@ class NearbyParentFragmentPresenter
298301
lockUnlockNearby(false) // So that new location updates wont come
299302
nearbyParentFragmentView.setProgressBarVisibility(false)
300303

301-
updatePlaceGroupsToControllerAndRender(nearbyPlaceGroups)
302-
303304
loadPlacesDataAyncJob = scope?.launch(Dispatchers.IO) {
304305
// clear past clicks and bookmarkChanged queues
305306
clickedPlaces.clear()
@@ -312,18 +313,20 @@ class NearbyParentFragmentPresenter
312313
val indicesToUpdate = mutableListOf<Int>()
313314
for (i in 0..updatedGroups.lastIndex) {
314315
val repoPlace = placesRepository.fetchPlace(updatedGroups[i].place.entityID)
315-
if (repoPlace != null && repoPlace.name != ""){
316-
updatedGroups[i] = MarkerPlaceGroup(
317-
bookmarkLocationDao.findBookmarkLocation(repoPlace),
318-
repoPlace
319-
)
316+
if (repoPlace != null && repoPlace.name != null && repoPlace.name != ""){
317+
updatedGroups[i].isBookmarked = bookmarkLocationDao.findBookmarkLocation(repoPlace)
318+
updatedGroups[i].place.apply {
319+
name = repoPlace.name
320+
isMonument = repoPlace.isMonument
321+
pic = repoPlace.pic ?: ""
322+
exists = repoPlace.exists ?: true
323+
longDescription = repoPlace.longDescription ?: ""
324+
}
320325
} else {
321326
indicesToUpdate.add(i)
322327
}
323328
}
324-
if (indicesToUpdate.size < updatedGroups.size) {
325-
schedulePlacesUpdate(updatedGroups)
326-
}
329+
schedulePlacesUpdate(updatedGroups, force = true)
327330
// channel for lists of indices of places, each list to be fetched in a single request
328331
val fetchPlacesChannel = Channel<List<Int>>(Channel.UNLIMITED)
329332
var totalBatches = 0

app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyParentFragmentPresenterTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,6 @@ class NearbyParentFragmentPresenterTest {
465465

466466
whenever(bookmarkLocationsDao.allBookmarksLocations).thenReturn(Collections.emptyList())
467467
nearbyPresenter.updateMapMarkers(nearbyPlacesInfo.placeList, latestLocation, null)
468-
Mockito.verify(nearbyParentFragmentView).setFilterState()
469468
Mockito.verify(nearbyParentFragmentView).setProgressBarVisibility(false)
470-
Mockito.verify(nearbyParentFragmentView).updateListFragment(nearbyPlacesInfo.placeList)
471469
}
472470
}

0 commit comments

Comments
 (0)