Update details metadata along with chapters list

This commit is contained in:
arkon 2020-05-09 10:26:02 -04:00
parent 63f3180dff
commit 29feee0095
3 changed files with 13 additions and 51 deletions

View File

@ -110,7 +110,6 @@ class LibraryUpdateService(
*/
enum class Target {
CHAPTERS, // Manga chapters
DETAILS, // Manga metadata
TRACKING // Tracking metadata
}
@ -234,7 +233,6 @@ class LibraryUpdateService(
// Update either chapter list or manga details.
when (target) {
Target.CHAPTERS -> updateChapterList(mangaList)
Target.DETAILS -> updateDetails(mangaList)
Target.TRACKING -> updateTrackings(mangaList)
}
}
@ -390,50 +388,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.

View File

@ -76,12 +76,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

View File

@ -353,9 +353,7 @@
<string name="pref_clear_database_summary">Delete manga and chapters that are not in your library</string>
<string name="clear_database_confirmation">Are you sure? Read chapters and progress of non-library manga will be lost</string>
<string name="clear_database_completed">Entries deleted</string>
<string name="pref_refresh_library_metadata">Refresh library metadata</string>
<string name="pref_refresh_library_metadata_summary">Updates covers, genres, description and manga status information</string>
<string name="pref_refresh_library_tracking">Refresh tracking metadata</string>
<string name="pref_refresh_library_tracking">Refresh tracking</string>
<string name="pref_refresh_library_tracking_summary">Updates status, score and last chapter read from the tracking services</string>
<string name="pref_disable_battery_optimization">Disable battery optimization</string>
<string name="pref_disable_battery_optimization_summary">Helps with background library updates and backups</string>