Fix: preload every 20 items, episode number sequence, search stability

This commit is contained in:
tvmon-dev
2026-04-15 20:51:18 +09:00
parent dae2fa6082
commit 6e193ca945
2 changed files with 17 additions and 11 deletions

View File

@@ -420,6 +420,8 @@ val episodes = mutableListOf<Episode>()
"a[href*='/$seriesId/'], a[href*='/${seriesId}/']"
)
var episodeIndex = 0
for (link in allEpisodeLinks) {
val href = link.attr("href")
if (href.isBlank()) continue
@@ -443,7 +445,12 @@ val episodes = mutableListOf<Episode>()
null
}
val finalNumber = episodeTitle ?: episodeId
val finalNumber = if (!episodeTitle.isNullOrBlank()) {
episodeTitle
} else {
episodeIndex++.toString()
}
if (finalNumber in seenNumbers) continue
seenNumbers.add(finalNumber)

View File

@@ -111,6 +111,7 @@ private fun handleRowSelection(position: Int) {
private fun preloadNextPage(categoryKey: String, page: Int) {
if (categoryLoading[categoryKey] == true) return
if (categoryPages[categoryKey] ?: 0 >= page) return
categoryLoading[categoryKey] = true
lifecycleScope.launch {
@@ -322,16 +323,14 @@ private fun loadNextPage(categoryKey: String, page: Int) {
}
private fun checkAndPreload(categoryKey: String, position: Int) {
if (position >= PRELOAD_THRESHOLD) {
val currentPage = categoryPages[categoryKey] ?: 1
val maxPage = categoryMaxPage[categoryKey] ?: 1
val lastPreload = lastPreloadedPage[categoryKey] ?: 0
if (currentPage < maxPage && currentPage > lastPreload) {
Log.w(TAG, "checkAndPreload: $categoryKey at position $position, preloading page ${currentPage + 1}")
lastPreloadedPage[categoryKey] = currentPage
preloadNextPage(categoryKey, currentPage + 1)
}
val currentPage = categoryPages[categoryKey] ?: 1
val maxPage = categoryMaxPage[categoryKey] ?: 1
val thresholdPage = (position / PRELOAD_THRESHOLD) + 1
if (thresholdPage > currentPage && thresholdPage <= maxPage) {
Log.w(TAG, "checkAndPreload: $categoryKey at position $position, preloading page $thresholdPage")
preloadNextPage(categoryKey, thresholdPage)
}
}
}