mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +01:00 
			
		
		
		
	Update details metadata along with chapters list
(cherry picked from commit 29feee0095)
			
			
This commit is contained in:
		| @@ -111,7 +111,6 @@ class LibraryUpdateService( | ||||
|      */ | ||||
|     enum class Target { | ||||
|         CHAPTERS, // Manga chapters | ||||
|         DETAILS, // Manga metadata | ||||
|         TRACKING // Tracking metadata | ||||
|     } | ||||
|  | ||||
| @@ -235,7 +234,6 @@ class LibraryUpdateService( | ||||
|                 // Update either chapter list or manga details. | ||||
|                 when (target) { | ||||
|                     Target.CHAPTERS -> updateChapterList(mangaList) | ||||
|                     Target.DETAILS -> updateDetails(mangaList) | ||||
|                     Target.TRACKING -> updateTrackings(mangaList) | ||||
|                 } | ||||
|             } | ||||
| @@ -396,50 +394,22 @@ class LibraryUpdateService( | ||||
|      */ | ||||
|     fun updateManga(manga: Manga): Observable<Pair<List<Chapter>, List<Chapter>>> { | ||||
|         val source = sourceManager.get(manga.source) as? HttpSource ?: return Observable.empty() | ||||
|  | ||||
|         // Update manga details metadata in the background | ||||
|         source.fetchMangaDetails(manga) | ||||
|             .map { networkManga -> | ||||
|                 manga.copyFrom(networkManga) | ||||
|                 db.insertManga(manga).executeAsBlocking() | ||||
|                 manga | ||||
|             } | ||||
|             .onErrorResumeNext { Observable.just(manga) } | ||||
|             .subscribeOn(Schedulers.io()) | ||||
|             .subscribe() | ||||
|  | ||||
|         return source.fetchChapterList(manga) | ||||
|             .map { syncChaptersWithSource(db, it, manga, source) } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method that updates the details of the given list of manga. It's called in a background | ||||
|      * thread, so it's safe to do heavy operations or network calls here. | ||||
|      * | ||||
|      * @param mangaToUpdate the list to update | ||||
|      * @return an observable delivering the progress of each update. | ||||
|      */ | ||||
|     fun updateDetails(mangaToUpdate: List<LibraryManga>): Observable<LibraryManga> { | ||||
|         // Initialize the variables holding the progress of the updates. | ||||
|         val count = AtomicInteger(0) | ||||
|  | ||||
|         // Emit each manga and update it sequentially. | ||||
|         return Observable.from(mangaToUpdate) | ||||
|             // Update the details of the manga concurrently from 5 different sources | ||||
|             .groupBy { it.source } | ||||
|             .flatMap( | ||||
|                 { bySource -> | ||||
|                     bySource | ||||
|                         // Notify manga that will update. | ||||
|                         .doOnNext { showProgressNotification(it, count.andIncrement, mangaToUpdate.size) } | ||||
|                         .concatMap { manga -> | ||||
|                             val source = sourceManager.get(manga.source) as? HttpSource | ||||
|                                 ?: return@concatMap Observable.empty<LibraryManga>() | ||||
|  | ||||
|                             source.fetchMangaDetails(manga) | ||||
|                                 .map { networkManga -> | ||||
|                                     manga.copyFrom(networkManga) | ||||
|                                     db.insertManga(manga).executeAsBlocking() | ||||
|                                     manga | ||||
|                                 } | ||||
|                                 .onErrorReturn { manga } | ||||
|                         } | ||||
|                 }, | ||||
|                 5 | ||||
|             ) | ||||
|             .doOnCompleted { | ||||
|                 cancelProgressNotification() | ||||
|             } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Method that updates the metadata of the connected tracking services. It's called in a | ||||
|      * background thread, so it's safe to do heavy operations or network calls here. | ||||
|   | ||||
| @@ -78,12 +78,6 @@ class SettingsAdvancedController : SettingsController() { | ||||
|                 ctrl.showDialog(router) | ||||
|             } | ||||
|         } | ||||
|         preference { | ||||
|             titleRes = R.string.pref_refresh_library_metadata | ||||
|             summaryRes = R.string.pref_refresh_library_metadata_summary | ||||
|  | ||||
|             onClick { LibraryUpdateService.start(context, target = Target.DETAILS) } | ||||
|         } | ||||
|         preference { | ||||
|             titleRes = R.string.pref_refresh_library_tracking | ||||
|             summaryRes = R.string.pref_refresh_library_tracking_summary | ||||
|   | ||||
		Reference in New Issue
	
	Block a user