diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/ChaptersMapper.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/ChaptersMapper.kt index 5a4209f9b..f525f7c8e 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/ChaptersMapper.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/ChaptersMapper.kt @@ -21,12 +21,11 @@ fun MangaDetails.mapChapters( val bookmarked = bookmarks.mapToSet { it.chapterId } val currentId = history?.chapterId ?: 0L val newFrom = if (newCount == 0 || remoteChapters.isEmpty()) Int.MAX_VALUE else remoteChapters.size - newCount - val chaptersSize = maxOf(remoteChapters.size, localChapters.size) - val ids = buildSet(chaptersSize) { + val ids = buildSet(maxOf(remoteChapters.size, localChapters.size)) { remoteChapters.mapTo(this) { it.id } localChapters.mapTo(this) { it.id } } - val result = ArrayList(chaptersSize) + val result = ArrayList(ids.size) val localMap = if (localChapters.isNotEmpty()) { localChapters.associateByTo(LinkedHashMap(localChapters.size)) { it.id } } else { @@ -38,7 +37,7 @@ fun MangaDetails.mapChapters( if (chapter.id == currentId) { isUnread = true } - result += chapter.toListItem( + result += (local ?: chapter).toListItem( isCurrent = chapter.id == currentId, isUnread = isUnread, isNew = isUnread && result.size >= newFrom,