diff --git a/app/src/main/java/com/example/zhpan/banner/adapter/others/ArticleAdapter.kt b/app/src/main/java/com/example/zhpan/banner/adapter/others/ArticleAdapter.kt index 241b644..a185c5e 100644 --- a/app/src/main/java/com/example/zhpan/banner/adapter/others/ArticleAdapter.kt +++ b/app/src/main/java/com/example/zhpan/banner/adapter/others/ArticleAdapter.kt @@ -91,7 +91,7 @@ class ArticleAdapter( .setIndicatorGravity(IndicatorGravity.END) .setInterval(2000) .setAdapter(DataBindingSampleAdapter()) - .setLifecycleRegistry(context.lifecycle) + .registerLifecycleObserver(context.lifecycle) .create() } } diff --git a/app/src/main/java/com/example/zhpan/banner/fragment/HomeFragment.java b/app/src/main/java/com/example/zhpan/banner/fragment/HomeFragment.java index 5d8de5f..79dd970 100644 --- a/app/src/main/java/com/example/zhpan/banner/fragment/HomeFragment.java +++ b/app/src/main/java/com/example/zhpan/banner/fragment/HomeFragment.java @@ -160,7 +160,7 @@ private void initHorizontalBanner() { mViewPagerHorizontal .setScrollDuration(600) .setOffScreenPageLimit(2) - .setLifecycleRegistry(getLifecycle()) + .registerLifecycleObserver(getLifecycle()) .setIndicatorStyle(IndicatorStyle.CIRCLE) .setIndicatorSlideMode(IndicatorSlideMode.WORM) .setInterval(3000) @@ -190,7 +190,7 @@ private void initVerticalBanner() { .setAutoPlay(true) .setScrollDuration(500) .stopLoopWhenDetachedFromWindow(true) - .setLifecycleRegistry(getLifecycle()) + .registerLifecycleObserver(getLifecycle()) .setIndicatorStyle(IndicatorStyle.ROUND_RECT) .setIndicatorSlideMode(IndicatorSlideMode.SCALE) .setIndicatorSliderGap(getResources().getDimensionPixelOffset(R.dimen.dp_4)) diff --git a/app/src/main/java/com/example/zhpan/banner/fragment/IndicatorFragment.java b/app/src/main/java/com/example/zhpan/banner/fragment/IndicatorFragment.java index 68c7f9d..eedaf38 100644 --- a/app/src/main/java/com/example/zhpan/banner/fragment/IndicatorFragment.java +++ b/app/src/main/java/com/example/zhpan/banner/fragment/IndicatorFragment.java @@ -50,7 +50,7 @@ protected void initView(Bundle savedInstanceState, View view) { mViewPager = view.findViewById(R.id.banner_view); mViewPager.setIndicatorSliderGap(BannerUtils.dp2px(6)) .setScrollDuration(800) - .setLifecycleRegistry(getLifecycle()) + .registerLifecycleObserver(getLifecycle()) .setIndicatorGravity(IndicatorGravity.CENTER) .setOnPageClickListener( (clickedView, position) -> ToastUtils.showShort("position:" + position)) diff --git a/app/src/main/java/com/example/zhpan/banner/fragment/OthersFragment.java b/app/src/main/java/com/example/zhpan/banner/fragment/OthersFragment.java index 5d47136..9c0cb17 100644 --- a/app/src/main/java/com/example/zhpan/banner/fragment/OthersFragment.java +++ b/app/src/main/java/com/example/zhpan/banner/fragment/OthersFragment.java @@ -72,7 +72,7 @@ protected void initView(Bundle savedInstanceState, @NonNull View view) { view.findViewById(R.id.tv_photo_view).setOnClickListener(this); mViewPager.setIndicatorSliderGap(BannerUtils.dp2px(6)) .setIndicatorView(mIndicatorView) - .setLifecycleRegistry(getLifecycle()) + .registerLifecycleObserver(getLifecycle()) .setRoundCorner(getResources().getDimensionPixelOffset(R.dimen.dp_10)) .setOnPageClickListener((clickedView, position) -> { ToastUtils.showShort("position:" + position); diff --git a/app/src/main/java/com/example/zhpan/banner/fragment/PageFragment.kt b/app/src/main/java/com/example/zhpan/banner/fragment/PageFragment.kt index 7c3b157..15abcf5 100644 --- a/app/src/main/java/com/example/zhpan/banner/fragment/PageFragment.kt +++ b/app/src/main/java/com/example/zhpan/banner/fragment/PageFragment.kt @@ -36,7 +36,7 @@ class PageFragment : BaseFragment() { private fun initBVP() { mViewPager.apply { - setLifecycleRegistry(lifecycle) + registerLifecycleObserver(lifecycle) adapter = ViewBindingSampleAdapter(resources.getDimensionPixelOffset(dimen.dp_8)) setIndicatorSlideMode(IndicatorSlideMode.SCALE) setIndicatorSliderColor( diff --git a/bannerview/src/main/java/com/zhpan/bannerview/BannerViewPager.java b/bannerview/src/main/java/com/zhpan/bannerview/BannerViewPager.java index 9b4309a..8315bbb 100644 --- a/bannerview/src/main/java/com/zhpan/bannerview/BannerViewPager.java +++ b/bannerview/src/main/java/com/zhpan/bannerview/BannerViewPager.java @@ -1062,11 +1062,20 @@ public BannerViewPager registerOnPageChangeCallback( return this; } + /** + * @deprecated use {@link #registerLifecycleObserver(Lifecycle)} instead. + */ + @Deprecated public BannerViewPager setLifecycleRegistry(Lifecycle lifecycleRegistry) { lifecycleRegistry.addObserver(this); return this; } + public BannerViewPager registerLifecycleObserver(Lifecycle lifecycleRegistry) { + lifecycleRegistry.addObserver(this); + return this; + } + public BannerViewPager removeLifecycleRegistry(Lifecycle lifecycleRegistry) { lifecycleRegistry.removeObserver(this); return this;