Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop support #104

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions pageindicatorview/src/main/java/com/rd/PageIndicatorView.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void setCount(int count) {
* Return number of circle indicators
*/
public int getCount() {
return manager.indicator().getCount();
return viewPager.getAdapter().getCount();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, just checked your PR, I think here you should keep manager.indicator().getCount()

}

/**
Expand Down Expand Up @@ -522,7 +522,6 @@ public void setViewPager(@Nullable ViewPager pager) {
viewPager = pager;
viewPager.addOnPageChangeListener(this);
viewPager.addOnAdapterChangeListener(this);
viewPager.setOnTouchListener(this);
manager.indicator().setViewPagerId(viewPager.getId());

setDynamicCount(manager.indicator().isDynamicCount());
Expand Down Expand Up @@ -736,8 +735,10 @@ private void updateState() {
return;
}

int count = viewPager.getAdapter().getCount();
int selectedPos = isRtl() ? (count - 1) - viewPager.getCurrentItem() : viewPager.getCurrentItem();
int count = this.getCount();
int pos = isRtl() ? (count - 1) - viewPager.getCurrentItem() : viewPager.getCurrentItem();

int selectedPos = pos % count;

manager.indicator().setSelectedPosition(selectedPos);
manager.indicator().setSelectingPosition(selectedPos);
Expand Down Expand Up @@ -766,20 +767,23 @@ private void updateVisibility() {
}

private void onPageSelect(int position) {

int pos = position % getCount();
Indicator indicator = manager.indicator();
boolean canSelectIndicator = isViewMeasured();
int count = indicator.getCount();

if (canSelectIndicator) {
if (isRtl()) {
position = (count - 1) - position;
pos = (count - 1) - pos;
}

setSelection(position);
setSelection(pos);
}
}

private void onPageScroll(int position, float positionOffset) {
private void onPageScroll(int _position, float positionOffset) {
int position = _position % getCount();
Indicator indicator = manager.indicator();
AnimationType animationType = indicator.getAnimationType();
boolean interactiveAnimation = indicator.isInteractiveAnimation();
Expand Down Expand Up @@ -890,3 +894,5 @@ public void run() {
}
};
}