Optimize chapters mapping
This commit is contained in:
@@ -16,7 +16,6 @@ import org.koitharu.kotatsu.parsers.exception.NotFoundException
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.util.mapToSet
|
||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||
|
||||
class MangaDetailsDelegate(
|
||||
@@ -84,7 +83,7 @@ class MangaDetailsDelegate(
|
||||
val dateFormat = settings.getDateFormat()
|
||||
val currentIndex = chapters.indexOfFirst { it.id == currentId }
|
||||
val firstNewIndex = chapters.size - newCount
|
||||
val downloadedIds = downloadedChapters?.mapToSet { it.id }
|
||||
val downloadedIds = downloadedChapters?.mapTo(HashSet(downloadedChapters.size)) { it.id }
|
||||
for (i in chapters.indices) {
|
||||
val chapter = chapters[i]
|
||||
if (chapter.branch != branch) {
|
||||
@@ -99,6 +98,9 @@ class MangaDetailsDelegate(
|
||||
dateFormat = dateFormat,
|
||||
)
|
||||
}
|
||||
if (result.size < chapters.size / 2) {
|
||||
result.trimToSize()
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -154,6 +156,9 @@ class MangaDetailsDelegate(
|
||||
}
|
||||
result.sortBy { it.chapter.number }
|
||||
}
|
||||
if (result.size < sourceChapters.size / 2) {
|
||||
result.trimToSize()
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,24 @@
|
||||
package org.koitharu.kotatsu.details.ui.model
|
||||
|
||||
import java.text.DateFormat
|
||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||
|
||||
class ChapterListItem(
|
||||
val chapter: MangaChapter,
|
||||
val flags: Int,
|
||||
val uploadDate: String?,
|
||||
private val uploadDateMs: Long,
|
||||
private val dateFormat: DateFormat,
|
||||
) {
|
||||
|
||||
var uploadDate: String? = null
|
||||
private set
|
||||
get() {
|
||||
if (field != null) return field
|
||||
if (uploadDateMs == 0L) return null
|
||||
field = dateFormat.format(uploadDateMs)
|
||||
return field
|
||||
}
|
||||
|
||||
val status: Int
|
||||
get() = flags and MASK_STATUS
|
||||
|
||||
@@ -32,7 +43,8 @@ class ChapterListItem(
|
||||
|
||||
if (chapter != other.chapter) return false
|
||||
if (flags != other.flags) return false
|
||||
if (uploadDate != other.uploadDate) return false
|
||||
if (uploadDateMs != other.uploadDateMs) return false
|
||||
if (dateFormat != other.dateFormat) return false
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -40,7 +52,8 @@ class ChapterListItem(
|
||||
override fun hashCode(): Int {
|
||||
var result = chapter.hashCode()
|
||||
result = 31 * result + flags
|
||||
result = 31 * result + (uploadDate?.hashCode() ?: 0)
|
||||
result = 31 * result + uploadDateMs.hashCode()
|
||||
result = 31 * result + dateFormat.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -53,4 +66,4 @@ class ChapterListItem(
|
||||
const val FLAG_DOWNLOADED = 32
|
||||
const val MASK_STATUS = FLAG_UNREAD or FLAG_CURRENT
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
package org.koitharu.kotatsu.details.ui.model
|
||||
|
||||
import java.text.DateFormat
|
||||
import org.koitharu.kotatsu.details.ui.model.ChapterListItem.Companion.FLAG_CURRENT
|
||||
import org.koitharu.kotatsu.details.ui.model.ChapterListItem.Companion.FLAG_DOWNLOADED
|
||||
import org.koitharu.kotatsu.details.ui.model.ChapterListItem.Companion.FLAG_MISSING
|
||||
import org.koitharu.kotatsu.details.ui.model.ChapterListItem.Companion.FLAG_NEW
|
||||
import org.koitharu.kotatsu.details.ui.model.ChapterListItem.Companion.FLAG_UNREAD
|
||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||
import java.text.DateFormat
|
||||
|
||||
fun MangaChapter.toListItem(
|
||||
isCurrent: Boolean,
|
||||
@@ -25,6 +25,7 @@ fun MangaChapter.toListItem(
|
||||
return ChapterListItem(
|
||||
chapter = this,
|
||||
flags = flags,
|
||||
uploadDate = if (uploadDate != 0L) dateFormat.format(uploadDate) else null
|
||||
uploadDateMs = uploadDate,
|
||||
dateFormat = dateFormat,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user