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 <nicolas.raoul@gmail.com>
This commit is contained in:
Tanmay Gupta 2024-12-21 16:40:33 +05:30 committed by GitHub
parent 4b152fc15f
commit 4dd16054ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 15 deletions

View file

@ -20,4 +20,8 @@ public class MarkerPlaceGroup {
public boolean getIsBookmarked() { public boolean getIsBookmarked() {
return isBookmarked; return isBookmarked;
} }
public void setIsBookmarked(boolean isBookmarked) {
this.isBookmarked = isBookmarked;
}
} }

View file

@ -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)); Drawable icon = ContextCompat.getDrawable(getContext(), getIconFor(place, isBookMarked));
GeoPoint point = new GeoPoint(place.location.getLatitude(), place.location.getLongitude()); GeoPoint point = new GeoPoint(place.location.getLatitude(), place.location.getLongitude());
Marker marker = new Marker(binding.map); Marker marker = new Marker(binding.map);

View file

@ -105,12 +105,15 @@ class NearbyParentFragmentPresenter
* *
* @see SchedulePlacesUpdateOptions * @see SchedulePlacesUpdateOptions
*/ */
private suspend fun schedulePlacesUpdate(markerPlaceGroups: List<MarkerPlaceGroup>) = private suspend fun schedulePlacesUpdate(
markerPlaceGroups: List<MarkerPlaceGroup>,
force: Boolean = false
) =
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
if (markerPlaceGroups.isEmpty()) return@withContext if (markerPlaceGroups.isEmpty()) return@withContext
schedulePlacesUpdateJob?.cancel() schedulePlacesUpdateJob?.cancel()
schedulePlacesUpdateJob = launch { schedulePlacesUpdateJob = launch {
if (SchedulePlacesUpdateOptions.skippedCount++ if (!force && SchedulePlacesUpdateOptions.skippedCount++
< SchedulePlacesUpdateOptions.SKIP_LIMIT < SchedulePlacesUpdateOptions.SKIP_LIMIT
) { ) {
delay(SchedulePlacesUpdateOptions.SKIP_DELAY_MS) delay(SchedulePlacesUpdateOptions.SKIP_DELAY_MS)
@ -298,8 +301,6 @@ class NearbyParentFragmentPresenter
lockUnlockNearby(false) // So that new location updates wont come lockUnlockNearby(false) // So that new location updates wont come
nearbyParentFragmentView.setProgressBarVisibility(false) nearbyParentFragmentView.setProgressBarVisibility(false)
updatePlaceGroupsToControllerAndRender(nearbyPlaceGroups)
loadPlacesDataAyncJob = scope?.launch(Dispatchers.IO) { loadPlacesDataAyncJob = scope?.launch(Dispatchers.IO) {
// clear past clicks and bookmarkChanged queues // clear past clicks and bookmarkChanged queues
clickedPlaces.clear() clickedPlaces.clear()
@ -312,18 +313,20 @@ class NearbyParentFragmentPresenter
val indicesToUpdate = mutableListOf<Int>() val indicesToUpdate = mutableListOf<Int>()
for (i in 0..updatedGroups.lastIndex) { for (i in 0..updatedGroups.lastIndex) {
val repoPlace = placesRepository.fetchPlace(updatedGroups[i].place.entityID) val repoPlace = placesRepository.fetchPlace(updatedGroups[i].place.entityID)
if (repoPlace != null && repoPlace.name != ""){ if (repoPlace != null && repoPlace.name != null && repoPlace.name != ""){
updatedGroups[i] = MarkerPlaceGroup( updatedGroups[i].isBookmarked = bookmarkLocationDao.findBookmarkLocation(repoPlace)
bookmarkLocationDao.findBookmarkLocation(repoPlace), updatedGroups[i].place.apply {
repoPlace name = repoPlace.name
) isMonument = repoPlace.isMonument
pic = repoPlace.pic ?: ""
exists = repoPlace.exists ?: true
longDescription = repoPlace.longDescription ?: ""
}
} else { } else {
indicesToUpdate.add(i) indicesToUpdate.add(i)
} }
} }
if (indicesToUpdate.size < updatedGroups.size) { schedulePlacesUpdate(updatedGroups, force = true)
schedulePlacesUpdate(updatedGroups)
}
// channel for lists of indices of places, each list to be fetched in a single request // channel for lists of indices of places, each list to be fetched in a single request
val fetchPlacesChannel = Channel<List<Int>>(Channel.UNLIMITED) val fetchPlacesChannel = Channel<List<Int>>(Channel.UNLIMITED)
var totalBatches = 0 var totalBatches = 0

View file

@ -465,8 +465,6 @@ class NearbyParentFragmentPresenterTest {
whenever(bookmarkLocationsDao.allBookmarksLocations).thenReturn(Collections.emptyList()) whenever(bookmarkLocationsDao.allBookmarksLocations).thenReturn(Collections.emptyList())
nearbyPresenter.updateMapMarkers(nearbyPlacesInfo.placeList, latestLocation, null) nearbyPresenter.updateMapMarkers(nearbyPlacesInfo.placeList, latestLocation, null)
Mockito.verify(nearbyParentFragmentView).setFilterState()
Mockito.verify(nearbyParentFragmentView).setProgressBarVisibility(false) Mockito.verify(nearbyParentFragmentView).setProgressBarVisibility(false)
Mockito.verify(nearbyParentFragmentView).updateListFragment(nearbyPlacesInfo.placeList)
} }
} }