[Android] Directly handle ViewPager.OnPageChangeListener

Geoffrey Métais git at videolan.org
Wed Aug 19 14:28:52 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Aug 19 14:28:09 2015 +0200| [7361d5b16c358130eb29427759087f09774cffb6] | committer: Geoffrey Métais

Directly handle ViewPager.OnPageChangeListener

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=7361d5b16c358130eb29427759087f09774cffb6
---

 .../vlc/gui/audio/AudioBrowserFragment.java        |   40 +++++++++++---------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index b4d7b15..10d0c39 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -77,7 +77,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
-public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeRefreshLayout.OnRefreshListener, MediaBrowser.EventListener, IBrowser {
+public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeRefreshLayout.OnRefreshListener, MediaBrowser.EventListener, IBrowser, ViewPager.OnPageChangeListener {
     public final static String TAG = "VLC/AudioBrowserFragment";
 
     private MediaBrowser mMediaBrowser;
@@ -161,23 +161,7 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
         mTabLayout = (TabLayout) v.findViewById(R.id.sliding_tabs);
         mTabLayout.setupWithViewPager(mViewPager);
 
-        mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
-        mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
-            @Override
-            public void onTabSelected(TabLayout.Tab tab) {
-                mViewPager.setCurrentItem(tab.getPosition());
-                updateEmptyView(tab.getPosition());
-                setFabPlayShuffleAllVisibility();
-            }
-
-            @Override
-            public void onTabUnselected(TabLayout.Tab tab) {}
-
-            @Override
-            public void onTabReselected(TabLayout.Tab tab) {
-                mViewPager.setCurrentItem(tab.getPosition());
-            }
-        });
+        mViewPager.addOnPageChangeListener(this);
 
         songsList.setOnItemClickListener(songListener);
         artistList.setOnItemClickListener(artistListListener);
@@ -654,6 +638,26 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
         mMainActivity.sendTextInfo(info, progress, max);
     }
 
+    TabLayout.TabLayoutOnPageChangeListener tcl = new TabLayout.TabLayoutOnPageChangeListener(mTabLayout);
+
+    @Override
+    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+        tcl.onPageScrolled(position, positionOffset, positionOffsetPixels);
+    }
+
+    @Override
+    public void onPageSelected(int position) {
+        mViewPager.setCurrentItem(position);
+        updateEmptyView(position);
+        setFabPlayShuffleAllVisibility();
+        tcl.onPageSelected(position);
+    }
+
+    @Override
+    public void onPageScrollStateChanged(int state) {
+        tcl.onPageScrollStateChanged(state);
+    }
+
     private static class AudioBrowserHandler extends WeakHandler<AudioBrowserFragment> {
         public AudioBrowserHandler(AudioBrowserFragment owner) {
             super(owner);



More information about the Android mailing list