From 4fdb245b14a2e03aa455339eada2e0591799a2c3 Mon Sep 17 00:00:00 2001 From: Saud-97 Date: Tue, 30 Jan 2024 18:54:42 +0300 Subject: [PATCH] Added long click shortcut to mark chapter as read in Reader view chapter list sheet --- .../kanade/tachiyomi/ui/reader/ReaderViewModel.kt | 12 ++++++++++++ .../ui/reader/chapter/ReaderChapterSheet.kt | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt index b32142fe717f..4cfdae9bc52c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt @@ -430,6 +430,18 @@ class ReaderViewModel( db.updateChapterProgress(chapter).executeAsBlocking() } + fun toggleRead(chapter: Chapter) { + chapter.read = !chapter.read + db.updateChapterProgress(chapter).executeAsBlocking() + if (chapter.read) { + if (preferences.removeAfterMarkedAsRead()) { + enqueueDeleteReadChapters(ReaderChapter(chapter)) + } else { + deleteChapterIfNeeded(ReaderChapter(chapter)) + } + } + } + /** * Called when the viewers decide it's a good time to preload a [chapter] and improve the UX so * that the user doesn't have to wait too long to continue reading. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt index 756c4cdc6f25..139e187e4550 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt @@ -180,6 +180,19 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr adapter = FastAdapter.with(itemAdapter) binding.chapterRecycler.adapter = adapter + adapter?.onLongClickListener = { _, _, item, _ -> + + if (!sheetBehavior.isExpanded() || activity.isLoading) { + false + } else { + if (item.chapter.id != viewModel.getCurrentChapter()?.chapter?.id) { + viewModel.toggleRead(item.chapter) + refreshList() + } + true + } + } + adapter?.onClickListener = { _, _, item, position -> if (!sheetBehavior.isExpanded() || activity.isLoading) { false