Fix resume button not considering filters
This commit is contained in:
parent
aefd2bf6f8
commit
685736b9ec
2 changed files with 22 additions and 18 deletions
|
@ -690,7 +690,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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1029,8 +1029,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()) {
|
||||||
|
@ -1042,7 +1042,7 @@ class MangaController :
|
||||||
private fun showCustomDownloadDialog() {
|
private fun showCustomDownloadDialog() {
|
||||||
DownloadCustomChaptersDialog(
|
DownloadCustomChaptersDialog(
|
||||||
this,
|
this,
|
||||||
presenter.chapters.size
|
presenter.allChapters.size
|
||||||
).showDialog(router)
|
).showDialog(router)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,10 +66,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
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,7 +124,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
|
||||||
|
|
||||||
|
@ -144,7 +149,7 @@ class MangaPresenter(
|
||||||
setDownloadedChapters(chapters)
|
setDownloadedChapters(chapters)
|
||||||
|
|
||||||
// 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()
|
||||||
|
@ -402,7 +407,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)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -444,7 +449,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
|
||||||
}
|
}
|
||||||
|
@ -461,16 +466,15 @@ 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 (sortDescending()) {
|
return 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 }
|
||||||
|
@ -708,7 +712,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -743,7 +747,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) {
|
||||||
withUIContext { view?.applicationContext?.toast(e.message) }
|
withUIContext { view?.applicationContext?.toast(e.message) }
|
||||||
|
|
Reference in a new issue