Skip to content

Commit 7003ffd

Browse files
authored
Merge pull request smarteist#169 from SrgGrch/master
Fixed bug that led to wrong position calculation in InfinitePagerAdapter.
2 parents 2220d9b + ab14435 commit 7003ffd

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

autoimageslider/src/main/java/com/smarteist/autoimageslider/InfiniteAdapter/InfinitePagerAdapter.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,15 @@ public int getRealCount() {
5757
* @return virtual mid point
5858
*/
5959
public int getMiddlePosition(int item) {
60-
int adapterCount = getRealCount() - 1;
61-
adapterCount = adapterCount == 0 ? 1 : adapterCount;
60+
int realCount = getRealCount();
61+
int adapterCount = realCount - 1 == 0 ? 1 : realCount - 1;
6262
int midpoint = adapterCount * (InfinitePagerAdapter.INFINITE_SCROLL_LIMIT / 2);
63-
return item + midpoint;
63+
64+
if (realCount != 0 && midpoint % realCount != 0) {
65+
return midpoint + (realCount - midpoint % realCount) + item;
66+
} else {
67+
return midpoint + item;
68+
}
6469
}
6570

6671
@NonNull

0 commit comments

Comments
 (0)