From 746bb77f15c587481320de823bae319f5606ae37 Mon Sep 17 00:00:00 2001 From: Tommy Buonomo Date: Tue, 10 Sep 2019 13:37:11 +0200 Subject: [PATCH] [fix #55] Fix ArrayIndexOutOfBoundsException when there is 0 or 1 item --- .../src/main/AndroidManifest.xml | 8 ++++---- .../viewpagerdotsindicator/OnPageChangeListenerHelper.kt | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/viewpagerdotsindicator-sample/src/main/AndroidManifest.xml b/viewpagerdotsindicator-sample/src/main/AndroidManifest.xml index 8aa7076..b670696 100644 --- a/viewpagerdotsindicator-sample/src/main/AndroidManifest.xml +++ b/viewpagerdotsindicator-sample/src/main/AndroidManifest.xml @@ -10,15 +10,15 @@ android:supportsRtl="true" android:theme="@style/AppTheme"> - - - - + + + + diff --git a/viewpagerdotsindicator/src/main/java/com/tbuonomo/viewpagerdotsindicator/OnPageChangeListenerHelper.kt b/viewpagerdotsindicator/src/main/java/com/tbuonomo/viewpagerdotsindicator/OnPageChangeListenerHelper.kt index 271c71e..4adf63b 100644 --- a/viewpagerdotsindicator/src/main/java/com/tbuonomo/viewpagerdotsindicator/OnPageChangeListenerHelper.kt +++ b/viewpagerdotsindicator/src/main/java/com/tbuonomo/viewpagerdotsindicator/OnPageChangeListenerHelper.kt @@ -14,6 +14,11 @@ abstract class OnPageChangeListenerHelper { } val leftPosition = offset.toInt() val rightPosition = leftPosition + 1 + + if (rightPosition > lastPageIndex || leftPosition == -1) { + return + } + onPageScrolled(leftPosition, rightPosition, offset % 1) if (lastLeftPosition != -1) {