mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2025-01-11 04:19:16 +01:00
Downloading/Deleteing batch chapters now ignores current filter
Fixes #761 Also deleting all chapter now delete entire manga folder, not just chapters Also also trying to delete certain type of chapters will pop up "No chapters to delete" if theres... yeah
This commit is contained in:
parent
3177063ada
commit
6906fff121
@ -327,6 +327,7 @@ class DownloadManager(val context: Context) {
|
||||
queue.remove(manga)
|
||||
provider.findMangaDir(manga, source)?.delete()
|
||||
cache.removeManga(manga)
|
||||
queue.updateListeners()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -910,26 +910,31 @@ class MangaDetailsController :
|
||||
|
||||
private fun massDeleteChapters(choice: Int) {
|
||||
val chaptersToDelete = when (choice) {
|
||||
R.id.remove_all -> presenter.chapters
|
||||
R.id.remove_non_bookmarked -> presenter.chapters.filter { !it.bookmark }
|
||||
R.id.remove_read -> presenter.chapters.filter { it.read }
|
||||
R.id.remove_all -> presenter.allChapters
|
||||
R.id.remove_non_bookmarked -> presenter.allChapters.filter { !it.bookmark }
|
||||
R.id.remove_read -> presenter.allChapters.filter { it.read }
|
||||
else -> emptyList()
|
||||
}.filter { it.isDownloaded }
|
||||
if (chaptersToDelete.isNotEmpty()) {
|
||||
massDeleteChapters(chaptersToDelete)
|
||||
if (chaptersToDelete.isNotEmpty() || choice == R.id.remove_all) {
|
||||
massDeleteChapters(chaptersToDelete, choice == R.id.remove_all)
|
||||
} else {
|
||||
snack?.dismiss()
|
||||
snack = view?.snack(R.string.no_chapters_to_delete)
|
||||
}
|
||||
}
|
||||
|
||||
private fun massDeleteChapters(chapters: List<ChapterItem>) {
|
||||
private fun massDeleteChapters(chapters: List<ChapterItem>, isEverything: Boolean) {
|
||||
val context = view?.context ?: return
|
||||
MaterialDialog(context).message(
|
||||
text = context.resources.getQuantityString(
|
||||
text =
|
||||
if (isEverything) context.getString(R.string.remove_all_downloads)
|
||||
else context.resources.getQuantityString(
|
||||
R.plurals.remove_n_chapters,
|
||||
chapters.size,
|
||||
chapters.size
|
||||
)
|
||||
).positiveButton(R.string.remove) {
|
||||
presenter.deleteChapters(chapters)
|
||||
presenter.deleteChapters(chapters, isEverything = isEverything)
|
||||
}.negativeButton(android.R.string.cancel).show()
|
||||
}
|
||||
|
||||
@ -941,8 +946,8 @@ class MangaDetailsController :
|
||||
createActionModeIfNeeded()
|
||||
return
|
||||
}
|
||||
R.id.download_unread -> presenter.chapters.filter { !it.read }
|
||||
R.id.download_all -> presenter.chapters
|
||||
R.id.download_unread -> presenter.allChapters.filter { !it.read }
|
||||
R.id.download_all -> presenter.allChapters
|
||||
else -> emptyList()
|
||||
}
|
||||
if (chaptersToDownload.isNotEmpty()) {
|
||||
|
@ -54,6 +54,7 @@ import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
@ -92,6 +93,9 @@ class MangaDetailsPresenter(
|
||||
var chapters: List<ChapterItem> = emptyList()
|
||||
private set
|
||||
|
||||
var allChapters: List<ChapterItem> = emptyList()
|
||||
private set
|
||||
|
||||
var headerItem = MangaHeaderItem(manga, controller.fromCatalogue)
|
||||
|
||||
fun onCreate() {
|
||||
@ -108,7 +112,7 @@ class MangaDetailsPresenter(
|
||||
controller.updateHeader()
|
||||
refreshAll()
|
||||
} else {
|
||||
updateChapters()
|
||||
runBlocking { getChapters() }
|
||||
controller.updateChapters(this.chapters)
|
||||
}
|
||||
setTrackItems()
|
||||
@ -139,17 +143,7 @@ class MangaDetailsPresenter(
|
||||
setDownloadedChapters(chapters)
|
||||
|
||||
// Store the last emission
|
||||
this.chapters = applyChapterFilters(chapters)
|
||||
}
|
||||
|
||||
private fun updateChapters(fetchedChapters: List<Chapter>? = null) {
|
||||
val chapters =
|
||||
(fetchedChapters ?: db.getChapters(manga).executeAsBlocking()).map { it.toModel() }
|
||||
|
||||
// Find downloaded chapters
|
||||
setDownloadedChapters(chapters)
|
||||
|
||||
// Store the last emission
|
||||
allChapters = chapters
|
||||
this.chapters = applyChapterFilters(chapters)
|
||||
}
|
||||
|
||||
@ -178,7 +172,7 @@ class MangaDetailsPresenter(
|
||||
|
||||
override fun updateDownloads() {
|
||||
scope.launch(Dispatchers.Default) {
|
||||
updateChapters(chapters)
|
||||
getChapters()
|
||||
withContext(Dispatchers.Main) {
|
||||
controller.updateChapters(chapters)
|
||||
}
|
||||
@ -261,12 +255,12 @@ class MangaDetailsPresenter(
|
||||
return chapters.sortedByDescending { it.source_order }.find { !it.read }
|
||||
}
|
||||
|
||||
fun anyRead(): Boolean = chapters.any { it.read }
|
||||
fun hasBookmark(): Boolean = chapters.any { it.bookmark }
|
||||
fun hasDownloads(): Boolean = chapters.any { it.isDownloaded }
|
||||
fun anyRead(): Boolean = allChapters.any { it.read }
|
||||
fun hasBookmark(): Boolean = allChapters.any { it.bookmark }
|
||||
fun hasDownloads(): Boolean = allChapters.any { it.isDownloaded }
|
||||
|
||||
fun getUnreadChaptersSorted() =
|
||||
chapters.filter { !it.read && it.status == Download.NOT_DOWNLOADED }.distinctBy { it.name }
|
||||
allChapters.filter { !it.read && it.status == Download.NOT_DOWNLOADED }.distinctBy { it.name }
|
||||
.sortedByDescending { it.source_order }
|
||||
|
||||
fun startDownloadingNow(chapter: Chapter) {
|
||||
@ -299,8 +293,14 @@ class MangaDetailsPresenter(
|
||||
* Deletes the given list of chapter.
|
||||
* @param chapters the list of chapters to delete.
|
||||
*/
|
||||
fun deleteChapters(chapters: List<ChapterItem>, update: Boolean = true) {
|
||||
downloadManager.deleteChapters(chapters, manga, source)
|
||||
fun deleteChapters(chapters: List<ChapterItem>, update: Boolean = true, isEverything: Boolean = false) {
|
||||
scope.launchIO {
|
||||
if (isEverything) {
|
||||
downloadManager.deleteManga(manga, source)
|
||||
} else {
|
||||
downloadManager.deleteChapters(chapters, manga, source)
|
||||
}
|
||||
}
|
||||
chapters.forEach { chapter ->
|
||||
this.chapters.find { it.id == chapter.id }?.apply {
|
||||
status = Download.QUEUE
|
||||
@ -394,7 +394,7 @@ class MangaDetailsPresenter(
|
||||
}
|
||||
}
|
||||
}
|
||||
withContext(Dispatchers.IO) { updateChapters() }
|
||||
getChapters()
|
||||
}
|
||||
isLoading = false
|
||||
if (chapterError == null) withContext(Dispatchers.Main) { controller.updateChapters(this@MangaDetailsPresenter.chapters) }
|
||||
@ -431,7 +431,7 @@ class MangaDetailsPresenter(
|
||||
try {
|
||||
syncChaptersWithSource(db, chapters, manga, source)
|
||||
|
||||
updateChapters()
|
||||
getChapters()
|
||||
withContext(Dispatchers.Main) { controller.updateChapters(this@MangaDetailsPresenter.chapters) }
|
||||
} catch (e: java.lang.Exception) {
|
||||
withContext(Dispatchers.Main) {
|
||||
@ -534,7 +534,7 @@ class MangaDetailsPresenter(
|
||||
private fun asyncUpdateMangaAndChapters(justChapters: Boolean = false) {
|
||||
scope.launch {
|
||||
if (!justChapters) db.updateFlags(manga).executeOnIO()
|
||||
updateChapters()
|
||||
getChapters()
|
||||
withContext(Dispatchers.Main) { controller.updateChapters(chapters) }
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,9 @@
|
||||
<string name="chapter_not_found">Chapter not found</string>
|
||||
<string name="no_chapters_error">No chapters found</string>
|
||||
<string name="no_pages_found">No pages found</string>
|
||||
<string name="remove_all_downloads">Remove all downloads?</string>
|
||||
<string name="no_chapters_to_delete">No chapters to delete</string>
|
||||
|
||||
<plurals name="remove_n_chapters">
|
||||
<item quantity="one">Remove %1$d downloaded chapter?</item>
|
||||
<item quantity="other">Remove %1$d downloaded chapters?</item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user