App version: 2.0.0 develop
Android version: 10
Expected behaviour:
When switching back and forth between the tabs on the episodes page, the pages should remember their scroll position.
Current behaviour:
The tabs always scroll back to the top
First occurred: Introduction of ViewPager2?
Sorry, I think I found another ViewPager2 bug @ebraminio
Oh well :/ guess that has something to do with offscreen pages it can load like what has configured https://github.com/AntennaPod/AntennaPod/commit/daa93665926bac5302595cf354e1218a0e394347#diff-6b48d5b96db2d4395de1cdddb8ed4267R89 ? I think setOffscreenPageLimit(1) means it only can hold one page but not sure if you are talking about this part of the code.
Hmm, failed to reproduce the issue I think, guess some gif would make it clearer
Looks like layoutManager.findFirstVisibleItemPosition(); in saveScrollPosition always returns -1. I don't think this is your fault. setOffscreenPageLimit(1) means it can hold one page to each direction, so this should be fine. Currently bisecting but I suspect that it is not your fault - sorry for assuming that :D
So git bisect shows that it is in fact caused by ViewPager2: e8166a7f7f162440ca05fa829cf2f78d73293492 is the first bad commit. I added a gif below. I suspect that at the time onPause is called, the RecyclerView is not visible anymore and therefore findFirstVisibleItemPosition() returns -1.
When pausing the app by going to the home screen, the position is saved fine. I guess we need to add a scroll listener to store the value before the fragment is paused.

Oh, indeed annoying, let me see what can be done about it, I didn't see the same in

maybe something is special here.
Yeah, there is something special. It tries to save the scroll position permanently but when retrieving the number, it always is -1. onResume, it then scrolls back to the top.
This issue has been mentioned on AntennaPod Forum. There might be relevant details there:
https://forum.antennapod.org/t/scrolling-through-episodes/76/4
Fixed in #4431