mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	add suspend keyword and refactor code
This commit is contained in:
		
							parent
							
								
									61d5010900
								
							
						
					
					
						commit
						cc8ea6e692
					
				
					 2 changed files with 11 additions and 17 deletions
				
			
		|  | @ -37,15 +37,11 @@ public abstract class PlaceDao { | |||
|      */ | ||||
|     public Completable save(final Place place) { | ||||
|         return Completable | ||||
|             .fromAction(() -> { | ||||
|                 saveSynchronous(place); | ||||
|             }); | ||||
|             .fromAction(() -> 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(); | ||||
|  | @ -53,11 +49,9 @@ public abstract class PlaceDao { | |||
|     /** | ||||
|      * Deletes all Place objects from the database. | ||||
|      * | ||||
|      * @return A Completable that completes once the deletion operation is done. | ||||
|      */ | ||||
|     public Completable deleteAll() { | ||||
|         return Completable | ||||
|             .fromAction(() -> { | ||||
|                 deleteAllSynchronous(); | ||||
|             }); | ||||
|         return Completable.fromAction(this::deleteAllSynchronous); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -22,21 +22,21 @@ abstract class DepictsDao { | |||
|     private val maxItemsAllowed = 10 | ||||
| 
 | ||||
|     @Insert(onConflict = OnConflictStrategy.REPLACE) | ||||
|     abstract fun insert(depictedItem: Depicts) | ||||
|     abstract suspend fun insert(depictedItem: Depicts) | ||||
| 
 | ||||
|     @Query("Select * From depicts_table order by lastUsed DESC") | ||||
|     abstract fun getAllDepicts(): List<Depicts> | ||||
|     abstract suspend fun getAllDepicts(): List<Depicts> | ||||
| 
 | ||||
|     @Query("Select * From depicts_table order by lastUsed DESC LIMIT :n OFFSET 10") | ||||
|     abstract fun getDepictsForDeletion(n: Int): List<Depicts> | ||||
|     abstract suspend fun getDepictsForDeletion(n: Int): List<Depicts> | ||||
| 
 | ||||
|     @Delete | ||||
|     abstract fun delete(depicts: Depicts) | ||||
|     abstract suspend fun delete(depicts: Depicts) | ||||
| 
 | ||||
|     /** | ||||
|      * Gets all Depicts objects from the database, ordered by lastUsed in descending order. | ||||
|      * | ||||
|      * @return A list of Depicts objects. | ||||
|      * @return Deferred list of Depicts objects. | ||||
|      */ | ||||
|     fun depictsList(): Deferred<List<Depicts>> = | ||||
|         CoroutineScope(Dispatchers.IO).async { | ||||
|  | @ -48,7 +48,7 @@ abstract class DepictsDao { | |||
|      * | ||||
|      * @param depictedItem The Depicts object to insert. | ||||
|      */ | ||||
|     private fun insertDepict(depictedItem: Depicts) = | ||||
|     fun insertDepict(depictedItem: Depicts) = | ||||
|         CoroutineScope(Dispatchers.IO).launch { | ||||
|             insert(depictedItem) | ||||
|         } | ||||
|  | @ -59,7 +59,7 @@ abstract class DepictsDao { | |||
|      * @param n The number of depicts to delete. | ||||
|      * @return A list of Depicts objects to delete. | ||||
|      */ | ||||
|     private suspend fun depictsForDeletion(n: Int): Deferred<List<Depicts>> = | ||||
|     fun depictsForDeletion(n: Int): Deferred<List<Depicts>> = | ||||
|         CoroutineScope(Dispatchers.IO).async { | ||||
|             getDepictsForDeletion(n) | ||||
|         } | ||||
|  | @ -69,7 +69,7 @@ abstract class DepictsDao { | |||
|      * | ||||
|      * @param depicts The Depicts object to delete. | ||||
|      */ | ||||
|     private suspend fun deleteDepicts(depicts: Depicts) = | ||||
|     fun deleteDepicts(depicts: Depicts) = | ||||
|         CoroutineScope(Dispatchers.IO).launch { | ||||
|             delete(depicts) | ||||
|         } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Rohit Verma
						Rohit Verma