Show all currently updating manga in library update notification

This commit is contained in:
arkon 2021-07-08 23:03:22 -04:00
parent 341c3d179e
commit e65f59b3df
3 changed files with 29 additions and 13 deletions

View File

@ -64,22 +64,25 @@ class LibraryUpdateNotifier(private val context: Context) {
/**
* Shows the notification containing the currently updating manga and the progress.
*
* @param manga the manga that's being updated.
* @param manga the manga that are being updated.
* @param current the current progress.
* @param total the total progress.
*/
fun showProgressNotification(manga: Manga, current: Int, total: Int) {
val title = if (preferences.hideNotificationContent()) {
context.getString(R.string.notification_check_updates)
fun showProgressNotification(manga: List<Manga>, current: Int, total: Int) {
if (preferences.hideNotificationContent()) {
progressNotificationBuilder
.setContentTitle(context.getString(R.string.notification_check_updates))
.setContentText("($current/$total)")
} else {
manga.title
val updatingText = manga.joinToString("\n") { it.title }
progressNotificationBuilder
.setContentTitle(context.getString(R.string.notification_updating, current, total))
.setStyle(NotificationCompat.BigTextStyle().bigText(updatingText))
}
context.notificationManager.notify(
Notifications.ID_LIBRARY_PROGRESS,
progressNotificationBuilder
.setContentTitle(title.chop(40))
.setContentText("($current/$total)")
.setProgress(total, current, false)
.build()
)

View File

@ -54,7 +54,6 @@ import timber.log.Timber
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.io.File
import java.util.concurrent.atomic.AtomicInteger
/**
* This class will take care of updating the chapters of the manga from the library. It can be
@ -274,7 +273,8 @@ class LibraryUpdateService(
*/
suspend fun updateChapterList() {
val semaphore = Semaphore(5)
val progressCount = AtomicInteger(0)
var progressCount = 0
val currentlyUpdatingManga = mutableListOf<LibraryManga>()
val newUpdates = mutableListOf<Pair<LibraryManga, Array<Chapter>>>()
val failedUpdates = mutableListOf<Pair<Manga, String?>>()
var hasDownloads = false
@ -291,7 +291,13 @@ class LibraryUpdateService(
return@async
}
notifier.showProgressNotification(manga, progressCount.andIncrement, mangaToUpdate.size)
currentlyUpdatingManga.add(manga)
progressCount++
notifier.showProgressNotification(
currentlyUpdatingManga,
progressCount,
mangaToUpdate.size
)
try {
val (newChapters, _) = updateManga(manga)
@ -317,6 +323,13 @@ class LibraryUpdateService(
if (preferences.autoUpdateTrackers()) {
updateTrackings(manga, loggedServices)
}
currentlyUpdatingManga.remove(manga)
notifier.showProgressNotification(
currentlyUpdatingManga,
progressCount,
mangaToUpdate.size
)
}
}
}
@ -391,7 +404,7 @@ class LibraryUpdateService(
return
}
notifier.showProgressNotification(manga, progressCount++, mangaToUpdate.size)
notifier.showProgressNotification(listOf(manga), progressCount++, mangaToUpdate.size)
sourceManager.get(manga.source)?.let { source ->
try {
@ -426,8 +439,7 @@ class LibraryUpdateService(
return
}
// Notify manga that will update.
notifier.showProgressNotification(manga, progressCount++, mangaToUpdate.size)
notifier.showProgressNotification(listOf(manga), progressCount++, mangaToUpdate.size)
// Update the tracking details.
updateTrackings(manga, loggedServices)

View File

@ -672,6 +672,7 @@
<!-- Library update service notifications -->
<string name="notification_check_updates">Checking for new chapters</string>
<string name="notification_updating">Updating library… (%1$d/%2$d)</string>
<string name="notification_new_chapters">New chapters found</string>
<plurals name="notification_new_chapters_summary">
<item quantity="one">For 1 title</item>