TobiasBuchholz / CircularViewPager

This is my implementation of a circular ViewPager
84 stars 22 forks source link

ViewPager current position not updating correctly #11

Open stevendesu opened 6 years ago

stevendesu commented 6 years ago

Update

I fixed half of my issue and made a second post (below). There's still a problem, but at least it's scrolling infinitely now

Original

I'm brand new to Android development, so forgive any terrible code or lack of understanding of simple concepts (like the difference between an Activity and a Fragment)

For my work I was asked to create a simple app with 3 screens that you could cycle between with a swipe, and on each of these screens we wanted a streaming video (same subject, different angles). Because Android supports OpenGL I know that in the worst-case scenario this is guaranteed to be possible by drawing all of the content to the screen myself, but Android had a lot of built-in UI components that seemed to make the job easier. Unfortunately I quickly learned that the ViewPager wouldn't meet my needs - as every solution online suggests you need at least 4 screens (I want 3) and their suggestion of having getCount() return Integer.MAX_VALUE means you can swipe right infinitely, but you still hit 0 if you swipe left.

Then I found this library - and the demo worked perfectly. I believe this will do everything I need. But when I tried to implement it in my project, I got the following behavior:

Load app: Displays screen A
Swipe left: Failed (hit the edge)
Swipe right: Displays screen A
Swipe right: Displays screen B
Swipe right: Displays screen C
Swipe right: Displays screen A
Swipe right: Failed (hit the edge)
Swipe left: Briefly displays screen C, then switches to screen B when the animation completes
Swipe left: Displays screen B again
Swipe left: Displays screen A
Swipe left: Displays screen C
Swipe left: Failed (hit the edge)

Here's a link to the repository where I temporarily uploaded my code (I've removed the license key for our Red5 streaming server from the code, so the video won't work -- but there's a red bar at the bottom of each screen which reads "test 1", "test 2", and "test 3" for each screen)

https://github.com/stevendesu/red5pro-tmp-repo

I'm not sure if I'm doing something wrong or if I found a bug in the library.

stevendesu commented 6 years ago

Doing a line by line comparison between my code and the example provided, I was able to figure out at least one thing I had wrong, but it's still not behaving quite right.

Now I can swipe infinitely, but it's not always loading the right page. I'm updating the repo now with the latest code. It goes something like this:

Swipe right
2 -> 2 -> 3 -> 1 -> 3 -> 3 -> 1 -> 2 -> 3 -> 1 -> 3 -> 3 -> 1 -> 2 -> 3 -> ...
(repeating "1, 2, 3, 1, 3, 3")

Swipe left
2 -> 3 -> 3 -> 1 -> 3 -> 2 -> 1 -> 3 -> 1 -> 1 -> 3 -> 2 -> 1 -> 3 -> 1 -> 1 -> ...
(repeating "3, 2, 1, 3, 1, 1")

So it's close, but not quite right.

Also the app will randomly crash upon swiping. I don't know if it's related to this or my video streaming code.