mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2025-01-11 06:49:08 +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)
|
queue.remove(manga)
|
||||||
provider.findMangaDir(manga, source)?.delete()
|
provider.findMangaDir(manga, source)?.delete()
|
||||||
cache.removeManga(manga)
|
cache.removeManga(manga)
|
||||||
|
queue.updateListeners()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -910,26 +910,31 @@ class MangaDetailsController :
|
|||||||
|
|
||||||
private fun massDeleteChapters(choice: Int) {
|
private fun massDeleteChapters(choice: Int) {
|
||||||
val chaptersToDelete = when (choice) {
|
val chaptersToDelete = when (choice) {
|
||||||
R.id.remove_all -> presenter.chapters
|
R.id.remove_all -> presenter.allChapters
|
||||||
R.id.remove_non_bookmarked -> presenter.chapters.filter { !it.bookmark }
|
R.id.remove_non_bookmarked -> presenter.allChapters.filter { !it.bookmark }
|
||||||
R.id.remove_read -> presenter.chapters.filter { it.read }
|
R.id.remove_read -> presenter.allChapters.filter { it.read }
|
||||||
else -> emptyList()
|
else -> emptyList()
|
||||||
}.filter { it.isDownloaded }
|
}.filter { it.isDownloaded }
|
||||||
if (chaptersToDelete.isNotEmpty()) {
|
if (chaptersToDelete.isNotEmpty() || choice == R.id.remove_all) {
|
||||||
massDeleteChapters(chaptersToDelete)
|
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
|
val context = view?.context ?: return
|
||||||
MaterialDialog(context).message(
|
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,
|
R.plurals.remove_n_chapters,
|
||||||
chapters.size,
|
chapters.size,
|
||||||
chapters.size
|
chapters.size
|
||||||
)
|
)
|
||||||
).positiveButton(R.string.remove) {
|
).positiveButton(R.string.remove) {
|
||||||
presenter.deleteChapters(chapters)
|
presenter.deleteChapters(chapters, isEverything = isEverything)
|
||||||
}.negativeButton(android.R.string.cancel).show()
|
}.negativeButton(android.R.string.cancel).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -941,8 +946,8 @@ class MangaDetailsController :
|
|||||||
createActionModeIfNeeded()
|
createActionModeIfNeeded()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
R.id.download_unread -> presenter.chapters.filter { !it.read }
|
R.id.download_unread -> presenter.allChapters.filter { !it.read }
|
||||||
R.id.download_all -> presenter.chapters
|
R.id.download_all -> presenter.allChapters
|
||||||
else -> emptyList()
|
else -> emptyList()
|
||||||
}
|
}
|
||||||
if (chaptersToDownload.isNotEmpty()) {
|
if (chaptersToDownload.isNotEmpty()) {
|
||||||
|
@ -54,6 +54,7 @@ import kotlinx.coroutines.async
|
|||||||
import kotlinx.coroutines.awaitAll
|
import kotlinx.coroutines.awaitAll
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
@ -92,6 +93,9 @@ class MangaDetailsPresenter(
|
|||||||
var chapters: List<ChapterItem> = emptyList()
|
var chapters: List<ChapterItem> = emptyList()
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
var allChapters: List<ChapterItem> = emptyList()
|
||||||
|
private set
|
||||||
|
|
||||||
var headerItem = MangaHeaderItem(manga, controller.fromCatalogue)
|
var headerItem = MangaHeaderItem(manga, controller.fromCatalogue)
|
||||||
|
|
||||||
fun onCreate() {
|
fun onCreate() {
|
||||||
@ -108,7 +112,7 @@ class MangaDetailsPresenter(
|
|||||||
controller.updateHeader()
|
controller.updateHeader()
|
||||||
refreshAll()
|
refreshAll()
|
||||||
} else {
|
} else {
|
||||||
updateChapters()
|
runBlocking { getChapters() }
|
||||||
controller.updateChapters(this.chapters)
|
controller.updateChapters(this.chapters)
|
||||||
}
|
}
|
||||||
setTrackItems()
|
setTrackItems()
|
||||||
@ -139,17 +143,7 @@ class MangaDetailsPresenter(
|
|||||||
setDownloadedChapters(chapters)
|
setDownloadedChapters(chapters)
|
||||||
|
|
||||||
// Store the last emission
|
// Store the last emission
|
||||||
this.chapters = applyChapterFilters(chapters)
|
allChapters = 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
|
|
||||||
this.chapters = applyChapterFilters(chapters)
|
this.chapters = applyChapterFilters(chapters)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +172,7 @@ class MangaDetailsPresenter(
|
|||||||
|
|
||||||
override fun updateDownloads() {
|
override fun updateDownloads() {
|
||||||
scope.launch(Dispatchers.Default) {
|
scope.launch(Dispatchers.Default) {
|
||||||
updateChapters(chapters)
|
getChapters()
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
controller.updateChapters(chapters)
|
controller.updateChapters(chapters)
|
||||||
}
|
}
|
||||||
@ -261,12 +255,12 @@ class MangaDetailsPresenter(
|
|||||||
return chapters.sortedByDescending { it.source_order }.find { !it.read }
|
return chapters.sortedByDescending { it.source_order }.find { !it.read }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun anyRead(): Boolean = chapters.any { it.read }
|
fun anyRead(): Boolean = allChapters.any { it.read }
|
||||||
fun hasBookmark(): Boolean = chapters.any { it.bookmark }
|
fun hasBookmark(): Boolean = allChapters.any { it.bookmark }
|
||||||
fun hasDownloads(): Boolean = chapters.any { it.isDownloaded }
|
fun hasDownloads(): Boolean = allChapters.any { it.isDownloaded }
|
||||||
|
|
||||||
fun getUnreadChaptersSorted() =
|
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 }
|
.sortedByDescending { it.source_order }
|
||||||
|
|
||||||
fun startDownloadingNow(chapter: Chapter) {
|
fun startDownloadingNow(chapter: Chapter) {
|
||||||
@ -299,8 +293,14 @@ class MangaDetailsPresenter(
|
|||||||
* Deletes the given list of chapter.
|
* Deletes the given list of chapter.
|
||||||
* @param chapters the list of chapters to delete.
|
* @param chapters the list of chapters to delete.
|
||||||
*/
|
*/
|
||||||
fun deleteChapters(chapters: List<ChapterItem>, update: Boolean = true) {
|
fun deleteChapters(chapters: List<ChapterItem>, update: Boolean = true, isEverything: Boolean = false) {
|
||||||
downloadManager.deleteChapters(chapters, manga, source)
|
scope.launchIO {
|
||||||
|
if (isEverything) {
|
||||||
|
downloadManager.deleteManga(manga, source)
|
||||||
|
} else {
|
||||||
|
downloadManager.deleteChapters(chapters, manga, source)
|
||||||
|
}
|
||||||
|
}
|
||||||
chapters.forEach { chapter ->
|
chapters.forEach { chapter ->
|
||||||
this.chapters.find { it.id == chapter.id }?.apply {
|
this.chapters.find { it.id == chapter.id }?.apply {
|
||||||
status = Download.QUEUE
|
status = Download.QUEUE
|
||||||
@ -394,7 +394,7 @@ class MangaDetailsPresenter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
withContext(Dispatchers.IO) { updateChapters() }
|
getChapters()
|
||||||
}
|
}
|
||||||
isLoading = false
|
isLoading = false
|
||||||
if (chapterError == null) withContext(Dispatchers.Main) { controller.updateChapters(this@MangaDetailsPresenter.chapters) }
|
if (chapterError == null) withContext(Dispatchers.Main) { controller.updateChapters(this@MangaDetailsPresenter.chapters) }
|
||||||
@ -431,7 +431,7 @@ class MangaDetailsPresenter(
|
|||||||
try {
|
try {
|
||||||
syncChaptersWithSource(db, chapters, manga, source)
|
syncChaptersWithSource(db, chapters, manga, source)
|
||||||
|
|
||||||
updateChapters()
|
getChapters()
|
||||||
withContext(Dispatchers.Main) { controller.updateChapters(this@MangaDetailsPresenter.chapters) }
|
withContext(Dispatchers.Main) { controller.updateChapters(this@MangaDetailsPresenter.chapters) }
|
||||||
} catch (e: java.lang.Exception) {
|
} catch (e: java.lang.Exception) {
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
@ -534,7 +534,7 @@ class MangaDetailsPresenter(
|
|||||||
private fun asyncUpdateMangaAndChapters(justChapters: Boolean = false) {
|
private fun asyncUpdateMangaAndChapters(justChapters: Boolean = false) {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
if (!justChapters) db.updateFlags(manga).executeOnIO()
|
if (!justChapters) db.updateFlags(manga).executeOnIO()
|
||||||
updateChapters()
|
getChapters()
|
||||||
withContext(Dispatchers.Main) { controller.updateChapters(chapters) }
|
withContext(Dispatchers.Main) { controller.updateChapters(chapters) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,9 @@
|
|||||||
<string name="chapter_not_found">Chapter not found</string>
|
<string name="chapter_not_found">Chapter not found</string>
|
||||||
<string name="no_chapters_error">No chapters found</string>
|
<string name="no_chapters_error">No chapters found</string>
|
||||||
<string name="no_pages_found">No pages 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">
|
<plurals name="remove_n_chapters">
|
||||||
<item quantity="one">Remove %1$d downloaded chapter?</item>
|
<item quantity="one">Remove %1$d downloaded chapter?</item>
|
||||||
<item quantity="other">Remove %1$d downloaded chapters?</item>
|
<item quantity="other">Remove %1$d downloaded chapters?</item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user