From 8bab1d97988714872cc6d88c2c8fde05389967b9 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 8 Aug 2020 12:16:37 -0400 Subject: [PATCH] Add mark as read/unread to library (closes #156) Adapted from https://github.com/CarlosEsco/Neko/commit/e51276a1acb233467bbb1c7214be0ec105c62cb7 --- .../tachiyomi/ui/library/LibraryController.kt | 8 +++++ .../tachiyomi/ui/library/LibraryPresenter.kt | 31 +++++++++++++++++++ app/src/main/res/menu/library_selection.xml | 14 +++++++++ 3 files changed, 53 insertions(+) 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 6570efaad6..9ecefbd025 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 @@ -472,6 +472,8 @@ class LibraryController( when (item.itemId) { R.id.action_move_to_category -> showChangeMangaCategoriesDialog() R.id.action_download_unread -> downloadUnreadChapters() + R.id.action_mark_as_read -> markReadStatus(true) + R.id.action_mark_as_unread -> markReadStatus(false) R.id.action_delete -> showDeleteMangaDialog() R.id.action_select_all -> selectAllCategoryManga() R.id.action_select_inverse -> selectInverseCategoryManga() @@ -554,6 +556,12 @@ class LibraryController( destroyActionModeIfNeeded() } + private fun markReadStatus(read: Boolean) { + val mangas = selectedMangas.toList() + presenter.markReadStatus(mangas, read) + 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 fd1d280f80..578aece21a 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 @@ -5,6 +5,7 @@ import com.jakewharton.rxrelay.BehaviorRelay 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.Manga import eu.kanade.tachiyomi.data.database.models.MangaCategory import eu.kanade.tachiyomi.data.download.DownloadManager @@ -326,6 +327,36 @@ class LibraryPresenter( } } + /** + * Marks mangas' chapters read status. + * + * @param mangas the list of manga. + */ + fun markReadStatus(mangas: List, read: Boolean) { + mangas.forEach { manga -> + launchIO { + val chapters = db.getChapters(manga).executeAsBlocking() + chapters.forEach { + it.read = read + if (!read) { + it.last_page_read = 0 + } + } + db.updateChaptersProgress(chapters).executeAsBlocking() + + if (preferences.removeAfterMarkedAsRead()) { + deleteChapters(manga, chapters) + } + } + } + } + + private fun deleteChapters(manga: Manga, chapters: List) { + sourceManager.get(manga.source)?.let { source -> + downloadManager.deleteChapters(chapters, manga, source) + } + } + /** * Remove the selected manga from the library. * diff --git a/app/src/main/res/menu/library_selection.xml b/app/src/main/res/menu/library_selection.xml index 1c43d4c762..4815092144 100644 --- a/app/src/main/res/menu/library_selection.xml +++ b/app/src/main/res/menu/library_selection.xml @@ -16,6 +16,20 @@ app:iconTint="?attr/colorOnPrimary" app:showAsAction="always" /> + + + +