diff --git a/README.md b/README.md index 451de88..31e8563 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This is an amazing image slider for the Android . You can easily load images with your custom layout, and there are many kinds of amazing animations you can choose. ```groovy - implementation 'com.github.smarteist:autoimageslider:1.3.5' + implementation 'com.github.smarteist:autoimageslider:1.3.6' ``` If you are using appcompat libraries use this one, but please migrate to androidx as soon as you can. ```groovy @@ -18,8 +18,8 @@ If you are using appcompat libraries use this one, but please migrate to android ``` ### New Feautures -* Infinite adapter implemented -* Slider API improvements. +* Minor sliderView API improvements. +* Ability to disable infinite mode. ### New Changes * Auto cycle Bugs fixed. diff --git a/app/src/main/java/com/smarteist/imageslider/MainActivity.java b/app/src/main/java/com/smarteist/imageslider/MainActivity.java index 0646829..83096c2 100644 --- a/app/src/main/java/com/smarteist/imageslider/MainActivity.java +++ b/app/src/main/java/com/smarteist/imageslider/MainActivity.java @@ -9,6 +9,7 @@ import androidx.appcompat.app.AppCompatActivity; import com.smarteist.autoimageslider.IndicatorAnimations; +import com.smarteist.autoimageslider.IndicatorView.draw.controller.DrawController; import com.smarteist.autoimageslider.SliderAnimations; import com.smarteist.autoimageslider.SliderView; import com.smarteist.imageslider.Model.SliderItem; @@ -39,6 +40,13 @@ protected void onCreate(Bundle savedInstanceState) { sliderView.setScrollTimeInSec(3); sliderView.setAutoCycle(false); + sliderView.setOnIndicatorClickListener(new DrawController.ClickListener() { + @Override + public void onIndicatorClicked(int position) { + sliderView.setCurrentPagePosition(position); + } + }); + } public void renewItems(View view) { diff --git a/autoimageslider/build.gradle b/autoimageslider/build.gradle index d967df2..e459e87 100644 --- a/autoimageslider/build.gradle +++ b/autoimageslider/build.gradle @@ -15,7 +15,7 @@ ext { siteUrl = 'https://github.com/smarteist' gitUrl = 'https://github.com/smarteist/android-image-slider.git' - libraryVersion = '1.3.5' + libraryVersion = '1.3.6' organization = 'smarteistbintray' // if you push to organization's repository. developerId = 'smarteist' developerName = 'Ali Hosseini' diff --git a/autoimageslider/src/main/java/com/smarteist/autoimageslider/SliderPager.java b/autoimageslider/src/main/java/com/smarteist/autoimageslider/SliderPager.java index f7d54af..e000e2a 100644 --- a/autoimageslider/src/main/java/com/smarteist/autoimageslider/SliderPager.java +++ b/autoimageslider/src/main/java/com/smarteist/autoimageslider/SliderPager.java @@ -1283,7 +1283,7 @@ private void triggerOnPageChangeEvent(int position) { int n = position % realCount; eachListener.onPageSelected(n); } else { - eachListener.onPageSelected(mAdapter.getCount()); + eachListener.onPageSelected(position); } } diff --git a/autoimageslider/src/main/java/com/smarteist/autoimageslider/SliderView.java b/autoimageslider/src/main/java/com/smarteist/autoimageslider/SliderView.java index 7f86ace..df4911e 100644 --- a/autoimageslider/src/main/java/com/smarteist/autoimageslider/SliderView.java +++ b/autoimageslider/src/main/java/com/smarteist/autoimageslider/SliderView.java @@ -71,6 +71,7 @@ public class SliderView extends FrameLayout private InfinitePagerAdapter mInfinitePagerAdapter; private boolean mPausedSliding = false; private OnSliderPageListener mPageListener; + private boolean mIsInfiniteAdapter = true; /*Constructor*/ public SliderView(Context context) { @@ -201,6 +202,24 @@ public void setSliderAdapter(@NonNull SliderViewAdapter pagerAdapter) { mPagerIndicator.setDynamicCount(true); } + /** + * @param pagerAdapter Set a SliderAdapter that will supply views + * for this slider as needed. + */ + public void setSliderAdapter(@NonNull SliderViewAdapter pagerAdapter, boolean infiniteAdapter) { + this.mIsInfiniteAdapter = infiniteAdapter; + if (!infiniteAdapter) { + this.mPagerAdapter = pagerAdapter; + //registerAdapterDataObserver(); + mSliderPager.setAdapter(pagerAdapter); + //setup with indicator + mPagerIndicator.setCount(getAdapterItemsCount()); + mPagerIndicator.setDynamicCount(true); + } else { + setSliderAdapter(pagerAdapter); + } + } + /** * @return Sliders Pager */ @@ -604,7 +623,7 @@ public int getIndicatorUnselectedColor() { /** * This method handles sliding behaviors * which passed into {@link #SliderView#mHandler} - * + *
* see {@link #SliderView#startAutoCycle()} */ @Override @@ -643,11 +662,35 @@ public void slideToNextPosition() { } } + + public void slideToPreviousPosition() { + + int currentPosition = mSliderPager.getCurrentItem(); + int adapterItemsCount = getAdapterItemsCount(); + + if (mAutoCycleDirection == AUTO_CYCLE_DIRECTION_BACK_AND_FORTH && adapterItemsCount > 1) { + if (currentPosition % (adapterItemsCount - 1) == 0) { + mFlagBackAndForth = !mFlagBackAndForth; + } + if (mFlagBackAndForth) { + mSliderPager.setCurrentItem(--currentPosition, true); + } else { + mSliderPager.setCurrentItem(++currentPosition, true); + } + } else if (mAutoCycleDirection == AUTO_CYCLE_DIRECTION_LEFT) { + mSliderPager.setCurrentItem(++currentPosition, true); + } else { + mSliderPager.setCurrentItem(--currentPosition, true); + } + } + //sync infinite pager adapter with real one @Override public void dataSetChanged() { - mInfinitePagerAdapter.notifyDataSetChanged(); - mSliderPager.setCurrentItem((getAdapterItemsCount() - 1) * (InfinitePagerAdapter.INFINITE_SCROLL_LIMIT / 2), false); + if (mIsInfiniteAdapter) { + mInfinitePagerAdapter.notifyDataSetChanged(); + mSliderPager.setCurrentItem((getAdapterItemsCount() - 1) * (InfinitePagerAdapter.INFINITE_SCROLL_LIMIT / 2), false); + } } @Override