mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	Tested changes as working, edited emptyCache to correctly clear cache and then reload map
This commit is contained in:
		
							parent
							
								
									979f3a3fbc
								
							
						
					
					
						commit
						76b3dc85ac
					
				
					 3 changed files with 37 additions and 23 deletions
				
			
		|  | @ -52,9 +52,8 @@ public abstract class PlaceDao { | ||||||
|     public abstract void deleteAllSynchronous(); |     public abstract void deleteAllSynchronous(); | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Deletes all Place objects asynchronously from the database. |      * Deletes all Place objects from the database. | ||||||
|      * |      * | ||||||
|      * @return A Completable that completes once the deletion operation is done. |  | ||||||
|      */ |      */ | ||||||
|     public Completable deleteAll() { |     public Completable deleteAll() { | ||||||
|         return Completable |         return Completable | ||||||
|  |  | ||||||
|  | @ -3,6 +3,7 @@ package fr.free.nrw.commons.nearby; | ||||||
| import fr.free.nrw.commons.contributions.Contribution; | import fr.free.nrw.commons.contributions.Contribution; | ||||||
| import fr.free.nrw.commons.location.LatLng; | import fr.free.nrw.commons.location.LatLng; | ||||||
| import io.reactivex.Completable; | import io.reactivex.Completable; | ||||||
|  | import io.reactivex.schedulers.Schedulers; | ||||||
| import javax.inject.Inject; | import javax.inject.Inject; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | @ -38,7 +39,13 @@ public class PlacesRepository { | ||||||
|         return localDataSource.fetchPlace(entityID); |         return localDataSource.fetchPlace(entityID); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Clears the Nearby cache on an IO thread. | ||||||
|  |      * | ||||||
|  |      * @return A Completable that completes once the cache has been successfully cleared. | ||||||
|  |      */ | ||||||
|     public Completable clearCache() { |     public Completable clearCache() { | ||||||
|         return localDataSource.clearCache(); |         return localDataSource.clearCache() | ||||||
|  |             .subscribeOn(Schedulers.io()); // Ensure it runs on IO thread | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -105,6 +105,7 @@ import fr.free.nrw.commons.utils.NetworkUtils; | ||||||
| import fr.free.nrw.commons.utils.SystemThemeUtils; | import fr.free.nrw.commons.utils.SystemThemeUtils; | ||||||
| import fr.free.nrw.commons.utils.ViewUtil; | import fr.free.nrw.commons.utils.ViewUtil; | ||||||
| import fr.free.nrw.commons.wikidata.WikidataEditListener; | import fr.free.nrw.commons.wikidata.WikidataEditListener; | ||||||
|  | import io.reactivex.Completable; | ||||||
| import io.reactivex.Observable; | import io.reactivex.Observable; | ||||||
| import io.reactivex.android.schedulers.AndroidSchedulers; | import io.reactivex.android.schedulers.AndroidSchedulers; | ||||||
| import io.reactivex.disposables.Disposable; | import io.reactivex.disposables.Disposable; | ||||||
|  | @ -319,9 +320,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | ||||||
|             @Override |             @Override | ||||||
|             public boolean onMenuItemClick(MenuItem item) { |             public boolean onMenuItemClick(MenuItem item) { | ||||||
|                 try { |                 try { | ||||||
|                     // REFRESH BUTTON FUNCTIONALITY HERE |  | ||||||
|                     emptyCache(); |                     emptyCache(); | ||||||
|                     reloadMap(); |  | ||||||
|                 } catch (Exception e) { |                 } catch (Exception e) { | ||||||
|                     throw new RuntimeException(e); |                     throw new RuntimeException(e); | ||||||
|                 } |                 } | ||||||
|  | @ -1132,34 +1131,43 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | ||||||
|     /** |     /** | ||||||
|      *  Reloads the Nearby map |      *  Reloads the Nearby map | ||||||
|      *  Clears all location markers, refreshes them, reinserts them into the map. |      *  Clears all location markers, refreshes them, reinserts them into the map. | ||||||
|      * @author Marcus Barta - marcusbarta@icloud.com |      * | ||||||
|      */ |      */ | ||||||
|     private void reloadMap() { |     private void reloadMap() { | ||||||
|         // TODO: Marcus's section |         clearAllMarkers(); // Clear the list of markers | ||||||
|         clearAllMarkers(); // clear the list of markers |         binding.map.getController().setZoom(ZOOM_LEVEL); // Reset the zoom level | ||||||
|         binding.map.getController().setZoom(ZOOM_LEVEL); // reset the zoom level |         binding.map.getController().setCenter(lastMapFocus); // Recenter the focus | ||||||
|         binding.map.getController().setCenter(lastMapFocus); // recentre the focus |  | ||||||
|         if (locationPermissionsHelper.checkLocationPermission(getActivity())) { |         if (locationPermissionsHelper.checkLocationPermission(getActivity())) { | ||||||
|             locationPermissionGranted(); // reload map with user's location |             locationPermissionGranted(); // Reload map with user's location | ||||||
|         } else { |         } else { | ||||||
|             startMapWithoutPermission(); // reload map without user's location |             startMapWithoutPermission(); // Reload map without user's location | ||||||
|         } |         } | ||||||
|         binding.map.invalidate(); // invalidate the map |         binding.map.invalidate(); // Invalidate the map | ||||||
|         presenter.updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED); // restart the map |         presenter.updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED); // Restart the map | ||||||
|  |         Timber.d("Reloaded Map Successfully"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      *  Empties the Nearby local cache |      * Clears the Nearby local cache and then calls for the map to be reloaded | ||||||
|  |      * | ||||||
|      */ |      */ | ||||||
|     private void emptyCache(){ |     private void emptyCache() { | ||||||
|         Timber.d("Reload: emptyCache"); |         // reload the map once the cache is cleared | ||||||
| 
 |         compositeDisposable.add( | ||||||
|         placesRepository.clearCache(); |             placesRepository.clearCache() | ||||||
| 
 |                 .subscribeOn(Schedulers.io()) | ||||||
|         // Optionally, clear any in-memory cache or state |                 .observeOn(AndroidSchedulers.mainThread()) | ||||||
|         updatedPlacesList.clear(); |                 .andThen(Completable.fromAction(this::reloadMap)) | ||||||
|         updatedLatLng = null; |                 .subscribe( | ||||||
|  |                     () -> { | ||||||
|  |                         Timber.d("Nearby Cache cleared successfully."); | ||||||
|  |                     }, | ||||||
|  |                     throwable -> { | ||||||
|  |                         Timber.e(throwable, "Failed to clear the Nearby Cache"); | ||||||
|  |                     } | ||||||
|  |                 ) | ||||||
|  |         ); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private void savePlacesAsKML() { |     private void savePlacesAsKML() { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Noah Vendrig
						Noah Vendrig