Crash fixes in recents

This commit is contained in:
Jays2Kings 2021-04-11 12:34:52 -04:00
parent 48dae05980
commit 780585caed
2 changed files with 7 additions and 5 deletions

View File

@ -61,6 +61,6 @@ class RecentMangaItem(
val showRemoveHistory = (adapter as? RecentMangaAdapter)?.showRemoveHistory ?: true
val showTitleFirst = (adapter as? RecentMangaAdapter)?.showTitleFirst ?: false
if (mch.manga.id == null) (holder as? RecentMangaFooterHolder)?.bind((header as? RecentMangaHeaderItem)?.recentsType ?: 0)
else (holder as? RecentMangaHolder)?.bind(this, showDLs, showRemoveHistory, showTitleFirst)
else if (chapter.id != null) (holder as? RecentMangaHolder)?.bind(this, showDLs, showRemoveHistory, showTitleFirst)
}
}

View File

@ -40,6 +40,7 @@ class RecentsPresenter(
private var scope = CoroutineScope(Job() + Dispatchers.Default)
private var recentsJob: Job? = null
var recentItems = listOf<RecentMangaItem>()
private set
var query = ""
@ -88,10 +89,11 @@ class RecentsPresenter(
getRecents()
}
fun getRecents(updatePageCount: Boolean = false, retryCount: Int = 0, itemCount: Int = 0) {
fun getRecents(updatePageCount: Boolean = false) {
val oldQuery = query
scope.launch {
runRecents(oldQuery, updatePageCount, retryCount, itemCount)
recentsJob?.cancel()
recentsJob = scope.launch {
runRecents(oldQuery, updatePageCount)
}
}
@ -320,7 +322,7 @@ class RecentsPresenter(
* @param chapters the list of chapter from the database.
*/
private fun setDownloadedChapters(chapters: List<RecentMangaItem>) {
for (item in chapters) {
for (item in chapters.filter { it.chapter.id != null }) {
if (downloadManager.isChapterDownloaded(item.chapter, item.mch.manga)) {
item.status = Download.DOWNLOADED
} else if (downloadManager.hasQueue()) {