From 7ed25704d6fb425a24d0f5ec93be8c7ac5bf41a4 Mon Sep 17 00:00:00 2001 From: Hunter Nickel Date: Fri, 1 Oct 2021 06:11:31 -0600 Subject: [PATCH] Add chapter bookmarking feature to Updates screen (#5984) --- .../ui/recent/updates/UpdatesAdapter.kt | 1 + .../ui/recent/updates/UpdatesController.kt | 9 +++++++++ .../ui/recent/updates/UpdatesHolder.kt | 7 +++++-- .../ui/recent/updates/UpdatesPresenter.kt | 16 ++++++++++++++++ app/src/main/res/layout/updates_item.xml | 18 ++++++++++++++++-- .../res/menu/updates_chapter_selection.xml | 14 ++++++++++++++ 6 files changed, 61 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesAdapter.kt index 78a5b8e656..96bb1b1eb1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesAdapter.kt @@ -13,6 +13,7 @@ class UpdatesAdapter( var readColor = context.getResourceColor(R.attr.colorOnSurface, 0.38f) var unreadColor = context.getResourceColor(R.attr.colorOnSurface) + var bookmarkedColor = context.getResourceColor(R.attr.colorAccent) val coverClickListener: OnCoverClickListener = controller diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt index d51f2de032..66613d764c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt @@ -324,6 +324,11 @@ class UpdatesController : presenter.startDownloadingNow(chapter) } + private fun bookmarkChapters(chapters: List, bookmarked: Boolean) { + presenter.bookmarkChapters(chapters, bookmarked) + destroyActionModeIfNeeded() + } + /** * Called when ActionMode created. * @param mode the ActionMode object @@ -346,6 +351,8 @@ class UpdatesController : val chapters = getSelectedChapters() binding.actionToolbar.findItem(R.id.action_download)?.isVisible = chapters.any { !it.isDownloaded } binding.actionToolbar.findItem(R.id.action_delete)?.isVisible = chapters.any { it.isDownloaded } + binding.actionToolbar.findItem(R.id.action_bookmark)?.isVisible = chapters.any { !it.bookmark } + binding.actionToolbar.findItem(R.id.action_remove_bookmark)?.isVisible = chapters.all { it.bookmark } binding.actionToolbar.findItem(R.id.action_mark_as_read)?.isVisible = chapters.any { !it.chapter.read } binding.actionToolbar.findItem(R.id.action_mark_as_unread)?.isVisible = chapters.all { it.chapter.read } } @@ -370,6 +377,8 @@ class UpdatesController : R.id.action_delete -> ConfirmDeleteChaptersDialog(this, getSelectedChapters()) .showDialog(router) + R.id.action_bookmark -> bookmarkChapters(getSelectedChapters(), true) + R.id.action_remove_bookmark -> bookmarkChapters(getSelectedChapters(), false) R.id.action_mark_as_read -> markAsRead(getSelectedChapters()) R.id.action_mark_as_unread -> markAsUnread(getSelectedChapters()) else -> return false diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesHolder.kt index 5ba0c7dfb5..e0ed10d5b2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesHolder.kt @@ -39,15 +39,18 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter) // Set manga title binding.mangaTitle.text = item.manga.title - // Check if chapter is read and set correct color + // Check if chapter is read and/or bookmarked and set correct color if (item.chapter.read) { binding.chapterTitle.setTextColor(adapter.readColor) binding.mangaTitle.setTextColor(adapter.readColor) } else { - binding.chapterTitle.setTextColor(adapter.unreadColor) binding.mangaTitle.setTextColor(adapter.unreadColor) + binding.chapterTitle.setTextColor(if (item.bookmark) adapter.bookmarkedColor else adapter.unreadColor) } + // Set bookmark status + binding.bookmarkIcon.isVisible = item.bookmark + // Set chapter status binding.download.isVisible = item.manga.source != LocalSource.ID binding.download.setState(item.status, item.progress) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt index d15183063a..e1ccdcdda6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt @@ -180,6 +180,22 @@ class UpdatesPresenter : BasePresenter() { ) } + /** + * Mark selected chapters as bookmarked + * @param items list of selected chapters + * @param bookmarked bookmark status + */ + fun bookmarkChapters(items: List, bookmarked: Boolean) { + val chapters = items.map { it.chapter } + chapters.forEach { + it.bookmark = bookmarked + } + + Observable.fromCallable { db.updateChaptersProgress(chapters).executeAsBlocking() } + .subscribeOn(Schedulers.io()) + .subscribe() + } + /** * Download selected chapters * @param items list of recent chapters seleted. diff --git a/app/src/main/res/layout/updates_item.xml b/app/src/main/res/layout/updates_item.xml index 257b9aeea4..23bdf2d9a8 100644 --- a/app/src/main/res/layout/updates_item.xml +++ b/app/src/main/res/layout/updates_item.xml @@ -37,17 +37,31 @@ app:layout_constraintVertical_chainStyle="packed" tools:text="Manga title" /> + + diff --git a/app/src/main/res/menu/updates_chapter_selection.xml b/app/src/main/res/menu/updates_chapter_selection.xml index 40713c00c4..1de5670e5d 100644 --- a/app/src/main/res/menu/updates_chapter_selection.xml +++ b/app/src/main/res/menu/updates_chapter_selection.xml @@ -16,6 +16,20 @@ app:iconTint="?attr/colorOnToolbar" app:showAsAction="always" /> + + + +