Preload doesn't work backward
- Dominant language
- Kotlin
- Stars
- 721
- Forks
- 162
- PR merge metrics
- No merged PRs in 30d
Description
Hi ! Thank you for this example of PreloadManager.
I have noticed a small issue, I don't know if this is intentional or not so please do tell.
When scrolling forward the app preloads the 2 next item under a certain threshold, but when scrolling back, it doesn't add the 2 previous items.
where x is the user current video index
x 0 -> NOT PRELOADED
1 -> PRELOADED
2 -> PRELOADED
3 -> PRELOADED
4 -> PRELOADED
...
0 -> NOT PRELOADED
1 -> NOT PRELOADED and removed from dequeue
2 -> NOT PRELOADED and removed from dequeue
x 3 -> PRELOADED
4 -> PRELOADED
5 -> PRELOADED
6 -> PRELOADED
0 -> NOT PRELOADED
1 -> NOT PRELOADED and removed from dequeue
x 2 -> NOT PRELOADED and removed from dequeue
3 -> PRELOADED
4 -> PRELOADED
5 -> PRELOADED
6 -> PRELOADED
So when going back to index 2, it's not preloading index 1 or 0. Keeping the 2 previous items is quite easy with the snippet below, but there is still the process of getting the starting video back to preload
```kotlin
private fun preloadNextItems() {
var lastPreloadedIndex = 0
if (!preloadWindow.isEmpty()) {
lastPreloadedIndex = preloadWindow.last().second
}
if (lastPreloadedIndex - currentPlayingIndex <= itemsRemainingToStartNextPreloading) {
for (i in 1 until (preloadWindowMaxSize - itemsRemainingToStartNextPreloading)) {
addMediaItem(index = lastPreloadedIndex + i)
if(preloadWindow.size > preloadWindowMaxSize + 2) {
removeMediaItem()
}
}
}
// With invalidate, preload manager will internally sort the priorities of all the media items added to it, and trigger the preload from the most important one.
defaultPreloadManager.invalidate()
}
```
Contributor guide
Research direction
Start at the preloadNextItems() logic described in the issue and inspect how preloadWindow, currentPlayingIndex, and defaultPreloadManager are updated during backward scrolling. Reproduce the forward-then-backward sequence, then verify that previously removed earlier indexes are added and preloaded when scrolling back.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100