mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +01:00 
			
		
		
		
	Nearby: Avoid reloading entire map upon cache clear
This commit is contained in:
		
							parent
							
								
									22238f55cd
								
							
						
					
					
						commit
						bbdb615628
					
				
					 2 changed files with 36 additions and 23 deletions
				
			
		|  | @ -92,6 +92,7 @@ import fr.free.nrw.commons.nearby.NearbyFilterSearchRecyclerViewAdapter; | ||||||
| import fr.free.nrw.commons.nearby.NearbyFilterState; | import fr.free.nrw.commons.nearby.NearbyFilterState; | ||||||
| import fr.free.nrw.commons.nearby.Place; | import fr.free.nrw.commons.nearby.Place; | ||||||
| import fr.free.nrw.commons.nearby.PlacesRepository; | import fr.free.nrw.commons.nearby.PlacesRepository; | ||||||
|  | import fr.free.nrw.commons.nearby.Sitelinks; | ||||||
| import fr.free.nrw.commons.nearby.WikidataFeedback; | import fr.free.nrw.commons.nearby.WikidataFeedback; | ||||||
| import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract; | import fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract; | ||||||
| import fr.free.nrw.commons.nearby.fragments.AdvanceQueryFragment.Callback; | import fr.free.nrw.commons.nearby.fragments.AdvanceQueryFragment.Callback; | ||||||
|  | @ -1173,27 +1174,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      *  Reloads the Nearby map |      * Clears the Nearby local cache and then calls for pin details to be fetched afresh. | ||||||
|      *  Clears all location markers, refreshes them, reinserts them into the map. |  | ||||||
|      * |  | ||||||
|      */ |  | ||||||
|     private void reloadMap() { |  | ||||||
|         clearAllMarkers(); // Clear the list of markers |  | ||||||
|         binding.map.getController().setZoom(ZOOM_LEVEL); // Reset the zoom level |  | ||||||
|         binding.map.getController().setCenter(lastMapFocus); // Recenter the focus |  | ||||||
|         if (locationPermissionsHelper.checkLocationPermission(getActivity())) { |  | ||||||
|             locationPermissionGranted(); // Reload map with user's location |  | ||||||
|         } else { |  | ||||||
|             startMapWithoutPermission(); // Reload map without user's location |  | ||||||
|         } |  | ||||||
|         binding.map.invalidate(); // Invalidate the map |  | ||||||
|         presenter.updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED); // Restart the map |  | ||||||
|         Timber.d("Reloaded Map Successfully"); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * Clears the Nearby local cache and then calls for the map to be reloaded |  | ||||||
|      * |      * | ||||||
|      */ |      */ | ||||||
|     private void emptyCache() { |     private void emptyCache() { | ||||||
|  | @ -1202,7 +1183,22 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | ||||||
|             placesRepository.clearCache() |             placesRepository.clearCache() | ||||||
|                 .subscribeOn(Schedulers.io()) |                 .subscribeOn(Schedulers.io()) | ||||||
|                 .observeOn(AndroidSchedulers.mainThread()) |                 .observeOn(AndroidSchedulers.mainThread()) | ||||||
|                 .andThen(Completable.fromAction(this::reloadMap)) |                 .andThen(Completable.fromAction(() -> { | ||||||
|  |                     // reload only the pin details, by making all loaded pins gray: | ||||||
|  |                     ArrayList<MarkerPlaceGroup> newPlaceGroups = new ArrayList<>( | ||||||
|  |                         NearbyController.markerLabelList.size()); | ||||||
|  |                     for (final MarkerPlaceGroup placeGroup : NearbyController.markerLabelList) { | ||||||
|  |                         final Place place = new Place("", "", placeGroup.getPlace().getLabel(), "", | ||||||
|  |                             placeGroup.getPlace().getLocation(), "", | ||||||
|  |                             placeGroup.getPlace().siteLinks, "", placeGroup.getPlace().exists, | ||||||
|  |                             placeGroup.getPlace().entityID); | ||||||
|  |                         place.setDistance(placeGroup.getPlace().distance); | ||||||
|  |                         place.setMonument(placeGroup.getPlace().isMonument()); | ||||||
|  |                         newPlaceGroups.add( | ||||||
|  |                             new MarkerPlaceGroup(placeGroup.getIsBookmarked(), place)); | ||||||
|  |                     } | ||||||
|  |                     presenter.loadPlacesDataAsync(newPlaceGroups, scope); | ||||||
|  |                 })) | ||||||
|                 .subscribe( |                 .subscribe( | ||||||
|                     () -> { |                     () -> { | ||||||
|                         Timber.d("Nearby Cache cleared successfully."); |                         Timber.d("Nearby Cache cleared successfully."); | ||||||
|  |  | ||||||
|  | @ -300,10 +300,27 @@ class NearbyParentFragmentPresenter | ||||||
|                 } |                 } | ||||||
|                 ?: return |                 ?: return | ||||||
| 
 | 
 | ||||||
|         loadPlacesDataAyncJob?.cancel() |  | ||||||
|         lockUnlockNearby(false) // So that new location updates wont come |         lockUnlockNearby(false) // So that new location updates wont come | ||||||
|         nearbyParentFragmentView.setProgressBarVisibility(false) |         nearbyParentFragmentView.setProgressBarVisibility(false) | ||||||
|  |         loadPlacesDataAsync(nearbyPlaceGroups, scope) | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Load the places' details from cache and Wikidata query, and update these details on the map | ||||||
|  |      * as and when they arrive. | ||||||
|  |      * | ||||||
|  |      * @param nearbyPlaceGroups The list of `MarkerPlaceGroup` objects to be rendered on the map. | ||||||
|  |      * Note that the supplied objects' `isBookmarked` property can be set false as the actual | ||||||
|  |      * value is retrieved from the bookmarks db eventually. | ||||||
|  |      * @param scope the lifecycle scope of `nearbyParentFragment`'s `viewLifecycleOwner` | ||||||
|  |      * | ||||||
|  |      * @see LoadPlacesAsyncOptions | ||||||
|  |      */ | ||||||
|  |     fun loadPlacesDataAsync( | ||||||
|  |         nearbyPlaceGroups: List<MarkerPlaceGroup>, | ||||||
|  |         scope: LifecycleCoroutineScope? | ||||||
|  |     ) { | ||||||
|  |         loadPlacesDataAyncJob?.cancel() | ||||||
|         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() | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 savsch
						savsch