Skip to content

Commit

Permalink
解决 update 数据为空的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomsh committed Sep 26, 2019
1 parent 90bdef8 commit 814f1a3
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions LibBanner/src/main/java/com/ms/banner/Banner.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class Banner extends FrameLayout implements ViewPager.OnPageChangeListene
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 @@ -238,21 +239,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 @@ -272,17 +265,15 @@ 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());
Expand Down Expand Up @@ -448,13 +439,16 @@ else if (bannerStyle == BannerConfig.CUSTOM_INDICATOR)

private void setData() {
if (isLoop) {
//currentItem = 1;
if (currentItem == -1) {
if (mCurrentPage > 0 && mCurrentPage < count) {
this.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) {
this.currentItem = mCurrentPage;
} else {
currentItem = 0;
}
lastPosition = 0;
Expand Down

0 comments on commit 814f1a3

Please sign in to comment.