mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-30 22:34:02 +01:00 
			
		
		
		
	* Changed files required to get the app to run correctly. Removed suspend from affected DAO files and funcs, and changed to (Kotlin v1.9.22) and (Kotlin compiler v1.5.8) * Created refresh button icon, and added it to the nearby_fragment_menu.xml (header of the nearby page). Created function refresh() in NearbyParentFragment.java to handle refresh functionality. * Replaced refresh() func with emptyCache() and reloadMap() * Attempt at reloadMap(), no testing done yet. * added changes for a possibly working emptyCache implementation (needs testing). * Tested changes as working, edited emptyCache to correctly clear cache and then reload map --------- Co-authored-by: MarcusBarta <marcusbarta@icloud.com>
This commit is contained in:
		
							parent
							
								
									becc07d26b
								
							
						
					
					
						commit
						3e020ed973
					
				
					 15 changed files with 140 additions and 35 deletions
				
			
		|  | @ -15,19 +15,19 @@ abstract class NotForUploadStatusDao { | |||
|      * Insert into Not For Upload status. | ||||
|      */ | ||||
|     @Insert(onConflict = OnConflictStrategy.REPLACE) | ||||
|     abstract suspend fun insert(notForUploadStatus: NotForUploadStatus) | ||||
|     abstract fun insert(notForUploadStatus: NotForUploadStatus) | ||||
| 
 | ||||
|     /** | ||||
|      * Delete Not For Upload status entry. | ||||
|      */ | ||||
|     @Delete | ||||
|     abstract suspend fun delete(notForUploadStatus: NotForUploadStatus) | ||||
|     abstract fun delete(notForUploadStatus: NotForUploadStatus) | ||||
| 
 | ||||
|     /** | ||||
|      * Query Not For Upload status with image sha1. | ||||
|      */ | ||||
|     @Query("SELECT * FROM images_not_for_upload_table WHERE imageSHA1 = (:imageSHA1) ") | ||||
|     abstract suspend fun getFromImageSHA1(imageSHA1: String): NotForUploadStatus? | ||||
|     abstract fun getFromImageSHA1(imageSHA1: String): NotForUploadStatus? | ||||
| 
 | ||||
|     /** | ||||
|      * Asynchronous image sha1 query. | ||||
|  | @ -38,7 +38,7 @@ abstract class NotForUploadStatusDao { | |||
|      * Deletion Not For Upload status with image sha1. | ||||
|      */ | ||||
|     @Query("DELETE FROM images_not_for_upload_table WHERE imageSHA1 = (:imageSHA1) ") | ||||
|     abstract suspend fun deleteWithImageSHA1(imageSHA1: String) | ||||
|     abstract fun deleteWithImageSHA1(imageSHA1: String) | ||||
| 
 | ||||
|     /** | ||||
|      * Asynchronous image sha1 deletion. | ||||
|  | @ -49,5 +49,5 @@ abstract class NotForUploadStatusDao { | |||
|      * Check whether the imageSHA1 is present in database | ||||
|      */ | ||||
|     @Query("SELECT COUNT() FROM images_not_for_upload_table WHERE imageSHA1 = (:imageSHA1) ") | ||||
|     abstract suspend fun find(imageSHA1: String): Int | ||||
|     abstract fun find(imageSHA1: String): Int | ||||
| } | ||||
|  |  | |||
|  | @ -17,31 +17,31 @@ abstract class UploadedStatusDao { | |||
|      * Insert into uploaded status. | ||||
|      */ | ||||
|     @Insert(onConflict = OnConflictStrategy.REPLACE) | ||||
|     abstract suspend fun insert(uploadedStatus: UploadedStatus) | ||||
|     abstract fun insert(uploadedStatus: UploadedStatus) | ||||
| 
 | ||||
|     /** | ||||
|      * Update uploaded status entry. | ||||
|      */ | ||||
|     @Update | ||||
|     abstract suspend fun update(uploadedStatus: UploadedStatus) | ||||
|     abstract fun update(uploadedStatus: UploadedStatus) | ||||
| 
 | ||||
|     /** | ||||
|      * Delete uploaded status entry. | ||||
|      */ | ||||
|     @Delete | ||||
|     abstract suspend fun delete(uploadedStatus: UploadedStatus) | ||||
|     abstract fun delete(uploadedStatus: UploadedStatus) | ||||
| 
 | ||||
|     /** | ||||
|      * Query uploaded status with image sha1. | ||||
|      */ | ||||
|     @Query("SELECT * FROM uploaded_table WHERE imageSHA1 = (:imageSHA1) ") | ||||
|     abstract suspend fun getFromImageSHA1(imageSHA1: String): UploadedStatus? | ||||
|     abstract fun getFromImageSHA1(imageSHA1: String): UploadedStatus? | ||||
| 
 | ||||
|     /** | ||||
|      * Query uploaded status with modified image sha1. | ||||
|      */ | ||||
|     @Query("SELECT * FROM uploaded_table WHERE modifiedImageSHA1 = (:modifiedImageSHA1) ") | ||||
|     abstract suspend fun getFromModifiedImageSHA1(modifiedImageSHA1: String): UploadedStatus? | ||||
|     abstract fun getFromModifiedImageSHA1(modifiedImageSHA1: String): UploadedStatus? | ||||
| 
 | ||||
|     /** | ||||
|      * Asynchronous insert into uploaded status table. | ||||
|  | @ -55,7 +55,7 @@ abstract class UploadedStatusDao { | |||
|      * Check whether the imageSHA1 is present in database | ||||
|      */ | ||||
|     @Query("SELECT COUNT() FROM uploaded_table WHERE imageSHA1 = (:imageSHA1) AND imageResult = (:imageResult) ") | ||||
|     abstract suspend fun findByImageSHA1( | ||||
|     abstract fun findByImageSHA1( | ||||
|         imageSHA1: String, | ||||
|         imageResult: Boolean, | ||||
|     ): Int | ||||
|  | @ -66,7 +66,7 @@ abstract class UploadedStatusDao { | |||
|     @Query( | ||||
|         "SELECT COUNT() FROM uploaded_table WHERE modifiedImageSHA1 = (:modifiedImageSHA1) AND modifiedImageResult = (:modifiedImageResult) ", | ||||
|     ) | ||||
|     abstract suspend fun findByModifiedImageSHA1( | ||||
|     abstract fun findByModifiedImageSHA1( | ||||
|         modifiedImageSHA1: String, | ||||
|         modifiedImageResult: Boolean, | ||||
|     ): Int | ||||
|  |  | |||
|  | @ -41,4 +41,23 @@ public abstract class PlaceDao { | |||
|                 saveSynchronous(place); | ||||
|             }); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Deletes all Place objects from the database. | ||||
|      * | ||||
|      * @return A Completable that completes once the deletion operation is done. | ||||
|      */ | ||||
|     @Query("DELETE FROM place") | ||||
|     public abstract void deleteAllSynchronous(); | ||||
| 
 | ||||
|     /** | ||||
|      * Deletes all Place objects from the database. | ||||
|      * | ||||
|      */ | ||||
|     public Completable deleteAll() { | ||||
|         return Completable | ||||
|             .fromAction(() -> { | ||||
|                 deleteAllSynchronous(); | ||||
|             }); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -35,4 +35,8 @@ public class PlacesLocalDataSource { | |||
|     public Completable savePlace(Place place) { | ||||
|         return placeDao.save(place); | ||||
|     } | ||||
| 
 | ||||
|     public Completable clearCache() { | ||||
|         return placeDao.deleteAll(); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -3,6 +3,7 @@ package fr.free.nrw.commons.nearby; | |||
| import fr.free.nrw.commons.contributions.Contribution; | ||||
| import fr.free.nrw.commons.location.LatLng; | ||||
| import io.reactivex.Completable; | ||||
| import io.reactivex.schedulers.Schedulers; | ||||
| import javax.inject.Inject; | ||||
| 
 | ||||
| /** | ||||
|  | @ -38,4 +39,13 @@ public class PlacesRepository { | |||
|         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() { | ||||
|         return localDataSource.clearCache() | ||||
|             .subscribeOn(Schedulers.io()); // Ensure it runs on IO thread | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -108,6 +108,7 @@ import fr.free.nrw.commons.utils.NetworkUtils; | |||
| import fr.free.nrw.commons.utils.SystemThemeUtils; | ||||
| import fr.free.nrw.commons.utils.ViewUtil; | ||||
| import fr.free.nrw.commons.wikidata.WikidataEditListener; | ||||
| import io.reactivex.Completable; | ||||
| import io.reactivex.Observable; | ||||
| import io.reactivex.android.schedulers.AndroidSchedulers; | ||||
| import io.reactivex.disposables.Disposable; | ||||
|  | @ -342,9 +343,21 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | |||
|     public void onCreateOptionsMenu(@NonNull final Menu menu, | ||||
|         @NonNull final MenuInflater inflater) { | ||||
|         inflater.inflate(R.menu.nearby_fragment_menu, menu); | ||||
|         MenuItem refreshButton = menu.findItem(R.id.item_refresh); | ||||
|         MenuItem listMenu = menu.findItem(R.id.list_sheet); | ||||
|         MenuItem saveAsGPXButton = menu.findItem(R.id.list_item_gpx); | ||||
|         MenuItem saveAsKMLButton = menu.findItem(R.id.list_item_kml); | ||||
|         refreshButton.setOnMenuItemClickListener(new OnMenuItemClickListener() { | ||||
|             @Override | ||||
|             public boolean onMenuItemClick(MenuItem item) { | ||||
|                 try { | ||||
|                     emptyCache(); | ||||
|                 } catch (Exception e) { | ||||
|                     throw new RuntimeException(e); | ||||
|                 } | ||||
|                 return false; | ||||
|             } | ||||
|         }); | ||||
|         listMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { | ||||
|             @Override | ||||
|             public boolean onMenuItemClick(MenuItem item) { | ||||
|  | @ -1158,6 +1171,48 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      *  Reloads the Nearby map | ||||
|      *  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() { | ||||
|         // reload the map once the cache is cleared | ||||
|         compositeDisposable.add( | ||||
|             placesRepository.clearCache() | ||||
|                 .subscribeOn(Schedulers.io()) | ||||
|                 .observeOn(AndroidSchedulers.mainThread()) | ||||
|                 .andThen(Completable.fromAction(this::reloadMap)) | ||||
|                 .subscribe( | ||||
|                     () -> { | ||||
|                         Timber.d("Nearby Cache cleared successfully."); | ||||
|                     }, | ||||
|                     throwable -> { | ||||
|                         Timber.e(throwable, "Failed to clear the Nearby Cache"); | ||||
|                     } | ||||
|                 ) | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
|     private void savePlacesAsKML() { | ||||
|         final Observable<String> savePlacesObservable = Observable | ||||
|             .fromCallable(() -> nearbyController | ||||
|  |  | |||
|  | @ -10,15 +10,13 @@ abstract class BaseDelegateAdapter<T>( | |||
|     areContentsTheSame: (T, T) -> Boolean = { old, new -> old == new }, | ||||
| ) : AsyncListDifferDelegationAdapter<T>( | ||||
|         object : DiffUtil.ItemCallback<T>() { | ||||
|             override fun areItemsTheSame( | ||||
|                 oldItem: T, | ||||
|                 newItem: T, | ||||
|             ) = areItemsTheSame(oldItem, newItem) | ||||
|             override fun areItemsTheSame(oldItem: T & Any, newItem: T & Any): Boolean { | ||||
|                 return areItemsTheSame(oldItem, newItem) | ||||
|             } | ||||
| 
 | ||||
|             override fun areContentsTheSame( | ||||
|                 oldItem: T, | ||||
|                 newItem: T, | ||||
|             ) = areContentsTheSame(oldItem, newItem) | ||||
|             override fun areContentsTheSame(oldItem: T & Any, newItem: T & Any): Boolean { | ||||
|                 return areContentsTheSame(oldItem, newItem) | ||||
|             } | ||||
|         }, | ||||
|         *delegates, | ||||
|     ) { | ||||
|  |  | |||
|  | @ -22,16 +22,16 @@ abstract class DepictsDao { | |||
|     private val maxItemsAllowed = 10 | ||||
| 
 | ||||
|     @Insert(onConflict = OnConflictStrategy.REPLACE) | ||||
|     abstract suspend fun insert(depictedItem: Depicts) | ||||
|     abstract fun insert(depictedItem: Depicts) | ||||
| 
 | ||||
|     @Query("Select * From depicts_table order by lastUsed DESC") | ||||
|     abstract suspend fun getAllDepicts(): List<Depicts> | ||||
|     abstract fun getAllDepicts(): List<Depicts> | ||||
| 
 | ||||
|     @Query("Select * From depicts_table order by lastUsed DESC LIMIT :n OFFSET 10") | ||||
|     abstract suspend fun getDepictsForDeletion(n: Int): List<Depicts> | ||||
|     abstract fun getDepictsForDeletion(n: Int): List<Depicts> | ||||
| 
 | ||||
|     @Delete | ||||
|     abstract suspend fun delete(depicts: Depicts) | ||||
|     abstract fun delete(depicts: Depicts) | ||||
| 
 | ||||
|     /** | ||||
|      * Gets all Depicts objects from the database, ordered by lastUsed in descending order. | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Noah Vendrig
						Noah Vendrig