mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Allow deleting bookmarked chapters option
Some minor tweaks to this: * tapping delete download on manga details/recents WILL delete the chapter, regardless of bookmark status * Tapping Remove all downloads in manga details will remove all downloads still, since there's an option to remove all but bookmarks anyway (library like upstream still deletes all) closes #1470 Co-Authored-By: arkon <4098258+arkon@users.noreply.github.com>
This commit is contained in:
parent
3fecc0bedb
commit
15a16048ae
6 changed files with 33 additions and 10 deletions
|
@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.data.download.model.Download
|
import eu.kanade.tachiyomi.data.download.model.Download
|
||||||
import eu.kanade.tachiyomi.data.download.model.DownloadQueue
|
import eu.kanade.tachiyomi.data.download.model.DownloadQueue
|
||||||
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.source.Source
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
import eu.kanade.tachiyomi.source.model.Page
|
import eu.kanade.tachiyomi.source.model.Page
|
||||||
|
@ -31,6 +32,8 @@ class DownloadManager(val context: Context) {
|
||||||
*/
|
*/
|
||||||
private val sourceManager by injectLazy<SourceManager>()
|
private val sourceManager by injectLazy<SourceManager>()
|
||||||
|
|
||||||
|
private val preferences by injectLazy<PreferencesHelper>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads provider, used to retrieve the folders where the chapters are or should be stored.
|
* Downloads provider, used to retrieve the folders where the chapters are or should be stored.
|
||||||
*/
|
*/
|
||||||
|
@ -249,16 +252,17 @@ class DownloadManager(val context: Context) {
|
||||||
* @param manga the manga of the chapters.
|
* @param manga the manga of the chapters.
|
||||||
* @param source the source of the chapters.
|
* @param source the source of the chapters.
|
||||||
*/
|
*/
|
||||||
fun deleteChapters(chapters: List<Chapter>, manga: Manga, source: Source) {
|
fun deleteChapters(chapters: List<Chapter>, manga: Manga, source: Source, force: Boolean = false) {
|
||||||
|
val filteredChapters = if (force) chapters else getChaptersToDelete(chapters, manga)
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
val wasPaused = isPaused()
|
val wasPaused = isPaused()
|
||||||
if (chapters.isEmpty()) {
|
if (filteredChapters.isEmpty()) {
|
||||||
DownloadService.stop(context)
|
DownloadService.stop(context)
|
||||||
downloader.queue.clear()
|
downloader.queue.clear()
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
downloader.pause()
|
downloader.pause()
|
||||||
downloader.queue.remove(chapters)
|
downloader.queue.remove(filteredChapters)
|
||||||
if (!wasPaused && downloader.queue.isNotEmpty()) {
|
if (!wasPaused && downloader.queue.isNotEmpty()) {
|
||||||
downloader.start()
|
downloader.start()
|
||||||
DownloadService.callListeners(true)
|
DownloadService.callListeners(true)
|
||||||
|
@ -268,15 +272,15 @@ class DownloadManager(val context: Context) {
|
||||||
DownloadService.callListeners(false)
|
DownloadService.callListeners(false)
|
||||||
downloader.stop()
|
downloader.stop()
|
||||||
}
|
}
|
||||||
queue.remove(chapters)
|
queue.remove(filteredChapters)
|
||||||
val chapterDirs =
|
val chapterDirs =
|
||||||
provider.findChapterDirs(chapters, manga, source) + provider.findTempChapterDirs(
|
provider.findChapterDirs(filteredChapters, manga, source) + provider.findTempChapterDirs(
|
||||||
chapters,
|
filteredChapters,
|
||||||
manga,
|
manga,
|
||||||
source,
|
source,
|
||||||
)
|
)
|
||||||
chapterDirs.forEach { it.delete() }
|
chapterDirs.forEach { it.delete() }
|
||||||
cache.removeChapters(chapters, manga)
|
cache.removeChapters(filteredChapters, manga)
|
||||||
if (cache.getDownloadCount(manga, true) == 0) { // Delete manga directory if empty
|
if (cache.getDownloadCount(manga, true) == 0) { // Delete manga directory if empty
|
||||||
chapterDirs.firstOrNull()?.parentFile?.delete()
|
chapterDirs.firstOrNull()?.parentFile?.delete()
|
||||||
}
|
}
|
||||||
|
@ -356,7 +360,7 @@ class DownloadManager(val context: Context) {
|
||||||
* @param manga the manga of the chapters.
|
* @param manga the manga of the chapters.
|
||||||
*/
|
*/
|
||||||
fun enqueueDeleteChapters(chapters: List<Chapter>, manga: Manga) {
|
fun enqueueDeleteChapters(chapters: List<Chapter>, manga: Manga) {
|
||||||
pendingDeleter.addChapters(chapters, manga)
|
pendingDeleter.addChapters(getChaptersToDelete(chapters, manga), manga)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -398,4 +402,13 @@ class DownloadManager(val context: Context) {
|
||||||
|
|
||||||
fun addListener(listener: DownloadQueue.DownloadListener) = queue.addListener(listener)
|
fun addListener(listener: DownloadQueue.DownloadListener) = queue.addListener(listener)
|
||||||
fun removeListener(listener: DownloadQueue.DownloadListener) = queue.removeListener(listener)
|
fun removeListener(listener: DownloadQueue.DownloadListener) = queue.removeListener(listener)
|
||||||
|
|
||||||
|
private fun getChaptersToDelete(chapters: List<Chapter>, manga: Manga): List<Chapter> {
|
||||||
|
// Retrieve the categories that are set to exclude from being deleted on read
|
||||||
|
return if (!preferences.removeBookmarkedChapters().get()) {
|
||||||
|
chapters.filterNot { it.bookmark }
|
||||||
|
} else {
|
||||||
|
chapters
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -393,6 +393,8 @@ class PreferencesHelper(val context: Context) {
|
||||||
|
|
||||||
fun deleteRemovedChapters() = flowPrefs.getInt(Keys.deleteRemovedChapters, 0)
|
fun deleteRemovedChapters() = flowPrefs.getInt(Keys.deleteRemovedChapters, 0)
|
||||||
|
|
||||||
|
fun removeBookmarkedChapters() = flowPrefs.getBoolean("pref_remove_bookmarked", false)
|
||||||
|
|
||||||
fun showAllCategories() = flowPrefs.getBoolean("show_all_categories", true)
|
fun showAllCategories() = flowPrefs.getBoolean("show_all_categories", true)
|
||||||
|
|
||||||
fun showAllCategoriesWhenSearchingSingleCategory() = flowPrefs.getBoolean("show_all_categories_when_searching_single_category", false)
|
fun showAllCategoriesWhenSearchingSingleCategory() = flowPrefs.getBoolean("show_all_categories_when_searching_single_category", false)
|
||||||
|
|
|
@ -280,8 +280,9 @@ class MangaDetailsPresenter(
|
||||||
* @param chapter the chapter to delete.
|
* @param chapter the chapter to delete.
|
||||||
*/
|
*/
|
||||||
fun deleteChapter(chapter: ChapterItem) {
|
fun deleteChapter(chapter: ChapterItem) {
|
||||||
downloadManager.deleteChapters(listOf(chapter), manga, source)
|
downloadManager.deleteChapters(listOf(chapter), manga, source, true)
|
||||||
this.chapters.find { it.id == chapter.id }?.apply {
|
this.chapters.find { it.id == chapter.id }?.apply {
|
||||||
|
if (chapter.chapter.bookmark && !preferences.removeBookmarkedChapters().get()) return@apply
|
||||||
status = Download.State.QUEUE
|
status = Download.State.QUEUE
|
||||||
download = null
|
download = null
|
||||||
}
|
}
|
||||||
|
@ -303,6 +304,7 @@ class MangaDetailsPresenter(
|
||||||
}
|
}
|
||||||
chapters.forEach { chapter ->
|
chapters.forEach { chapter ->
|
||||||
this.chapters.find { it.id == chapter.id }?.apply {
|
this.chapters.find { it.id == chapter.id }?.apply {
|
||||||
|
if (chapter.chapter.bookmark && !preferences.removeBookmarkedChapters().get() && !isEverything) return@apply
|
||||||
status = Download.State.QUEUE
|
status = Download.State.QUEUE
|
||||||
download = null
|
download = null
|
||||||
}
|
}
|
||||||
|
|
|
@ -425,11 +425,12 @@ class RecentsPresenter(
|
||||||
fun deleteChapter(chapter: Chapter, manga: Manga, update: Boolean = true) {
|
fun deleteChapter(chapter: Chapter, manga: Manga, update: Boolean = true) {
|
||||||
val source = Injekt.get<SourceManager>().getOrStub(manga.source)
|
val source = Injekt.get<SourceManager>().getOrStub(manga.source)
|
||||||
launchIO {
|
launchIO {
|
||||||
downloadManager.deleteChapters(listOf(chapter), manga, source)
|
downloadManager.deleteChapters(listOf(chapter), manga, source, true)
|
||||||
}
|
}
|
||||||
if (update) {
|
if (update) {
|
||||||
val item = recentItems.find { it.chapter.id == chapter.id } ?: return
|
val item = recentItems.find { it.chapter.id == chapter.id } ?: return
|
||||||
item.apply {
|
item.apply {
|
||||||
|
if (chapter.bookmark && !preferences.removeBookmarkedChapters().get()) return@apply
|
||||||
status = Download.State.NOT_DOWNLOADED
|
status = Download.State.NOT_DOWNLOADED
|
||||||
download = null
|
download = null
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,10 @@ class SettingsDownloadController : SettingsController() {
|
||||||
entryRange = -1..4
|
entryRange = -1..4
|
||||||
defaultValue = -1
|
defaultValue = -1
|
||||||
}
|
}
|
||||||
|
switchPreference {
|
||||||
|
bindTo(preferences.removeBookmarkedChapters())
|
||||||
|
titleRes = R.string.allow_deleting_bookmarked_chapters
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val dbCategories = db.getCategories().executeAsBlocking()
|
val dbCategories = db.getCategories().executeAsBlocking()
|
||||||
|
|
|
@ -955,6 +955,7 @@
|
||||||
<string name="download_location">Download location</string>
|
<string name="download_location">Download location</string>
|
||||||
<string name="only_download_over_wifi">Only download over Wi-Fi</string>
|
<string name="only_download_over_wifi">Only download over Wi-Fi</string>
|
||||||
<string name="remove_when_marked_as_read">Remove when marked as read</string>
|
<string name="remove_when_marked_as_read">Remove when marked as read</string>
|
||||||
|
<string name="allow_deleting_bookmarked_chapters">Allow deleting bookmarked chapters</string>
|
||||||
<string name="remove_after_read">Remove after read</string>
|
<string name="remove_after_read">Remove after read</string>
|
||||||
<string name="custom_location">Custom location</string>
|
<string name="custom_location">Custom location</string>
|
||||||
<string name="last_read_chapter">Last read chapter</string>
|
<string name="last_read_chapter">Last read chapter</string>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue