Fix: preload every 20 items, episode number sequence, search stability
This commit is contained in:
@@ -420,6 +420,8 @@ val episodes = mutableListOf<Episode>()
|
|||||||
"a[href*='/$seriesId/'], a[href*='/${seriesId}/']"
|
"a[href*='/$seriesId/'], a[href*='/${seriesId}/']"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var episodeIndex = 0
|
||||||
|
|
||||||
for (link in allEpisodeLinks) {
|
for (link in allEpisodeLinks) {
|
||||||
val href = link.attr("href")
|
val href = link.attr("href")
|
||||||
if (href.isBlank()) continue
|
if (href.isBlank()) continue
|
||||||
@@ -443,7 +445,12 @@ val episodes = mutableListOf<Episode>()
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
val finalNumber = episodeTitle ?: episodeId
|
val finalNumber = if (!episodeTitle.isNullOrBlank()) {
|
||||||
|
episodeTitle
|
||||||
|
} else {
|
||||||
|
episodeIndex++.toString()
|
||||||
|
}
|
||||||
|
|
||||||
if (finalNumber in seenNumbers) continue
|
if (finalNumber in seenNumbers) continue
|
||||||
seenNumbers.add(finalNumber)
|
seenNumbers.add(finalNumber)
|
||||||
|
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ private fun handleRowSelection(position: Int) {
|
|||||||
|
|
||||||
private fun preloadNextPage(categoryKey: String, page: Int) {
|
private fun preloadNextPage(categoryKey: String, page: Int) {
|
||||||
if (categoryLoading[categoryKey] == true) return
|
if (categoryLoading[categoryKey] == true) return
|
||||||
|
if (categoryPages[categoryKey] ?: 0 >= page) return
|
||||||
categoryLoading[categoryKey] = true
|
categoryLoading[categoryKey] = true
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
@@ -322,16 +323,14 @@ private fun loadNextPage(categoryKey: String, page: Int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkAndPreload(categoryKey: String, position: Int) {
|
private fun checkAndPreload(categoryKey: String, position: Int) {
|
||||||
if (position >= PRELOAD_THRESHOLD) {
|
val currentPage = categoryPages[categoryKey] ?: 1
|
||||||
val currentPage = categoryPages[categoryKey] ?: 1
|
val maxPage = categoryMaxPage[categoryKey] ?: 1
|
||||||
val maxPage = categoryMaxPage[categoryKey] ?: 1
|
|
||||||
val lastPreload = lastPreloadedPage[categoryKey] ?: 0
|
val thresholdPage = (position / PRELOAD_THRESHOLD) + 1
|
||||||
|
|
||||||
if (currentPage < maxPage && currentPage > lastPreload) {
|
if (thresholdPage > currentPage && thresholdPage <= maxPage) {
|
||||||
Log.w(TAG, "checkAndPreload: $categoryKey at position $position, preloading page ${currentPage + 1}")
|
Log.w(TAG, "checkAndPreload: $categoryKey at position $position, preloading page $thresholdPage")
|
||||||
lastPreloadedPage[categoryKey] = currentPage
|
preloadNextPage(categoryKey, thresholdPage)
|
||||||
preloadNextPage(categoryKey, currentPage + 1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user