Fix resume button not considering filters

(cherry picked from commit 685736b9ec426384603eb421937b5500ee6e849c)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt
This commit is contained in:
arkon 2021-05-23 12:02:09 -04:00 committed by Jobobby04
parent e9a21a6bbe
commit 666447faac
2 changed files with 24 additions and 20 deletions

View File

@ -1103,7 +1103,7 @@ class MangaController :
fun onNextChapters(chapters: List<ChapterItem>) {
// If the list is empty and it hasn't requested previously, fetch chapters from source
// We use presenter chapters instead because they are always unfiltered
if (!presenter.hasRequested && presenter.chapters.isEmpty()) {
if (!presenter.hasRequested && presenter.allChapters.isEmpty()) {
fetchChaptersFromSource()
}
@ -1442,8 +1442,8 @@ class MangaController :
showCustomDownloadDialog()
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()) {
@ -1455,7 +1455,7 @@ class MangaController :
private fun showCustomDownloadDialog() {
DownloadCustomChaptersDialog(
this,
presenter.chapters.size
presenter.allChapters.size
).showDialog(router)
}

View File

@ -99,10 +99,9 @@ class MangaPresenter(
*/
private var fetchMangaJob: Job? = null
/**
* List of chapters of the manga. It's always unfiltered and unsorted.
*/
var chapters: List<ChapterItem> = emptyList()
var allChapters: List<ChapterItem> = emptyList()
private set
var filteredAndSortedChapters: List<ChapterItem> = emptyList()
private set
/**
@ -198,7 +197,13 @@ class MangaPresenter(
// Prepare the relay.
chaptersRelay.flatMap { applyChapterFilters(it) }
.observeOn(AndroidSchedulers.mainThread())
.subscribeLatestCache(MangaController::onNextChapters) { _, error -> Timber.e(error) }
.subscribeLatestCache(
{ _, chapters ->
filteredAndSortedChapters = chapters
view?.onNextChapters(chapters)
},
{ _, error -> Timber.e(error) }
)
// Manga info - end
@ -219,7 +224,7 @@ class MangaPresenter(
allChapterScanlators = chapters.flatMap { MdUtil.getScanlators(it.chapter.scanlator) }.toSet()
// Store the last emission
this.chapters = chapters
this.allChapters = chapters
// Listen for download status changes
observeDownloads()
@ -805,7 +810,7 @@ class MangaPresenter(
* Updates the UI after applying the filters.
*/
private fun refreshChapters() {
chaptersRelay.call(chapters)
chaptersRelay.call(allChapters)
}
/**
@ -854,7 +859,7 @@ class MangaPresenter(
private fun onDownloadStatusChange(download: Download) {
// Assign the download to the model object.
if (download.status == Download.State.QUEUE) {
chapters.find { it.id == download.chapter.id }?.let {
allChapters.find { it.id == download.chapter.id }?.let {
if (it.download == null) {
it.download = download
}
@ -871,24 +876,23 @@ class MangaPresenter(
* Returns the next unread chapter or null if everything is read.
*/
fun getNextUnreadChapter(): ChapterItem? {
val chapters = chapters.sortedWith(getChapterSort(manga))
return if (source.isEhBasedSource()) {
if (sortDescending()) {
chapters.firstOrNull()?.takeUnless { it.read }
filteredAndSortedChapters.firstOrNull()?.takeUnless { it.read }
} else {
chapters.lastOrNull()?.takeUnless { it.read }
filteredAndSortedChapters.lastOrNull()?.takeUnless { it.read }
}
} else {
if (sortDescending()) {
return chapters.findLast { !it.read }
return filteredAndSortedChapters.findLast { !it.read }
} else {
chapters.find { !it.read }
filteredAndSortedChapters.find { !it.read }
}
}
}
fun getUnreadChaptersSorted(): List<ChapterItem> {
val chapters = chapters
val chapters = allChapters
.sortedWith(getChapterSort(manga))
.filter { !it.read && it.status == Download.State.NOT_DOWNLOADED }
.distinctBy { it.name }
@ -1175,7 +1179,7 @@ class MangaPresenter(
db.insertTrack(track).executeAsBlocking()
if (it.service is UnattendedTrackService) {
syncChaptersWithTrackServiceTwoWay(db, chapters, track, it.service)
syncChaptersWithTrackServiceTwoWay(db, allChapters, track, it.service)
}
}
}
@ -1212,7 +1216,7 @@ class MangaPresenter(
db.insertTrack(item).executeAsBlocking()
if (service is UnattendedTrackService) {
syncChaptersWithTrackServiceTwoWay(db, chapters, item, service)
syncChaptersWithTrackServiceTwoWay(db, allChapters, item, service)
}
} catch (e: Throwable) {
this@MangaPresenter.xLogD("Error registering tracking", e)