Skip to content

Commit

Permalink
Merge pull request #129 from smarteist/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
smarteist authored May 7, 2020
2 parents 248be7d + 3f2286b commit dc91fe4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ 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
implementation 'com.github.smarteist:autoimageslider:1.3.2-appcompat'
```

### New Feautures
* Infinite adapter implemented
* Slider API improvements.
* Minor sliderView API improvements.
* Ability to disable infinite mode.

### New Changes
* Auto cycle Bugs fixed.
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/smarteist/imageslider/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion autoimageslider/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ private void triggerOnPageChangeEvent(int position) {
int n = position % realCount;
eachListener.onPageSelected(n);
} else {
eachListener.onPageSelected(mAdapter.getCount());
eachListener.onPageSelected(position);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -604,7 +623,7 @@ public int getIndicatorUnselectedColor() {
/**
* This method handles sliding behaviors
* which passed into {@link #SliderView#mHandler}
*
* <p>
* see {@link #SliderView#startAutoCycle()}
*/
@Override
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dc91fe4

Please sign in to comment.