mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-24 05:38:01 +03:00
Add ability to download unread chapters from library
This commit is contained in:
parent
963cf4c996
commit
d9a12d79b0
6 changed files with 48 additions and 13 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -313,6 +313,22 @@ class LibraryPresenter(
|
|||
.reduce { set1: Iterable<Category>, 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<Manga>) {
|
||||
mangas.forEach { manga ->
|
||||
launchIO {
|
||||
val chapters = db.getChapters(manga).executeAsBlocking()
|
||||
.filter { !it.read }
|
||||
|
||||
downloadManager.downloadChapters(manga, chapters)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the selected manga from the library.
|
||||
*
|
||||
|
|
|
@ -745,9 +745,6 @@ class MangaInfoChaptersController(private val fromSource: Boolean = false) :
|
|||
|
||||
private fun markAsRead(chapters: List<ChapterItem>) {
|
||||
presenter.markChaptersRead(chapters, true)
|
||||
if (presenter.preferences.removeAfterMarkedAsRead()) {
|
||||
deleteChapters(chapters)
|
||||
}
|
||||
destroyActionModeIfNeeded()
|
||||
}
|
||||
|
||||
|
|
|
@ -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<ChapterItem>, 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,13 @@
|
|||
app:iconTint="?attr/colorOnPrimary"
|
||||
app:showAsAction="always" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_download_unread"
|
||||
android:icon="@drawable/ic_get_app_24dp"
|
||||
android:title="@string/action_download_unread"
|
||||
app:iconTint="?attr/colorOnPrimary"
|
||||
app:showAsAction="always" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_delete"
|
||||
android:icon="@drawable/ic_delete_24dp"
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
<string name="action_mark_as_unread">Mark as unread</string>
|
||||
<string name="action_mark_previous_as_read">Mark previous as read</string>
|
||||
<string name="action_download">Download</string>
|
||||
<string name="action_download_unread">Download unread chapters</string>
|
||||
<string name="action_bookmark">Bookmark</string>
|
||||
<string name="action_remove_bookmark">Unbookmark</string>
|
||||
<string name="action_delete">Delete</string>
|
||||
|
|
Loading…
Reference in a new issue