Skip to content

Commit

Permalink
发布 新版本
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomsh committed Sep 26, 2019
1 parent 460a3af commit fa0bdae
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 32 deletions.
2 changes: 1 addition & 1 deletion LibBanner/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ publish {
userOrg = 'songwenchao0714'
groupId = 'com.ms'
artifactId = 'Banner'
publishVersion = '2.3.16'
publishVersion = '2.3.17'
desc = 'A simple banner lib'
website = 'https://github.com/wenchaosong/Banner'
}
2 changes: 1 addition & 1 deletion LibBannerAndroidx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ publish {
userOrg = 'songwenchao0714'
groupId = 'com.ms'
artifactId = 'Banner-androidx'
publishVersion = '2.3.16'
publishVersion = '2.3.17'
desc = 'A simple banner lib'
website = 'https://github.com/wenchaosong/Banner'
}
41 changes: 16 additions & 25 deletions LibBannerAndroidx/src/main/java/com/ms/banner/Banner.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class Banner extends FrameLayout implements OnPageChangeListener {
private int titleTextSize;
private int count = 0;
private int currentItem = -1;
private int mCurrentPage = 0;
private int gravity = -1;
private int lastPosition;
private List<String> titles;
Expand Down Expand Up @@ -170,7 +171,7 @@ private void initViewPagerScroll() {
scroller.setDuration(scrollTime);
mField.set(viewPager, scroller);
} catch (Exception e) {

e.printStackTrace();
}
}

Expand Down Expand Up @@ -208,7 +209,7 @@ public Banner setBannerAnimation(Class<? extends PageTransformer> transformer) {
try {
viewPager.setPageTransformer(true, transformer.newInstance());
} catch (Exception e) {

e.printStackTrace();
}
return this;
}
Expand Down Expand Up @@ -241,21 +242,13 @@ public Banner setViewPagerIsScroll(boolean isScroll) {
}

public Banner setCurrentPage(@IntRange(from = 0) int page) {
if (count == 0)
return this;
if (page > count) {
throw new RuntimeException("[Banner] --> The current page is out of range");
}
if (isLoop) {
this.currentItem = NUM / 2 - ((NUM / 2) % count) + 1 + page;
} else {
this.currentItem = page;
}
mCurrentPage = page;
return this;
}

public Banner setPages(List<?> datas, BannerViewHolder creator) {
this.mDatas = datas;
this.mDatas.clear();
this.mDatas.addAll(datas);
this.creator = creator;
this.count = datas.size();
return this;
Expand All @@ -275,19 +268,18 @@ public void update(List<?> imageUrls) {
if (imageUrls == null) {
imageUrls = new ArrayList<>();
}
this.mDatas.clear();
this.indicatorImages.clear();
if (imageUrls.size() == 0) {
bannerDefaultImage.setVisibility(VISIBLE);
this.mDatas.clear();
this.indicatorImages.clear();
this.count = 0;
if (adapter != null) {
adapter.notifyDataSetChanged();
}
} else {
this.mDatas.clear();
this.indicatorImages.clear();
this.mDatas.addAll(imageUrls);
this.count = this.mDatas.size();
setOffscreenPageLimit(imageUrls.size());
start();
}
}
Expand Down Expand Up @@ -450,13 +442,16 @@ else if (bannerStyle == BannerConfig.CUSTOM_INDICATOR)

private void setData() {
if (isLoop) {
//currentItem = 1;
if (currentItem == -1) {
if (mCurrentPage > 0 && mCurrentPage < count) {
currentItem = NUM / 2 - ((NUM / 2) % count) + 1 + mCurrentPage;
} else {
currentItem = NUM / 2 - ((NUM / 2) % count) + 1;
}
lastPosition = 1;
} else {
if (currentItem == -1) {
if (mCurrentPage > 0 && mCurrentPage < count) {
currentItem = mCurrentPage;
} else {
currentItem = 0;
}
lastPosition = 0;
Expand All @@ -467,7 +462,6 @@ private void setData() {
}
viewPager.setAdapter(adapter);
viewPager.setCurrentItem(currentItem);
viewPager.setOffscreenPageLimit(count);
if (isScroll && count > 1) {
viewPager.setScrollable(true);
} else {
Expand Down Expand Up @@ -581,12 +575,9 @@ public Object instantiateItem(ViewGroup container, final int position) {
if (creator == null) {
throw new RuntimeException("[Banner] --> The layout is not specified,please set holder");
}
View view = creator.createView(container.getContext());
View view = creator.createView(container.getContext(), toRealPosition(position), mDatas.get(toRealPosition(position)));
container.addView(view);

if (mDatas != null && mDatas.size() > 0) {
creator.onBind(container.getContext(), toRealPosition(position), mDatas.get(toRealPosition(position)));
}
if (listener != null) {
view.setOnClickListener(new OnClickListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

public interface BannerViewHolder<T> {

View createView(Context context);
View createView(Context context, int position, T data);

void onBind(Context context, int position, T data);
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
#### Step 1.依赖banner
```
dependencies{
implementation 'com.ms:Banner:2.3.16'
implementation 'com.ms:Banner-androidx:2.3.16'
implementation 'com.ms:Banner:2.3.17'
implementation 'com.ms:Banner-androidx:2.3.17'
}
```
或者引用本地lib
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':LibBanner', ':demo'
include ':LibBanner', ':demo'/*, ':LibBannerAndroidx'*/

0 comments on commit fa0bdae

Please sign in to comment.