Skip to content

Commit

Permalink
optimize the getOriginalPosition method.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhpanvip committed Aug 21, 2020
1 parent c86388f commit 18beb37
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.zhpan.bannerview.BannerViewPager;
import com.zhpan.bannerview.BaseViewHolder;
import com.zhpan.bannerview.constants.IndicatorGravity;
import com.zhpan.bannerview.utils.BannerUtils;
import com.zhpan.idea.net.common.ResponseObserver;
import com.zhpan.idea.utils.LogUtils;
import com.zhpan.idea.utils.RxUtil;
Expand Down Expand Up @@ -177,6 +178,7 @@ public void onPageSelected(int position) {
super.onPageSelected(position);
BannerData bannerData = mViewPagerHorizontal.getData().get(position);
mTvTitle.setText(bannerData.getTitle());
BannerUtils.log("position:" + mViewPagerHorizontal.getCurrentItem());
}
})
.setOnPageClickListener(this::onPageClicked).create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void log(String tag, String msg) {

public static void log(String msg) {
if (isDebugMode()) {
Log.e(TAG, msg);
log(TAG, msg);
}
}

Expand All @@ -57,14 +57,14 @@ public static int getRealPosition(boolean isCanLoop, int position, int pageSize)
if (pageSize == 0) {
return 0;
}
return isCanLoop ? (position - 1 + pageSize) % pageSize : (position + pageSize) % pageSize;
return isCanLoop ? (position + pageSize) % pageSize : (position + pageSize) % pageSize;
}

/**
* @param pageSize 轮播图页面数
* @return 轮播图初始位置
*/
public static int getOriginalPosition(int pageSize) {
return MAX_VALUE / 2 - ((MAX_VALUE / 2) % pageSize) + 1;
return MAX_VALUE / 2 - ((MAX_VALUE / 2) % pageSize);
}
}

0 comments on commit 18beb37

Please sign in to comment.