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 5ac5fbb22..4a3831fc4 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 @@ -28,6 +28,7 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.asImmediateFlow import eu.kanade.tachiyomi.databinding.LibraryControllerBinding +import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.RootController import eu.kanade.tachiyomi.ui.base.controller.TabbedController @@ -441,6 +442,7 @@ class LibraryController( mode.title = count.toString() binding.actionToolbar.findItem(R.id.action_edit_cover)?.isVisible = count == 1 + binding.actionToolbar.findItem(R.id.action_download_unread)?.isVisible = selectedMangas.any { it.source != LocalSource.ID } } return false } @@ -453,6 +455,7 @@ class LibraryController( when (item.itemId) { R.id.action_edit_cover -> handleChangeCover() R.id.action_move_to_category -> showChangeMangaCategoriesDialog() + R.id.action_download_unread -> downloadUnreadChapters() R.id.action_delete -> showDeleteMangaDialog() R.id.action_select_all -> selectAllCategoryManga() R.id.action_select_inverse -> selectInverseCategoryManga() @@ -546,6 +549,12 @@ class LibraryController( .showDialog(router) } + private fun downloadUnreadChapters() { + val mangas = selectedMangas.toList() + presenter.downloadUnreadChapters(mangas) + destroyActionModeIfNeeded() + } + private fun showDeleteMangaDialog() { DeleteLibraryMangasDialog(this, selectedMangas.toList()).showDialog(router) } 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 1e365a01e..53ea010a9 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 @@ -313,6 +313,22 @@ class LibraryPresenter( .reduce { set1: Iterable, set2 -> set1.intersect(set2).toMutableList() } } + /** + * Queues all unread chapters from the given list of manga. + * + * @param mangas the list of manga. + */ + fun downloadUnreadChapters(mangas: List) { + mangas.forEach { manga -> + launchIO { + val chapters = db.getChapters(manga).executeAsBlocking() + .filter { !it.read } + + downloadManager.downloadChapters(manga, chapters) + } + } + } + /** * Remove the selected manga from the library. * diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaInfoChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaInfoChaptersController.kt index da7808990..2334fd934 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaInfoChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaInfoChaptersController.kt @@ -745,9 +745,6 @@ class MangaInfoChaptersController(private val fromSource: Boolean = false) : private fun markAsRead(chapters: List) { presenter.markChaptersRead(chapters, true) - if (presenter.preferences.removeAfterMarkedAsRead()) { - deleteChapters(chapters) - } destroyActionModeIfNeeded() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaInfoChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaInfoChaptersPresenter.kt index 72cfc7bc2..15189c879 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaInfoChaptersPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/MangaInfoChaptersPresenter.kt @@ -16,6 +16,7 @@ import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource import eu.kanade.tachiyomi.util.isLocal import eu.kanade.tachiyomi.util.lang.isNullOrUnsubscribed +import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.prepUpdateCover import eu.kanade.tachiyomi.util.removeCovers import eu.kanade.tachiyomi.util.shouldDownloadNewChapters @@ -366,17 +367,21 @@ class MangaInfoChaptersPresenter( * @param read whether to mark chapters as read or unread. */ fun markChaptersRead(selectedChapters: List, read: Boolean) { - Observable.from(selectedChapters) - .doOnNext { chapter -> - chapter.read = read - if (!read) { - chapter.last_page_read = 0 - } + val chapters = selectedChapters.map { chapter -> + chapter.read = read + if (!read) { + chapter.last_page_read = 0 } - .toList() - .flatMap { db.updateChaptersProgress(it).asRxObservable() } - .subscribeOn(Schedulers.io()) - .subscribe() + chapter + } + + launchIO { + db.updateChaptersProgress(chapters).executeAsBlocking() + + if (preferences.removeAfterMarkedAsRead()) { + deleteChapters(chapters) + } + } } /** diff --git a/app/src/main/res/menu/library_selection.xml b/app/src/main/res/menu/library_selection.xml index 525bce3e6..6781476a7 100644 --- a/app/src/main/res/menu/library_selection.xml +++ b/app/src/main/res/menu/library_selection.xml @@ -16,6 +16,13 @@ app:iconTint="?attr/colorOnPrimary" app:showAsAction="always" /> + + Mark as unread Mark previous as read Download + Download unread chapters Bookmark Unbookmark Delete