From cc2f9d4529ce35a67dcac087aa0b60b31d87f011 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Thu, 12 Oct 2023 13:24:51 +0300 Subject: [PATCH] Improve chapters mapping --- .../org/koitharu/kotatsu/details/ui/ChaptersMapper.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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,