From 41f4ea6f016fa93e19fab415caca2a1a103af25d Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Fri, 26 Mar 2021 01:55:42 -0400 Subject: [PATCH] Update library while restore happens --- .../tachiyomi/data/backup/full/FullBackupRestore.kt | 1 + .../data/backup/legacy/LegacyBackupRestore.kt | 2 ++ .../tachiyomi/data/library/LibraryUpdateService.kt | 10 +++++++--- .../kanade/tachiyomi/ui/library/LibraryController.kt | 6 +++--- .../eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt | 2 +- .../kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt | 5 ++--- .../ui/recent_updates/RecentChaptersPresenter.kt | 3 +-- .../eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt | 7 +++---- 8 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestore.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestore.kt index b9244e975e..98bf2f6a69 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestore.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestore.kt @@ -77,6 +77,7 @@ class FullBackupRestore(context: Context, notifier: BackupNotifier) : AbstractBa restoreProgress += 1 showRestoreProgress(restoreProgress, restoreAmount, manga.title) + LibraryUpdateService.callListener(manga) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/legacy/LegacyBackupRestore.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/legacy/LegacyBackupRestore.kt index 5607f10403..7c419bcd24 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/legacy/LegacyBackupRestore.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/legacy/LegacyBackupRestore.kt @@ -20,6 +20,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.MangaImpl import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.database.models.TrackImpl +import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.source.Source import java.util.Date @@ -100,6 +101,7 @@ class LegacyBackupRestore(context: Context, notifier: BackupNotifier) : Abstract restoreProgress += 1 showRestoreProgress(restoreProgress, restoreAmount, manga.title) + LibraryUpdateService.callListener(manga) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index b9f53ded07..be02c107ff 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -180,7 +180,7 @@ class LibraryUpdateService( if (wakeLock.isHeld) { wakeLock.release() } - listener?.onUpdateManga(LibraryManga()) + listener?.onUpdateManga() super.onDestroy() } @@ -225,7 +225,7 @@ class LibraryUpdateService( stopSelf(startId) } if (target == Target.CHAPTERS) { - listener?.onUpdateManga(LibraryManga()) + listener?.onUpdateManga() } job = GlobalScope.launch(handler) { when (target) { @@ -626,9 +626,13 @@ class LibraryUpdateService( fun removeListener(listener: LibraryServiceListener) { if (this.listener == listener) this.listener = null } + + fun callListener(manga: Manga) { + listener?.onUpdateManga(manga) + } } } interface LibraryServiceListener { - fun onUpdateManga(manga: LibraryManga) + fun onUpdateManga(manga: Manga? = null) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index b9ed58f18d..5d37da1f3d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -1165,9 +1165,9 @@ class LibraryController( } } - override fun onUpdateManga(manga: LibraryManga) { - if (manga.id == null) adapter.notifyDataSetChanged() - else presenter.updateManga(manga) + override fun onUpdateManga(manga: Manga?) { + if (manga == null) adapter.notifyDataSetChanged() + else presenter.updateManga() } private fun setSelection(position: Int, selected: Boolean = true) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 56130d7630..bfad688652 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -737,7 +737,7 @@ class LibraryPresenter( } /** Called when Library Service updates a manga, update the item as well */ - fun updateManga(manga: LibraryManga) { + fun updateManga() { scope.launch { getLibrary() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt index f68265ea30..c425bb6729 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt @@ -9,7 +9,6 @@ import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Chapter -import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.MangaCategory import eu.kanade.tachiyomi.data.database.models.Track @@ -599,8 +598,8 @@ class MangaDetailsPresenter( toggleFavorite() } - override fun onUpdateManga(manga: LibraryManga) { - if (manga.id == this.manga.id) { + override fun onUpdateManga(manga: Manga?) { + if (manga?.id == this.manga.id) { fetchChapters() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersPresenter.kt index 3f15354895..dd0eb8d782 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersPresenter.kt @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.recent_updates import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Chapter -import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.MangaChapter import eu.kanade.tachiyomi.data.download.DownloadManager @@ -92,7 +91,7 @@ class RecentChaptersPresenter( } } - override fun onUpdateManga(manga: LibraryManga) { + override fun onUpdateManga(manga: Manga?) { getUpdates() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt index bfcf57679f..4a498f3f3b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt @@ -4,7 +4,6 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.History import eu.kanade.tachiyomi.data.database.models.HistoryImpl -import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory import eu.kanade.tachiyomi.data.download.DownloadManager @@ -265,10 +264,10 @@ class RecentsPresenter( } } - override fun onUpdateManga(manga: LibraryManga) { - if (manga.id == null && !LibraryUpdateService.isRunning()) { + override fun onUpdateManga(manga: Manga?) { + if (manga == null && !LibraryUpdateService.isRunning()) { scope.launch(Dispatchers.Main) { controller.setRefreshing(false) } - } else if (manga.id == null) { + } else if (manga == null) { scope.launch(Dispatchers.Main) { controller.setRefreshing(true) } } else { getRecents()