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

View File

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