diff --git a/app/src/main/java/com/example/zhpan/banner/adapter/AdapterFragmentPager.kt b/app/src/main/java/com/example/zhpan/banner/adapter/AdapterFragmentPager.kt index cbf4b05d..69b3f3a2 100644 --- a/app/src/main/java/com/example/zhpan/banner/adapter/AdapterFragmentPager.kt +++ b/app/src/main/java/com/example/zhpan/banner/adapter/AdapterFragmentPager.kt @@ -4,12 +4,7 @@ import android.util.SparseArray import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentActivity import androidx.viewpager2.adapter.FragmentStateAdapter - -import com.example.zhpan.banner.fragment.BaseFragment -import com.example.zhpan.banner.fragment.HomeFragment -import com.example.zhpan.banner.fragment.IndicatorFragment -import com.example.zhpan.banner.fragment.OthersFragment -import com.example.zhpan.banner.fragment.PageFragment +import com.example.zhpan.banner.fragment.* /** *
@@ -60,7 +55,7 @@ class AdapterFragmentPager(fragmentActivity: FragmentActivity) : FragmentStateAd } else -> { if (fragments.get(PAGE_HOME) == null) { - fragment = HomeFragment.getInstance(); + fragment = EmptyFragment.getInstance(); fragments.put(PAGE_HOME, fragment) } else { fragment = fragments.get(PAGE_HOME) diff --git a/app/src/main/java/com/example/zhpan/banner/fragment/EmptyFragment.java b/app/src/main/java/com/example/zhpan/banner/fragment/EmptyFragment.java new file mode 100644 index 00000000..695192be --- /dev/null +++ b/app/src/main/java/com/example/zhpan/banner/fragment/EmptyFragment.java @@ -0,0 +1,35 @@ +package com.example.zhpan.banner.fragment; + +import android.os.Bundle; +import android.view.View; + +import com.example.zhpan.banner.R; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author zhangpan + * @date 2020/12/9 + */ +public class EmptyFragment extends BaseFragment { + + @Override + protected int getLayout() { + return R.layout.fragment_empty; + } + + @Override + protected void initTitle() { + + } + + @Override + protected void initView(@Nullable Bundle savedInstanceState, @NotNull View view) { + + } + + public static EmptyFragment getInstance() { + return new EmptyFragment(); + } +} 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 ef5534dd..55130219 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 @@ -106,7 +106,6 @@ private void initRecyclerView(View view) { DividerItemDecoration.VERTICAL)); articleAdapter = new ArticleAdapter(getActivity(), new ArrayList<>()); recyclerView.setAdapter(articleAdapter); - recyclerView.getHeadAndFootAdapter(); } private void initRefreshLayout(View view) { 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 01d97650..c598ffad 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 @@ -83,42 +83,28 @@ private void initRadioGroup() { mRadioGroupStyle.setOnCheckedChangeListener((group, checkedId) -> checkedChange(mCheckId = checkedId)); radioButton.performClick(); mRadioGroupMode.setOnCheckedChangeListener((group, checkedId) -> { - switch (checkedId) { - case R.id.rb_normal: - mSlideMode = IndicatorSlideMode.NORMAL; - break; - case R.id.rb_worm: - mSlideMode = IndicatorSlideMode.WORM; - break; - case R.id.rb_smooth: - mSlideMode = IndicatorSlideMode.SMOOTH; - break; - case R.id.rb_color: - mSlideMode = IndicatorSlideMode.COLOR; - break; - case R.id.rb_scale: - mSlideMode = IndicatorSlideMode.SCALE; - break; - default: - break; + if (checkedId == R.id.rb_normal) { + mSlideMode = IndicatorSlideMode.NORMAL; + } else if (checkedId == R.id.rb_worm) { + mSlideMode = IndicatorSlideMode.WORM; + } else if (checkedId == R.id.rb_smooth) { + mSlideMode = IndicatorSlideMode.SMOOTH; + } else if (checkedId == R.id.rb_color) { + mSlideMode = IndicatorSlideMode.COLOR; + } else if (checkedId == R.id.rb_scale) { + mSlideMode = IndicatorSlideMode.SCALE; } checkedChange(mCheckId); }); } private void checkedChange(int checkedId) { - switch (checkedId) { - case R.id.rb_circle: - setupCircleIndicator(); - break; - case R.id.rb_dash: - setupDashIndicator(); - break; - case R.id.rb_round_rect: - setupRoundRectIndicator(); - break; - default: - break; + if (checkedId == R.id.rb_circle) { + setupCircleIndicator(); + } else if (checkedId == R.id.rb_dash) { + setupDashIndicator(); + } else if (checkedId == R.id.rb_round_rect) { + setupRoundRectIndicator(); } } 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 a6e5b852..f7ee69b1 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 @@ -90,21 +90,14 @@ protected void initView(Bundle savedInstanceState, @NonNull View view) { private void initRadioGroup() { radioGroupStyle.setVisibility(View.VISIBLE); radioGroupStyle.setOnCheckedChangeListener((group, checkedId) -> { - switch (checkedId) { - case R.id.rb_indicator_below: - setIndicatorBelowOfBanner(); - break; - case R.id.rb_dash: - setupCustomIndicator(); - break; - case R.id.rb_drawable: - setDrawableIndicator(getDrawableIndicator()); - break; - case R.id.rb_vector_drawable: - setDrawableIndicator(getVectorDrawableIndicator()); - break; - default: - break; + if (checkedId == R.id.rb_indicator_below) { + setIndicatorBelowOfBanner(); + } else if (checkedId == R.id.rb_dash) { + setupCustomIndicator(); + } else if (checkedId == R.id.rb_drawable) { + setDrawableIndicator(getDrawableIndicator()); + } else if (checkedId == R.id.rb_vector_drawable) { + setDrawableIndicator(getVectorDrawableIndicator()); } }); radioButton.performClick(); @@ -173,21 +166,16 @@ private void updateData() { @Override public void onClick(View view) { - switch (view.getId()) { - case R.id.tv_add_data: - addData(); - break; - case R.id.tv_remove_item: - removeItem(); - break; - case R.id.tv_insert_item: - insertItem(); - break; - default: - int position = new Random().nextInt(5); - mViewPager.setCurrentItem(position, true); - ToastUtils.showShort("Jump to position:" + position); - break; + if (view.getId() == R.id.tv_add_data) { + addData(); + } else if (view.getId() == R.id.tv_remove_item) { + removeItem(); + } else if (view.getId() == R.id.tv_insert_item) { + insertItem(); + } else { + int position = new Random().nextInt(5); + mViewPager.setCurrentItem(position, true); + ToastUtils.showShort("Jump to position:" + position); } } diff --git a/app/src/main/java/com/example/zhpan/banner/fragment/PageFragment.java b/app/src/main/java/com/example/zhpan/banner/fragment/PageFragment.java index 97461bcd..0258dea0 100644 --- a/app/src/main/java/com/example/zhpan/banner/fragment/PageFragment.java +++ b/app/src/main/java/com/example/zhpan/banner/fragment/PageFragment.java @@ -61,27 +61,18 @@ private void pageClick(View view, int position) { private void initRadioGroup() { mRadioGroupPageStyle.setOnCheckedChangeListener((group, checkedId) -> { - switch (checkedId) { - case R.id.rb_multi_page: - setupMultiPageBanner(); - break; - case R.id.rb_right_page_reveal: - setupRightPageReveal(); - break; - case R.id.rb_multi_page_scale: - setupBanner(PageStyle.MULTI_PAGE_SCALE); - break; - case R.id.rb_multi_page_overlap: - setupBanner(PageStyle.MULTI_PAGE_OVERLAP); - break; - case R.id.rb_qq_music_style: - setQQMusicStyle(); - break; - case R.id.rb_netease_music_style: - setNetEaseMusicStyle(); - break; - default: - break; + if (checkedId == R.id.rb_multi_page) { + setupMultiPageBanner(); + } else if (checkedId == R.id.rb_right_page_reveal) { + setupRightPageReveal(); + } else if (checkedId == R.id.rb_multi_page_scale) { + setupBanner(PageStyle.MULTI_PAGE_SCALE); + } else if (checkedId == R.id.rb_multi_page_overlap) { + setupBanner(PageStyle.MULTI_PAGE_OVERLAP); + } else if (checkedId == R.id.rb_netease_music_style) { + setNetEaseMusicStyle(); + } else if (checkedId == R.id.rb_qq_music_style) { + setQQMusicStyle(); } }); } diff --git a/app/src/main/res/layout/fragment_empty.xml b/app/src/main/res/layout/fragment_empty.xml new file mode 100644 index 00000000..77d9ef65 --- /dev/null +++ b/app/src/main/res/layout/fragment_empty.xml @@ -0,0 +1,6 @@ + ++ + \ No newline at end of file diff --git a/bannerview/src/main/java/com/zhpan/bannerview/BannerViewPager.java b/bannerview/src/main/java/com/zhpan/bannerview/BannerViewPager.java index 6bc08f2f..14a3379e 100644 --- a/bannerview/src/main/java/com/zhpan/bannerview/BannerViewPager.java +++ b/bannerview/src/main/java/com/zhpan/bannerview/BannerViewPager.java @@ -994,7 +994,7 @@ public BannerViewPagersetLifecycleRegistry(Lifecycle lifecycleRegistry) @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) public void onPause() { - stopLoop(); + stopLoop(); } @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) @@ -1002,6 +1002,11 @@ public void onResume() { startLoop(); } + @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) + public void onDestroy() { + stopLoop(); + } + /** * 设置是否允许BVP对事件进行拦截,用于解决CoordinatorLayout+CollapsingToolbarLayout * 在嵌套BVP时引起的滑动冲突问题。