Skip to content

Commit 0948f34

Browse files
author
Nikita Olifer
committed
Useless checks was removed. Division by zero fix.
1 parent 75cd3cc commit 0948f34

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

library/src/main/java/ru/tinkoff/scrollingpagerindicator/RecyclerViewAttacher.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
9393
int newPosition = findCompletelyVisiblePosition();
9494
if (newPosition != RecyclerView.NO_POSITION) {
9595
indicator.setDotCount(adapter.getItemCount());
96-
if (newPosition >= 0 && newPosition < adapter.getItemCount()) {
96+
if (newPosition < adapter.getItemCount()) {
9797
indicator.setCurrentPosition(newPosition);
9898
}
9999
}
@@ -126,15 +126,16 @@ private void updateCurrentOffset() {
126126
if (position == RecyclerView.NO_POSITION) {
127127
return;
128128
}
129+
final int itemCount = adapter.getItemCount();
129130

130131
// In case there is an infinite pager
131-
if (position >= adapter.getItemCount()) {
132-
position = position % adapter.getItemCount();
132+
if (position >= itemCount && itemCount != 0) {
133+
position = position % itemCount;
133134
}
134135

135136
final float offset = (getCurrentFrameLeft() - leftView.getX()) / leftView.getMeasuredWidth();
136137

137-
if (offset >= 0 && offset <= 1 && position != RecyclerView.NO_POSITION && position < adapter.getItemCount()) {
138+
if (offset >= 0 && offset <= 1 && position < itemCount) {
138139
indicator.onPageScrolled(position, offset);
139140
}
140141
}

0 commit comments

Comments
 (0)